module Bunch:Collection of elements with fast union.sig
..end
type 'a
t
val size : 'a t -> int
val empty : 'a t
val is_empty : 'a t -> bool
val singleton : 'a -> 'a t
val couple : 'a -> 'a -> 'a t
val imbalance : 'a t -> int
imbalance b >= 0
val add : 'a -> 'a t -> 'a t
Bunch.imbalance
b <=
Bunch.imbalance
(add x b) <=
Bunch.imbalance
b + 1
Bunch.size
(add x b) = 1 +
Bunch.size
b
val add_balanced : 'a -> 'a t -> 'a t
Bunch.imbalance
(add_balanced x b) <=
Bunch.imbalance
<=
Bunch.imbalance
(add_balanced x b) + 1
Bunch.size
(add_balanced x b) = 1 +
Bunch.size
b
val join : 'a t -> 'a t -> 'a t
Bunch.imbalance
(join b c) = max (max (abs (size b - size c),
Bunch.imbalance
b),
Bunch.imbalance
c)
Bunch.size
(join a b) =
Bunch.size
a +
Bunch.size
b
val iter : ('a -> unit) -> 'a t -> unit
iter f b
evaluates f
on all the elements of b
.
b
val iter_const : ('a -> 'b -> unit) -> 'a -> 'b t -> unit
val filter : ('a -> bool) -> 'a t -> 'a t
filter p b
is a bunch containing all elements of b
that
satisfy predicate b
.
Not tail-recursive, but sharing preserving.
val filter_const : ('a -> 'b -> bool) -> 'a -> 'b t -> 'b t
val partition : ('a -> bool) -> 'a t -> 'a t * 'a t
partition p b
is a pair of bunches (b1, b2)
such that b1
contains all elements of b
that satisfy predicate b
, and
b2
contains the rest.
Not tail-recursive, but sharing preserving.
val partition_const : ('a -> 'b -> bool) -> 'a -> 'b t -> 'b t * 'b t
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
fold f a b
folds f
over every element of b
using a
as an
initial value.
val map : ('a -> 'b) -> 'a t -> 'b t
map f a
maps every element of a
using f
.
val exists : ('a -> bool) -> 'a t -> bool
exists p b
is true if p x
holds for any x in b
.
val for_all : ('a -> bool) -> 'a t -> bool
for_all p b
is true if p x
holds for every x in b
. val of_list : 'a list -> 'a t
val to_list : 'a t -> 'a list