type 'a tof_sexp and bin_io functions aren't supplied for heaps due to the difficulties in reconstructing the correct comparison function when de-serializing.
val sexp_of_t : ('a -> Ppx_sexp_conv_lib.Sexp.t) -> 'a t -> Ppx_sexp_conv_lib.Sexp.t
Mutation of the heap during iteration is not supported, but there is no check to prevent it. The behavior of a heap that is mutated during iteration is undefined.
include Core_kernel.Container.S1 with type 'a t := 'a t
val mem : 'a t -> 'a -> equal:('a -> 'a -> bool) -> boolChecks whether the provided element is there, using
equal.
val length : 'a t -> intval is_empty : 'a t -> boolval iter : 'a t -> f:('a -> unit) -> unitval fold : 'a t -> init:'accum -> f:('accum -> 'a -> 'accum) -> 'accumfold t ~init ~freturnsf (... f (f (f init e1) e2) e3 ...) en, wheree1..enare the elements oft
val fold_result : 'a t -> init:'accum -> f:('accum -> 'a -> ('accum, 'e) Base.Result.t) -> ('accum, 'e) Base.Result.tfold_result t ~init ~fis a short-circuiting version offoldthat runs in theResultmonad. Iffreturns anError _, that value is returned without any additional invocations off.
val fold_until : 'a t -> init:'accum -> f:('accum -> 'a -> ('accum, 'final) Base__Container_intf.Export.Continue_or_stop.t) -> finish:('accum -> 'final) -> 'finalfold_until t ~init ~f ~finishis a short-circuiting version offold. IffreturnsStop _the computation ceases and results in that value. IffreturnsContinue _, the fold will proceed. Iffnever returnsStop _, the final result is computed byfinish.Example:
type maybe_negative = | Found_negative of int | All_nonnegative of { sum : int } (** [first_neg_or_sum list] returns the first negative number in [list], if any, otherwise returns the sum of the list. *) let first_neg_or_sum = List.fold_until ~init:0 ~f:(fun sum x -> if x < 0 then Stop (Found_negative x) else Continue (sum + x)) ~finish:(fun sum -> All_nonnegative { sum }) ;; let x = first_neg_or_sum [1; 2; 3; 4; 5] val x : maybe_negative = All_nonnegative {sum = 15} let y = first_neg_or_sum [1; 2; -3; 4; 5] val y : maybe_negative = Found_negative -3
val exists : 'a t -> f:('a -> bool) -> boolReturns
trueif and only if there exists an element for which the provided function evaluates totrue. This is a short-circuiting operation.
val for_all : 'a t -> f:('a -> bool) -> boolReturns
trueif and only if the provided function evaluates totruefor all elements. This is a short-circuiting operation.
val count : 'a t -> f:('a -> bool) -> intReturns the number of elements for which the provided function evaluates to true.
val sum : (module Base__Container_intf.Summable with type t = 'sum) -> 'a t -> f:('a -> 'sum) -> 'sumReturns the sum of
f ifor alliin the container.
val find : 'a t -> f:('a -> bool) -> 'a optionReturns as an
optionthe first element for whichfevaluates to true.
val find_map : 'a t -> f:('a -> 'b option) -> 'b optionReturns the first evaluation of
fthat returnsSome, and returnsNoneif there is no such element.
val to_list : 'a t -> 'a listval to_array : 'a t -> 'a arrayval min_elt : 'a t -> compare:('a -> 'a -> int) -> 'a optionReturns a minimum (resp maximum) element from the collection using the provided
comparefunction, orNoneif the collection is empty. In case of a tie, the first element encountered while traversing the collection is returned. The implementation usesfoldso it has the same complexity asfold.
val max_elt : 'a t -> compare:('a -> 'a -> int) -> 'a option
include Core_kernel.Invariant.S1 with type 'a t := 'a t
val invariant : ('a -> unit) -> 'a t -> unit
val min_elt : 'a t -> compare:('a -> 'a -> int) -> 'a optionval max_elt : 'a t -> compare:('a -> 'a -> int) -> 'a optionval create : ?min_size:int -> cmp:('a -> 'a -> int) -> unit -> 'a tcreate ?min_size ~cmpreturns a new min-heap that can storemin_sizeelements without reallocations, using ordering functioncmp.The top of the heap is the smallest element as determined by the provided comparison function. In particular, if
cmp x y < 0thenxwill be "on top of"yin the heap.Memory use can be surprising in that the underlying pool never shrinks, so current memory use will at least be proportional to the largest number of elements that the heap has ever held.
val of_array : 'a array -> cmp:('a -> 'a -> int) -> 'a tmin_size(seecreate) will be set to the size of the input array or list.
val of_list : 'a list -> cmp:('a -> 'a -> int) -> 'a tval top : 'a t -> 'a optionReturns the top (i.e., smallest) element of the heap.
val top_exn : 'a t -> 'aval add : 'a t -> 'a -> unitval remove_top : _ t -> unitremove_top tdoes nothing iftis empty.
val pop : 'a t -> 'a optionpopremoves and returns the top (i.e. least) element.
val pop_exn : 'a t -> 'aval pop_if : 'a t -> ('a -> bool) -> 'a optionpop_if t condreturnsSome top_elementoftif it satisfies conditioncond, removing it, orNonein any other case.
module Elt : sig ... endval add_removable : 'a t -> 'a -> 'a Elt.tadd_removable t vaddsvtot, returning a token that can be used to deletevfromtin lg(n) amortized time.Note that while
adddoesn't allocate unless the underlying pool needs to be resized,add_removablealways allocates. TheUnsafemodule has a non-allocating alternative.
val remove : 'a t -> 'a Elt.t -> unitIf
tandtokenare mismatched then behavior is undefined. Trying toremovean already removed token (by an earlier call toremoveorpopfor instance) is a no-op, but keepingtokenaround after it has been removed may lead to memory leaks since it has a reference to the heap.
val update : 'a t -> 'a Elt.t -> 'a -> 'a Elt.tupdate t token vis shorthand forremove t token; add_removable t v.
val find_elt : 'a t -> f:('a -> bool) -> 'a Elt.t optionfind_elt t ~f. Iffis true for some element int, return anElt.tfor that element. This operation is O(n).
module Unsafe : sig ... end