-
Notifications
You must be signed in to change notification settings - Fork 63
/
union_find.mli
37 lines (26 loc) · 1.33 KB
/
union_find.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(** Imperative data structure for representing disjoint sets.
Union find is used to implement an equivalence relation on objects, where
the equivalence relation can dynamically be coarsened by "union"ing two
equivalence classes together.
All of the operations are effectively (amortized) constant time.
@see <en.wikipedia.org/wiki/Disjoint-set_data_structure> wikipedia.
This implementation is not thread-safe.
*)
open! Import
(** [type 'a t] is the type of objects, where each object is part of an
equivalence class that is associated with a single value of type ['a]. *)
type 'a t
(** [create v] returns a new object in its own equivalence class that has value [v]. *)
val create : 'a -> 'a t
(** [get t] returns the value of the class of [t]. *)
val get : 'a t -> 'a
(** [set t v] sets the value of the class of [t] to [v]. *)
val set : 'a t -> 'a -> unit
(** [same_class t1 t2] returns true iff [t1] and [t2] are in the same equivalence class.
*)
val same_class : 'a t -> 'a t -> bool
(** [union t1 t2] makes the class of [t1] and the class of [t2] be the same (if they are
already equal, then nothing changes). The value of the combined class is the value of
[t1] or [t2]; it is unspecified which. After [union t1 t2], it will always be the
case that [same_class t1 t2]. *)
val union: 'a t -> 'a t -> unit