Skip to content

Commit f825110

Browse files
committed
Improve documentation
1 parent 4ab0ec4 commit f825110

File tree

7 files changed

+165
-164
lines changed

7 files changed

+165
-164
lines changed

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

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import kotlinx.collections.immutable.toPersistentSet
66
* Finds the representative key for the given key
77
* and performs path compression.
88
*
9-
* @param key the key for which to find the representative key
10-
* @param roots the map from sets to their values
11-
* @param parents the mutable map from keys to their parent key
12-
* @param ranks the mutable map from keys to their ranks
13-
* @param K the type of keys
14-
* @param V the type of values
15-
* @return the representative key, or the given key when it's
16-
* its own representative; or `null` when the key was not found
9+
* @param K The type of keys.
10+
* @param V The type of values.
11+
* @param key The key for which to find the representative key.
12+
* @param roots The map from sets to their values.
13+
* @param parents The mutable map from keys to their parent key.
14+
* @param ranks The mutable map from keys to their ranks.
15+
* @return The representative key, or the given key when it's
16+
* its own representative; or `null` when the key was not found.
1717
*/
1818
internal fun <K, V> findMutable(
1919
key: K,
@@ -50,19 +50,19 @@ internal fun <K, V> findMutable(
5050
*
5151
* When one or both of the keys don't exist in the map, they are added.
5252
*
53-
* @param key1 the first key
54-
* @param key2 the second key
55-
* @param default function that provides a default value
56-
* @param compare function that compares the keys: the higher is used as the new representative;
57-
* or 0 to use the rank to determine this
58-
* @param unify function that unifies the associated values of each of the sets,
59-
* where the first value is from the representative
60-
* @param roots the mutable map from sets to their values
61-
* @param parents the mutable map from keys to their parent key
62-
* @param ranks the mutable map from keys to their ranks
63-
* @param K the type of keys
64-
* @param V the type of values
65-
* @return whether disjoint sets have been unified
53+
* @param K The type of keys.
54+
* @param V The type of values.
55+
* @param key1 The first key.
56+
* @param key2 The second key.
57+
* @param default Function that provides a default value.
58+
* @param compare Function that compares the keys: the higher is used as the new representative;
59+
* or 0 to use the rank to determine this.
60+
* @param unify Function that unifies the associated values of each of the sets,
61+
* where the first value is from the representative.
62+
* @param roots The mutable map from sets to their values.
63+
* @param parents The mutable map from keys to their parent key.
64+
* @param ranks The mutable map from keys to their ranks.
65+
* @return Whether disjoint sets have been unified.
6666
*/
6767
@Suppress("UNCHECKED_CAST")
6868
internal fun <K, V> unionMutable(
@@ -132,13 +132,13 @@ internal fun <K, V> unionMutable(
132132
* This will create a new set with the given key and the value of the original set.
133133
* When the key doesn't exist, nothing happens.
134134
*
135-
* @param key the key to disunify
136-
* @param roots the mutable map from sets to their values
137-
* @param parents the mutable map from keys to their parent key
138-
* @param ranks the mutable map from keys to their ranks
139-
* @param K the type of keys
140-
* @param V the type of values
141-
* @return whether the key was in the map
135+
* @param K The type of keys.
136+
* @param V The type of values.
137+
* @param key The key to disunify.
138+
* @param roots The mutable map from sets to their values.
139+
* @param parents The mutable map from keys to their parent key.
140+
* @param ranks The mutable map from keys to their ranks.
141+
* @return Whether the key was in the map.
142142
*/
143143
internal fun <K, V> disunionMutable(key: K, roots: MutableMap<K, V>, parents: MutableMap<K, K>, ranks: MutableMap<K, Int>): Boolean {
144144
var rep: K = findMutable(key, roots, parents, ranks) ?: return false
@@ -171,14 +171,14 @@ internal fun <K, V> disunionMutable(key: K, roots: MutableMap<K, V>, parents: Mu
171171
*
172172
* When the key doesn't exist in the map, it is added.
173173
*
174-
* @param key the key of the set to set
175-
* @param value the value to associate with the set
176-
* @param roots the mutable map from sets to their values
177-
* @param parents the mutable map from keys to their parent key
178-
* @param ranks the mutable map from keys to their ranks
179-
* @param K the type of keys
180-
* @param V the type of values
181-
* @return the old value associated with the key; or `null`
174+
* @param K The type of keys.
175+
* @param V The type of values.
176+
* @param key The key of the set to set.
177+
* @param value The value to associate with the set.
178+
* @param roots The mutable map from sets to their values.
179+
* @param parents The mutable map from keys to their parent key.
180+
* @param ranks The mutable map from keys to their ranks.
181+
* @return The old value associated with the key; or `null`.
182182
*/
183183
internal fun <K, V> setMutable(key: K, value: V, roots: MutableMap<K, V>, parents: MutableMap<K, K>, ranks: MutableMap<K, Int>): V? {
184184
val rep = findMutable(key, roots, parents, ranks) ?: key
@@ -192,11 +192,11 @@ internal fun <K, V> setMutable(key: K, value: V, roots: MutableMap<K, V>, parent
192192
*
193193
* When the key doesn't exist in the map, it is added.
194194
*
195-
* @param rep the representative element of the set to set
196-
* @param value the value to associate with the set
197-
* @param roots the mutable map from sets to their values
198-
* @param K the type of keys
199-
* @param V the type of values
195+
* @param K The type of keys.
196+
* @param V The type of values.
197+
* @param rep The representative element of the set to set.
198+
* @param value The value to associate with the set.
199+
* @param roots The mutable map from sets to their values.
200200
*/
201201
internal fun <K, V> setMutableRep(rep: K, value: V, roots: MutableMap<K, V>) {
202202
roots[rep] = value
@@ -207,13 +207,13 @@ internal fun <K, V> setMutableRep(rep: K, value: V, roots: MutableMap<K, V>) {
207207
*
208208
* When the key is the last key of a set, the set is removed.
209209
*
210-
* @param key the key to remove
211-
* @param roots the mutable map from sets to their values
212-
* @param parents the mutable map from keys to their parent key
213-
* @param ranks the mutable map from keys to their ranks
214-
* @param K the type of keys
215-
* @param V the type of values
216-
* @return the value of the set from which the key was removed; or `null` when the key was not found
210+
* @param K The type of keys.
211+
* @param V The type of values.
212+
* @param key The key to remove.
213+
* @param roots The mutable map from sets to their values.
214+
* @param parents The mutable map from keys to their parent key.
215+
* @param ranks The mutable map from keys to their ranks.
216+
* @return The value of the set from which the key was removed; or `null` when the key was not found.
217217
*/
218218
internal fun <K, V> removeMutable(
219219
key: K,
@@ -230,7 +230,7 @@ internal fun <K, V> removeMutable(
230230
/**
231231
* Copies the sets from this disjoint map to a new map.
232232
*
233-
* @return the new map
233+
* @return The new map.
234234
*/
235235
internal fun <K, V> DisjointMap<K, V>.toMapImpl(
236236
roots: Map<K, V>,

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

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ package net.pelsmaeker.collections
55
/**
66
* Returns an empty persistent disjoint map.
77
*
8-
* @param K the type of keys
9-
* @param V the type of values
10-
* @return an empty persistent disjoint map
8+
* @param K The type of keys.
9+
* @param V The type of values.
10+
* @return An empty persistent disjoint map.
1111
*/
1212
fun <K, V> persistentDisjointMapOf(): PersistentDisjointMap<K, V> = PersistentUnionFindMap.emptyOf()
1313

1414
/**
1515
* Returns a persistent disjoint map with the given sets.
1616
*
17-
* @param pairs the pairs of sets, consisting of a set of keys and an associated value
18-
* @param K the type of keys
19-
* @param V the type of values
20-
* @return the created persistent disjoint map
17+
* @param pairs The pairs of sets, consisting of a set of keys and an associated value.
18+
* @param K The type of keys.
19+
* @param V The type of values.
20+
* @return The created persistent disjoint map.
2121
*/
2222
fun <K, V> persistentDisjointMapOf(vararg pairs: Pair<Set<K>, V>): PersistentDisjointMap<K, V> {
2323
return pairs.asIterable().toPersistentDisjointMap()
@@ -26,19 +26,19 @@ fun <K, V> persistentDisjointMapOf(vararg pairs: Pair<Set<K>, V>): PersistentDis
2626
/**
2727
* Returns an empty mutable disjoint map.
2828
*
29-
* @param K the type of keys
30-
* @param V the type of values
31-
* @return an empty mutable disjoint map
29+
* @param K The type of keys.
30+
* @param V The type of values.
31+
* @return An empty mutable disjoint map.
3232
*/
3333
fun <K, V> mutableDisjointMapOf(): MutableDisjointMap<K, V> = MutableUnionFindMap()
3434

3535
/**
3636
* Returns a mutable disjoint map with the given sets.
3737
*
38-
* @param pairs the pairs of sets, consisting of a set of keys and an associated value
39-
* @param K the type of keys
40-
* @param V the type of values
41-
* @return the created mutable disjoint map
38+
* @param pairs The pairs of sets, consisting of a set of keys and an associated value.
39+
* @param K The type of keys.
40+
* @param V The type of values.
41+
* @return The created mutable disjoint map.
4242
*/
4343
fun <K, V> mutableDisjointMapOf(vararg pairs: Pair<Set<K>, V>): MutableDisjointMap<K, V> {
4444
return pairs.asIterable().toMutableDisjointMap()
@@ -49,9 +49,9 @@ fun <K, V> mutableDisjointMapOf(vararg pairs: Pair<Set<K>, V>): MutableDisjointM
4949
*
5050
* If the receiver is already an immutable disjoint map, it is returned as-is.
5151
*
52-
* @param K the type of keys
53-
* @param V the type of values
54-
* @return the resulting immutable disjoint map
52+
* @param K The type of keys.
53+
* @param V The type of values.
54+
* @return The resulting immutable disjoint map.
5555
*/
5656
fun <K, V> DisjointMap<K, V>.toImmutableDisjointMap(): ImmutableDisjointMap<K, V> {
5757
return this as? ImmutableDisjointMap<K, V> ?: this.toPersistentDisjointMap()
@@ -63,9 +63,9 @@ fun <K, V> DisjointMap<K, V>.toImmutableDisjointMap(): ImmutableDisjointMap<K, V
6363
* If the receiver is already a persistent disjoint map, it is returned as-is.
6464
* If the receiver is a persistent disjoint map builder, the result of calling its [PersistentDisjointMap.Builder.build] method is returned.
6565
*
66-
* @param K the type of keys
67-
* @param V the type of values
68-
* @return the resulting persistent disjoint map
66+
* @param K The type of keys.
67+
* @param V The type of values.
68+
* @return The resulting persistent disjoint map.
6969
*/
7070
fun <K, V> DisjointMap<K, V>.toPersistentDisjointMap(): PersistentDisjointMap<K, V> {
7171
return this as? PersistentDisjointMap<K, V>
@@ -76,9 +76,9 @@ fun <K, V> DisjointMap<K, V>.toPersistentDisjointMap(): PersistentDisjointMap<K,
7676
/**
7777
* Returns the given map of sets as a persistent disjoint map.
7878
*
79-
* @param K the type of keys
80-
* @param V the type of values
81-
* @return the resulting persistent disjoint map
79+
* @param K The type of keys.
80+
* @param V The type of values.
81+
* @return The resulting persistent disjoint map.
8282
*/
8383
fun <K, V> Map<Set<K>, V>.toPersistentDisjointMap(): PersistentDisjointMap<K, V> {
8484
return this.entries.map { it.toPair() }.toPersistentDisjointMap()
@@ -87,9 +87,9 @@ fun <K, V> Map<Set<K>, V>.toPersistentDisjointMap(): PersistentDisjointMap<K, V>
8787
/**
8888
* Returns the given map of sets as a mutable disjoint map.
8989
*
90-
* @param K the type of keys
91-
* @param V the type of values
92-
* @return the resulting mutable disjoint map
90+
* @param K The type of keys.
91+
* @param V The type of values.
92+
* @return The resulting mutable disjoint map.
9393
*/
9494
private fun <K, V> Map<Set<K>, V>.toMutableDisjointMap(): MutableDisjointMap<K, V> {
9595
return this.entries.map { it.toPair() }.toMutableDisjointMap()
@@ -98,9 +98,9 @@ private fun <K, V> Map<Set<K>, V>.toMutableDisjointMap(): MutableDisjointMap<K,
9898
/**
9999
* Returns the given iterable of pairs of a set of keys and a value as a persistent disjoint map.
100100
*
101-
* @param K the type of keys
102-
* @param V the type of values
103-
* @return the resulting persistent disjoint map
101+
* @param K The type of keys.
102+
* @param V The type of values.
103+
* @return The resulting persistent disjoint map.
104104
*/
105105
fun <K, V> Iterable<Pair<Set<K>, V>>.toPersistentDisjointMap(): PersistentDisjointMap<K, V> {
106106
return PersistentUnionFindMap.emptyOf<K, V>().builder().addSets(this).build()
@@ -109,9 +109,9 @@ fun <K, V> Iterable<Pair<Set<K>, V>>.toPersistentDisjointMap(): PersistentDisjoi
109109
/**
110110
* Returns the given iterable of pairs of a set of keys and a value as a mutable disjoint map.
111111
*
112-
* @param K the type of keys
113-
* @param V the type of values
114-
* @return the resulting mutable disjoint map
112+
* @param K The type of keys.
113+
* @param V The type of values.
114+
* @return The resulting mutable disjoint map.
115115
*/
116116
private fun <K, V> Iterable<Pair<Set<K>, V>>.toMutableDisjointMap(): MutableDisjointMap<K, V> {
117117
return mutableDisjointMapOf<K, V>().addSets(this)
@@ -120,10 +120,10 @@ private fun <K, V> Iterable<Pair<Set<K>, V>>.toMutableDisjointMap(): MutableDisj
120120
/**
121121
* Adds the given sets to the mutable disjoint map.
122122
*
123-
* @param sets the sets to add, an iterable of pairs of a set of keys and a value
124-
* @param K the type of keys
125-
* @param V the type of values
126-
* @return the receiver
123+
* @param sets The sets to add, an iterable of pairs of a set of keys and a value.
124+
* @param K The type of keys.
125+
* @param V The type of values.
126+
* @return The receiver.
127127
*/
128128
private fun <K, V, T: MutableDisjointMap<K, V>> T.addSets(sets: Iterable<Pair<Set<K>, V>>): T {
129129
for ((keys, value) in sets) {
@@ -140,10 +140,10 @@ private fun <K, V, T: MutableDisjointMap<K, V>> T.addSets(sets: Iterable<Pair<Se
140140
*
141141
* The mutable disjoint map passed to [mutator] had the same contents as the persistent disjoint map.
142142
*
143-
* @param mutator the closure that mutates the map
144-
* @param K the type of keys
145-
* @param V the type of values
146-
* @return a persistent disjoint map with the modifications applied
143+
* @param mutator The closure that mutates the map.
144+
* @param K The type of keys.
145+
* @param V The type of values.
146+
* @return A persistent disjoint map with the modifications applied.
147147
*/
148148
inline fun <K, V> PersistentDisjointMap<K, V>.mutate(mutator: (MutableDisjointMap<K, V>) -> Unit): PersistentDisjointMap<K, V>
149149
= this.builder().apply(mutator).build()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface ImmutableDisjointMap<K, out V> : DisjointMap<K, V> {
1313
/**
1414
* Copies the sets from this disjoint map to a new map.
1515
*
16-
* @return the new map
16+
* @return The new map.
1717
*/
1818
override fun toMap(): ImmutableMap<Set<K>, V>
1919

0 commit comments

Comments
 (0)