Module CCHeap.Make_from_compare
A convenient version of Make
that take a TOTAL_ORD
instead of a partially ordered module. It allow to directly pass modules that implement compare
without implementing leq
explicitly
Parameters
Signature
type elt
= E.t
type t
val empty : t
empty
returns the empty heap.
val is_empty : t -> bool
is_empty h
returnstrue
if the heaph
is empty.
val filter : (elt -> bool) -> t -> t
filter p h
filters values, only retaining the ones that satisfy the predicatep
. Linear time at least.
val find_min_exn : t -> elt
find_min_exn h
is likefind_min
but can fail.- raises Empty
if the heap is empty.
val take : t -> (t * elt) option
take h
extracts and returns the minimum element, and the new heap (without this element), orNone
if the heaph
is empty.
val delete_one : (elt -> elt -> bool) -> elt -> t -> t
delete_one eq x h
useseq
to find one occurrence of a valuex
if it exist in the heaph
, and delete it. Ifh
do not containx
then it returnh
.- since
- 2.0
val delete_all : (elt -> elt -> bool) -> elt -> t -> t
delete_all eq x h
useseq
to find allx
inh
and delete them. Ifh
do not containx
then it returnh
. The difference withfilter
is thatdelete_all
stops as soon as it enters a subtree whose root is bigger than the element.- since
- 2.0
val iter : (elt -> unit) -> t -> unit
iter f h
iterates over the heaph
invokingf
with the current element.
val size : t -> int
size h
is the number of elements in the heaph
. Linear complexity.
Conversions
val to_list_sorted : t -> elt list
to_list_sorted h
returns the elements of the heaph
in increasing order.- since
- 1.1
val add_list : t -> elt list -> t
add_list h l
adds the elements of the listl
into the heaph
. An element occurring several times will be added that many times to the heap.- since
- 0.16
val add_seq : t -> elt Stdlib.Seq.t -> t
add_seq h seq
is likeadd_list
. Renamed fromadd_std_seq
since 3.0.- since
- 3.0
val of_iter : elt iter -> t
of_iter iter
builds a heap from a giveniter
. Complexity:O(n log n)
.- since
- 2.8
val of_seq : elt Stdlib.Seq.t -> t
of_seq seq
builds a heap from a givenSeq.t
. Complexity:O(n log n)
. Renamed fromof_seq
since 3.0.- since
- 3.0
val to_seq : t -> elt Stdlib.Seq.t
to_seq h
returns aSeq.t
of the elements of the heaph
. Renamed fromto_std_seq
since 3.0.- since
- 3.0
val to_iter_sorted : t -> elt iter
to_iter_sorted h
returns aiter
by iterating on the elements ofh
, in increasing order.- since
- 2.8
val to_seq_sorted : t -> elt Stdlib.Seq.t
to_seq_sorted h
returns aSeq.t
by iterating on the elements ofh
, in increasing order. Renamed fromto_std_seq_sorted
since 3.0.- since
- 3.0
val to_string : ?sep:string -> (elt -> string) -> t -> string
to_string ?sep f h
prints the heaph
in a string usingsep
as a given separator (default ",") between each element (converted to a string usingf
).- since
- 2.7
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
printsh
onppf
. Each element is formatted withppf
,pp_start
is called at the beginning,pp_stop
is called at the end,pp_sep
is called between each elements. By defaultspp_start
andpp_stop
does nothing andpp_sep
defaults to (fun out -> Format.fprintf out ",@ "). Renamed fromprint
since 2.0- since
- 0.16