Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/c0040355-ffdc-4813-80e9-baf859ef02b9.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "c0040355-ffdc-4813-80e9-baf859ef02b9",
"type": "bugfix",
"description": "fix: correct hash code calculation for case-insensitive map entries"
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal class CaseInsensitiveMap<Value> : MutableMap<String, Value> {
return value
}

override fun hashCode(): Int = 17 * 31 + key!!.hashCode() + value!!.hashCode()
override fun hashCode(): Int = key.hashCode() xor value.hashCode() // Match JVM & K/N stdlib implementations

override fun equals(other: Any?): Boolean {
if (other == null || other !is Map.Entry<*, *>) return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ class CaseInsensitiveMapTest {
assertEquals(left.entries, right.entries)
}

@Test
fun testEntriesEqualityWithNormalMap() {
val left = CaseInsensitiveMap<String>()
left["A"] = "apple"
left["B"] = "banana"
left["C"] = "cherry"

val right = mutableMapOf(
"c" to "cherry",
"b" to "banana",
"a" to "apple",
)

assertEquals(left.entries, right.entries)
}

@Test
fun testToString() {
val map = CaseInsensitiveMap<String>()
Expand Down
Loading