Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 74 lines (54 sloc) 2.351 kb
fccc685 Initial open-source release
MLstate authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18
19 (**
20 UnionFind.
21
22 This module offers an imperative implementation for the union find algorithm
23 based on linked pointer and collapsing rules.
24
25 A support is given for hooking values to keys.
26
27 @author Henri Binsztok
28 @author Mikolaj Konarski
29 @author Mathieu Barbin
30 *)
31
32 (** {6 Union Find with key/value } *)
33
34 (**
35 the type of an element. an element can be seen as a set, or an equivalence class,
36 represented by a elt of type 'a.
37
38 <!> values of type [('a, 'b) t] are mutable.
39
40 performing an [union] or [replace] lead to change the returned key/values of a elt.
41 *)
42 type ('a, 'b) t
43
44 (** build a new set *)
45 val make : 'a -> 'b -> ('a, 'b) t
46
47 (** merging 2 elts.
48 <!> The key/value resulting in the merged elt is in unspecified.
49 @see 'replace' if you need to specify what key/value should be keeped *)
50 val union : ('a, 'b) t -> ('a, 'b) t -> unit
51
52 (**
53 this is like an [union] but assure that the [key,value] of the [keeped] element
54 are keeped. Essentially, this function is there because in any other implementation,
55 the behavior of the function [union] may be unspecified.
56 *)
57 val replace : replaced:('a, 'b) t -> keeped:('a, 'b) t -> unit
58
59 (** find pointed key/value by an elt
60 @see 'key' for getting only the key
61 @see 'value' for getting only the value *)
62 val find : ('a, 'b) t -> 'a * 'b
63
64 (** like [key t] is like [fst (find t)] but slighty optimized
65 @see 'find' for getting key * value *)
66 val key : ('a, 'b) t -> 'a
67
68 (** like [value t] is like [snd (find t)] but slighty optimized
69 @see 'find' for getting key * value *)
70 val value : ('a, 'b) t -> 'b
71
72 (** changing the hooked by this class of key *)
73 val changeval : ('a, 'b) t -> 'b -> unit
Something went wrong with that request. Please try again.