Module Bunch


module Bunch: sig .. end
Collection of elements with fast union.


A multi-set like collection of elements with a fast union operation that shares the unioned collections, and a filter operation that retains sharing.
type 'a t 
Collection of elements.
val size : 'a t -> int
Number of elements in a bunch.


val empty : 'a t
An empty bunch.


val is_empty : 'a t -> bool
Is a bunch empty?
val singleton : 'a -> 'a t
A singleton bunch.


val couple : 'a -> 'a -> 'a t
A bunch with the two elements provided.


val imbalance : 'a t -> int
The worst imbalance in the internal tree representation of a bunch. Optimally balanced representations have a an imbalance of 0. A completely unbalanced representation will have an imbalance within 1 of the size of the bunch.


val add : 'a -> 'a t -> 'a t
Add an element to a bunch.


val add_balanced : 'a -> 'a t -> 'a t
Add an element to a bunch.


val join : 'a t -> 'a t -> 'a t
The constant time union of two bunches.


val iter : ('a -> unit) -> 'a t -> unit
iter f b evaluates f on all the elements of b.


val iter_const : ('a -> 'b -> unit) -> 'a -> 'b t -> unit
iter_const f c b is Bunch.iter (f c) b, only faster since applying closures is slow.
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
filter_const p c b is Bunch.filter (p c) b, only faster since applying closures is slow.
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
partition_const p c b is Bunch.partition (p c) b, only faster since applying closures is slow.
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
A bunch with all the elements in the list.


val to_list : 'a t -> 'a list
A list of all elements in the bunch.



Hosted by the SourceForge.net Logo* web site.
*Other names and brands may be claimed as the property of others.