fix hash map (-> 0.19)

This commit is contained in:
alex_s168
2024-07-30 20:02:48 +00:00
parent 8439df8ae5
commit aca62fd413
3 changed files with 5 additions and 3 deletions

View File

@@ -12,7 +12,7 @@ repositories {
} }
dependencies { dependencies {
implementation("me.alex_s168:blitz:0.17") implementation("me.alex_s168:blitz:0.19")
} }
``` ```

View File

@@ -5,7 +5,7 @@ plugins {
} }
group = "me.alex_s168" group = "me.alex_s168"
version = "0.18" version = "0.19"
repositories { repositories {
mavenCentral() mavenCentral()

View File

@@ -1,5 +1,7 @@
package blitz.collections package blitz.collections
import kotlin.math.abs
class BlitzHashMap<K, V>( class BlitzHashMap<K, V>(
private val bucketCount: Int = 16, private val bucketCount: Int = 16,
private val bucketSrc: DynBuckets<K, V>, private val bucketSrc: DynBuckets<K, V>,
@@ -8,7 +10,7 @@ class BlitzHashMap<K, V>(
private val buckets = Array(bucketCount) { bucketSrc.new() } private val buckets = Array(bucketCount) { bucketSrc.new() }
override fun index(key: K): Index<K,V> = override fun index(key: K): Index<K,V> =
IndexImpl(buckets[hash(key) % bucketCount], key) IndexImpl(buckets[abs(hash(key)) % bucketCount], key)
private inline fun index(idx: Index<K,V>) = private inline fun index(idx: Index<K,V>) =
idx as IndexImpl idx as IndexImpl