Skip to content

Commit 15e7786

Browse files
committed
Add DisjointMap.keys and values properties
1 parent a1ac974 commit 15e7786

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ package net.pelsmaeker.collections
66
* Given an underlying union-find map U, and this map M:
77
* A key can be added to M, which is not found in U.
88
*/
9-
class DiffingMutableUnionFindMap<K, V>: MutableDisjointMap<K, V> {
9+
class DiffingMutableUnionFindMap<K, V> : MutableDisjointMap<K, V> {
10+
11+
override val keys: Set<K> get() = TODO()
12+
override val values: Collection<V> get() = TODO()
13+
1014
override val size: Int
1115
get() = TODO("Not yet implemented")
1216

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ interface DisjointMap<K, out V> {
1717
/** Determines whether the collection is not empty. */
1818
fun isNotEmpty(): Boolean = !isEmpty()
1919

20+
/** The keys in the disjoint map. */
21+
val keys: Set<K>
22+
23+
/** The values in the disjoint map. */
24+
val values: Collection<V>
25+
2026
/**
2127
* Gets the value associated with the set that contains the specified key;
2228
* or `null` when the key is not in the map.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ class MutableUnionFindMap<K, V> internal constructor(
2222

2323
override val size: Int get() = _roots.size + _parents.size
2424

25+
override val keys: Set<K>
26+
get() = _roots.keys + _parents.keys
27+
28+
override val values: Collection<V>
29+
get() = _roots.values
30+
2531
override operator fun get(key: K): V? {
2632
val rep = find(key) ?: return null
2733
return this._roots[rep]

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.pelsmaeker.collections
22

33
import kotlinx.collections.immutable.*
4+
import kotlin.collections.plus
45

56
/**
67
* A persistent union-find map.
@@ -32,6 +33,12 @@ class PersistentUnionFindMap<K, V> internal constructor(
3233

3334
override val size: Int get() = _roots.size + _parents.size
3435

36+
override val keys: Set<K>
37+
get() = _roots.keys + _parents.keys
38+
39+
override val values: Collection<V>
40+
get() = _roots.values
41+
3542
override operator fun get(key: K): V? {
3643
val rep = find(key) ?: return null
3744
return this._roots[rep]
@@ -169,6 +176,12 @@ class PersistentUnionFindMap<K, V> internal constructor(
169176
override val size: Int
170177
get() = currentMap.size
171178

179+
override val keys: Set<K>
180+
get() = currentMap.keys
181+
182+
override val values: Collection<V>
183+
get() = currentMap.values
184+
172185
override fun isEmpty() = currentMap.isEmpty()
173186

174187
override fun get(key: K): V? = currentMap.get(key)

0 commit comments

Comments
 (0)