diff --git a/src/commonMain/kotlin/com/github/quillraven/fleks/collection/bitArray.kt b/src/commonMain/kotlin/com/github/quillraven/fleks/collection/bitArray.kt index b757881..6afe3e8 100644 --- a/src/commonMain/kotlin/com/github/quillraven/fleks/collection/bitArray.kt +++ b/src/commonMain/kotlin/com/github/quillraven/fleks/collection/bitArray.kt @@ -154,13 +154,9 @@ class BitArray( } override fun hashCode(): Int { - if (bits.isEmpty()) { - return 0 - } - val word = length() ushr 6 var hash = 0 - for (i in 0..word) { + for(i in 0.. word) { hash = 127 * hash + (bits[i] xor (bits[i] ushr 32)).toInt() } return hash diff --git a/src/commonTest/kotlin/com/github/quillraven/fleks/collection/BitArrayTest.kt b/src/commonTest/kotlin/com/github/quillraven/fleks/collection/BitArrayTest.kt index 3f92590..c5dd918 100644 --- a/src/commonTest/kotlin/com/github/quillraven/fleks/collection/BitArrayTest.kt +++ b/src/commonTest/kotlin/com/github/quillraven/fleks/collection/BitArrayTest.kt @@ -1,11 +1,22 @@ package com.github.quillraven.fleks.collection -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertFalse -import kotlin.test.assertTrue +import kotlin.test.* internal class BitArrayTest { + + @Test + fun testBitAt63HashcodeFunction() { + val bits = BitArray(1) + bits.set(63) + try { + bits.hashCode() + } catch (e: Exception) { + fail("hashcode function is brocken.") + } + + } + + @Test fun createEmptyBitArray() { val bits = BitArray(0)