Skip to content

Commit 6b5a14a

Browse files
committed
Implement MutableUnionFindMap equality
1 parent 15e7786 commit 6b5a14a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

disjointmap/src/main/kotlin/net/pelsmaeker/collections/MutableUnionFindMap.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package net.pelsmaeker.collections
1515
class MutableUnionFindMap<K, V> internal constructor(
1616
private val _roots: MutableMap<K, V>,
1717
private val _parents: MutableMap<K, K>,
18-
private val _ranks: MutableMap<K, Int>
18+
private val _ranks: MutableMap<K, Int>,
1919
): MutableDisjointMap<K, V> {
2020

2121
constructor(): this(mutableMapOf(), mutableMapOf(), mutableMapOf())
@@ -103,4 +103,24 @@ class MutableUnionFindMap<K, V> internal constructor(
103103
return toMapImpl(this._roots, this._parents, this._ranks).toMutableMap()
104104
}
105105

106+
override fun equals(other: Any?): Boolean {
107+
if (this === other) return true
108+
if (javaClass != other?.javaClass) return false
109+
110+
other as MutableDisjointMap<*, *>
111+
112+
return this.toMap() == other.toMap()
113+
}
114+
115+
override fun hashCode(): Int {
116+
var result = 17
117+
result = 31 * result + _roots.hashCode()
118+
result = 31 * result + _parents.hashCode()
119+
result = 31 * result + _ranks.hashCode()
120+
return result
121+
}
122+
123+
124+
// TODO: Implement equals() and hashCode() methods
125+
106126
}

0 commit comments

Comments
 (0)