diff --git a/util/src/main/java/dev/openrs2/util/collect/DisjointSet.kt b/util/src/main/java/dev/openrs2/util/collect/DisjointSet.kt index 1b90cdb1..484645be 100644 --- a/util/src/main/java/dev/openrs2/util/collect/DisjointSet.kt +++ b/util/src/main/java/dev/openrs2/util/collect/DisjointSet.kt @@ -1,5 +1,10 @@ package dev.openrs2.util.collect +/** + * A data structure containing a set of elements partitioned into a number of + * non-overlapping subsets. New elements belong to singleton subsets. The + * [union] function combines two subsets together into a single larger subset. + */ interface DisjointSet : Iterable> { interface Partition : Iterable diff --git a/util/src/main/java/dev/openrs2/util/collect/ForestDisjointSet.kt b/util/src/main/java/dev/openrs2/util/collect/ForestDisjointSet.kt index cb2a0245..c1d061d2 100644 --- a/util/src/main/java/dev/openrs2/util/collect/ForestDisjointSet.kt +++ b/util/src/main/java/dev/openrs2/util/collect/ForestDisjointSet.kt @@ -2,6 +2,11 @@ package dev.openrs2.util.collect import java.util.ArrayDeque +/** + * A [DisjointSet] implementation backed by a disjoint-set forest, as described + * in chapter 21.3 of the third edition of CLRS. It uses path compression and + * union by rank. + */ class ForestDisjointSet : DisjointSet { private class Node(val value: T) : DisjointSet.Partition { val children = mutableListOf>()