CCHeap.Make
module E : PARTIAL_ORD
type elt = E.t
val empty : t
empty
returns the empty heap.
val is_empty : t -> bool
is_empty h
returns true
if the heap h
is empty.
filter p h
filters values, only retaining the ones that satisfy the predicate p
. Linear time at least.
take h
extracts and returns the minimum element, and the new heap (without this element), or None
if the heap h
is empty.
delete_one eq x h
uses eq
to find one occurrence of a value x
if it exist in the heap h
, and delete it. If h
do not contain x
then it return h
.
delete_all eq x h
uses eq
to find all x
in h
and delete them. If h
do not contain x
then it return h
. The difference with filter
is that delete_all
stops as soon as it enters a subtree whose root is bigger than the element.
iter f h
iterates over the heap h
invoking f
with the current element.
val size : t -> int
size h
is the number of elements in the heap h
. Linear complexity.
to_list_sorted h
returns the elements of the heap h
in increasing order.
add_list h l
adds the elements of the list l
into the heap h
. An element occurring several times will be added that many times to the heap.
add_seq h seq
is like add_list
. Renamed from add_std_seq
since 3.0.
of_seq seq
builds a heap from a given Seq.t
. Complexity: O(n log n)
. Renamed from of_seq
since 3.0.
to_seq h
returns a Seq.t
of the elements of the heap h
. Renamed from to_std_seq
since 3.0.
to_iter_sorted h
returns a iter
by iterating on the elements of h
, in increasing order.
to_seq_sorted h
returns a Seq.t
by iterating on the elements of h
, in increasing order. Renamed from to_std_seq_sorted
since 3.0.
to_string ?sep f h
prints the heap h
in a string using sep
as a given separator (default ",") between each element (converted to a string using f
).
val pp : ?pp_start:unit printer -> ?pp_stop:unit printer -> ?pp_sep:unit printer -> elt printer -> t printer
pp ?pp_start ?pp_stop ?pp_sep ppf h
prints h
on ppf
. Each element is formatted with ppf
, pp_start
is called at the beginning, pp_stop
is called at the end, pp_sep
is called between each elements. By defaults pp_start
and pp_stop
does nothing and pp_sep
defaults to (fun out -> Format.fprintf out ",@ "). Renamed from print
since 2.0