Skip to content
This repository
tag: v1102
Fetching contributors…

Cannot retrieve contributors at this time

file 73 lines (54 sloc) 2.351 kb
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
(*
Copyright © 2011 MLstate

This file is part of OPA.

OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.

OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.

You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)

(**
UnionFind.

This module offers an imperative implementation for the union find algorithm
based on linked pointer and collapsing rules.

A support is given for hooking values to keys.

@author Henri Binsztok
@author Mikolaj Konarski
@author Mathieu Barbin
*)

(** {6 Union Find with key/value } *)

(**
the type of an element. an element can be seen as a set, or an equivalence class,
represented by a elt of type 'a.
<!> values of type [('a, 'b) t] are mutable.

performing an [union] or [replace] lead to change the returned key/values of a elt.
*)
type ('a, 'b) t

(** build a new set *)
val make : 'a -> 'b -> ('a, 'b) t

(** merging 2 elts.
<!> The key/value resulting in the merged elt is in unspecified.
@see 'replace' if you need to specify what key/value should be keeped *)
val union : ('a, 'b) t -> ('a, 'b) t -> unit

(**
this is like an [union] but assure that the [key,value] of the [keeped] element
are keeped. Essentially, this function is there because in any other implementation,
the behavior of the function [union] may be unspecified.
*)
val replace : replaced:('a, 'b) t -> keeped:('a, 'b) t -> unit

(** find pointed key/value by an elt
@see 'key' for getting only the key
@see 'value' for getting only the value *)
val find : ('a, 'b) t -> 'a * 'b

(** like [key t] is like [fst (find t)] but slighty optimized
@see 'find' for getting key * value *)
val key : ('a, 'b) t -> 'a

(** like [value t] is like [snd (find t)] but slighty optimized
@see 'find' for getting key * value *)
val value : ('a, 'b) t -> 'b

(** changing the hooked by this class of key *)
val changeval : ('a, 'b) t -> 'b -> unit
Something went wrong with that request. Please try again.