2 USING: help.markup help.syntax kernel assocs math ;
5 { $values { "disjoint-set" disjoint-set } }
6 { $description "Creates a new disjoint set data structure with no elements." } ;
9 { $values { "a" object } { "disjoint-set" disjoint-set } }
10 { $description "Adds a new element to the disjoint set, initially only equivalent to itself." } ;
13 { $values { "a" object } { "disjoint-set" disjoint-set } { "n" integer } }
14 { $description "Outputs the number of elements in the equivalence class of " { $snippet "a" } "." } ;
17 { $values { "a" object } { "b" object } { "disjoint-set" disjoint-set } { "?" "a boolean" } }
18 { $description "Tests if two elements belong to the same equivalence class." } ;
21 { $values { "a" object } { "b" object } { "disjoint-set" disjoint-set } }
22 { $description "Merges the equivalence classes of two elements, which must previously have been added with " { $link add-atom } "." } ;
24 HELP: assoc>disjoint-set
25 { $values { "assoc" assoc } { "disjoint-set" disjoint-set } }
26 { $description "Given an assoc representation of a graph where the keys are vertices and key/value pairs are edges, creates a disjoint set whose elements are the keys of assoc, and two keys are equvalent if they belong to the same connected component of the graph." }
29 "USING: disjoint-sets kernel prettyprint ;"
30 "H{ { 1 1 } { 2 1 } { 3 4 } { 4 4 } { 5 3 } } assoc>disjoint-set"
39 ARTICLE: "disjoint-sets" "Disjoint sets"
40 "The " { $vocab-link "disjoint-sets" } " vocabulary implements the " { $emphasis "disjoint set" } " data structure (also known as " { $emphasis "union-find" } ", after the two main operations which it supports) that represents a set of elements partitioned into disjoint equivalence classes, or alternatively, an equivalence relation on a set."
42 "The two main supported operations are equating two elements, which joins their equivalence classes, and checking if two elements belong to the same equivalence class. Both operations have the time complexity of the inverse Ackermann function, which for all intents and purposes is constant time."
44 "The class of disjoint sets:"
45 { $subsection disjoint-set }
46 "Creating new disjoint sets:"
47 { $subsection <disjoint-set> }
48 { $subsection assoc>disjoint-set }
50 { $subsection equiv? }
51 { $subsection equiv-set-size }
53 { $subsection add-atom }
55 { $subsection equate }
56 "Additionally, disjoint sets implement the " { $link clone } " generic word." ;
58 ABOUT: "disjoint-sets"