Skip to content

Commit

Permalink
(Quillraven#159) added new hashcode function in bitArray
Browse files Browse the repository at this point in the history
  • Loading branch information
AnderWoche committed Oct 25, 2024
1 parent 2a52b09 commit 91ca0a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 91ca0a3

Please sign in to comment.