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.ttype t
val empty : temptyreturns the empty heap.
val is_empty : t -> boolis_empty hreturnstrueif the heaphis empty.
val filter : (elt -> bool) -> t -> tfilter p hfilters values, only retaining the ones that satisfy the predicatep. Linear time at least.
val find_min_exn : t -> eltfind_min_exn his likefind_minbut can fail.- raises Empty
if the heap is empty.
val take : t -> (t * elt) optiontake hextracts and returns the minimum element, and the new heap (without this element), orNoneif the heaphis empty.
val delete_one : (elt -> elt -> bool) -> elt -> t -> tdelete_one eq x huseseqto find one occurrence of a valuexif it exist in the heaph, and delete it. Ifhdo not containxthen it returnh.- since
- 2.0
val delete_all : (elt -> elt -> bool) -> elt -> t -> tdelete_all eq x huseseqto find allxinhand delete them. Ifhdo not containxthen it returnh. The difference withfilteris thatdelete_allstops as soon as it enters a subtree whose root is bigger than the element.- since
- 2.0
val iter : (elt -> unit) -> t -> unititer f hiterates over the heaphinvokingfwith the current element.
val size : t -> intsize his the number of elements in the heaph. Linear complexity.
Conversions
val to_list_sorted : t -> elt listto_list_sorted hreturns the elements of the heaphin increasing order.- since
- 1.1
val add_list : t -> elt list -> tadd_list h ladds the elements of the listlinto 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 -> tadd_seq h seqis likeadd_list. Renamed fromadd_std_seqsince 3.0.- since
- 3.0
val of_iter : elt iter -> tof_iter iterbuilds a heap from a giveniter. Complexity:O(n log n).- since
- 2.8
val of_seq : elt Stdlib.Seq.t -> tof_seq seqbuilds a heap from a givenSeq.t. Complexity:O(n log n). Renamed fromof_seqsince 3.0.- since
- 3.0
val to_seq : t -> elt Stdlib.Seq.tto_seq hreturns aSeq.tof the elements of the heaph. Renamed fromto_std_seqsince 3.0.- since
- 3.0
val to_iter_sorted : t -> elt iterto_iter_sorted hreturns aiterby iterating on the elements ofh, in increasing order.- since
- 2.8
val to_seq_sorted : t -> elt Stdlib.Seq.tto_seq_sorted hreturns aSeq.tby iterating on the elements ofh, in increasing order. Renamed fromto_std_seq_sortedsince 3.0.- since
- 3.0
val to_string : ?sep:string -> (elt -> string) -> t -> stringto_string ?sep f hprints the heaphin a string usingsepas 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 printerpp ?pp_start ?pp_stop ?pp_sep ppf hprintshonppf. Each element is formatted withppf,pp_startis called at the beginning,pp_stopis called at the end,pp_sepis called between each elements. By defaultspp_startandpp_stopdoes nothing andpp_sepdefaults to (fun out -> Format.fprintf out ",@ "). Renamed fromprintsince 2.0- since
- 0.16