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 26, 2024
1 parent 9b584e1 commit 653b854
Show file tree
Hide file tree
Showing 2 changed files with 11 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,17 @@
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)
bits.hashCode()
}


@Test
fun createEmptyBitArray() {
val bits = BitArray(0)
Expand Down

0 comments on commit 653b854

Please sign in to comment.