Parameters
Signature
type elt = E.ttype t
val empty : tEmpty heap.
val is_empty : t -> boolIs the heap empty?
exception Empty
val merge : t -> t -> tMerge two heaps.
val insert : elt -> t -> tInsert a value in the heap.
val add : t -> elt -> tSynonym to insert.
val filter : (elt -> bool) -> t -> tFilter values, only retaining the ones that satisfy the predicate. Linear time at least.
val find_min : t -> elt optionFind minimal element.
val find_min_exn : t -> eltLike find_min but can fail.
- raises Empty
if the heap is empty.
val take : t -> (t * elt) optionExtract and return the minimum element, and the new heap (without this element), or None if the heap is empty.
val take_exn : t -> t * eltLike take, but can fail.
- raises Empty
if the heap is empty.
val delete_one : (elt -> elt -> bool) -> elt -> t -> tDelete one occurrence of a value if it exist in the heap. delete_one eq x h, use eq to find one x in h and delete it. If h do not contain x then it return h.
- since
- 2.0
val delete_all : (elt -> elt -> bool) -> elt -> t -> tDelete all occurrences of a value in the heap. delete_all eq x h, use 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.
- since
- 2.0
val iter : (elt -> unit) -> t -> unitIterate on elements.
val fold : ('a -> elt -> 'a) -> 'a -> t -> 'aFold on all values.
val size : t -> intNumber of elements (linear complexity).
Conversions
The interface of of_gen, of_seq, of_klist has changed since 0.16 (the old signatures are now add_seq, add_gen, add_klist).
val to_list : t -> elt listReturn the elements of the heap, in no particular order.
val to_list_sorted : t -> elt listReturn the elements in increasing order.
- since
- 1.1
val add_list : t -> elt list -> tAdd the elements of the list to the heap. An element occurring several times will be added that many times to the heap.
- since
- 0.16
val of_list : elt list -> tof_list l is add_list empty l. Complexity: O(n log n).
val add_seq : t -> elt sequence -> t- since
- 0.16
val of_seq : elt sequence -> tBuild a heap from a given sequence. Complexity: O(n log n).
val to_seq : t -> elt sequenceReturn a sequence of the elements of the heap.
val to_seq_sorted : t -> elt sequenceIterate on the elements, in increasing order.
- since
- 1.1
val add_klist : t -> elt klist -> t- since
- 0.16
val of_klist : elt klist -> tBuild a heap from a given klist. Complexity: O(n log n).
val to_klist : t -> elt klistReturn a klist of the elements of the heap.
val add_gen : t -> elt gen -> t- since
- 0.16
val of_gen : elt gen -> tBuild a heap from a given gen. Complexity: O(n log n).
val to_gen : t -> elt genReturn a gen of the elements of the heap.
val to_tree : t -> elt ktreeReturn a ktree of the elements of the heap.
val pp : ?sep:string -> elt printer -> t printerPrinter. Renamed from print since 2.0
- since
- 0.16