Utils.Heap

This document is auto-generated for Owl’s APIs. #12 entries have been extracted.

Github: {Signature} {Implementation}

Type definition

type 'a t

Type of a min heap.

Basic functions

val make : ('a -> 'a -> int) -> 'a t

make cmp creates an empty min heap, using cmp as a comparison function.

source code

val make_int : ?initial_size:int -> (int -> int -> int) -> int t

make_int ?initial_size cmp creates an empty integer heap, using cmp as a comparison function and pre-allocates a space of initial_size elements.

source code

val make_float : ?initial_size:int -> (float -> float -> int) -> float t

make_float ?initial_size cmp creates an empty float heap, using cmp as a comparison function and pre-allocates a space of initial_size elements.

source code

val size : 'a t -> int

size heap returns the number of elements in the heap.

source code

val push : 'a t -> 'a -> unit

push heap x pushes x into heap. Time complexity is O(log(n)), where n is the size of heap.

source code

val pop : 'a t -> 'a

pop heap pops the minimal element from heap. It raises an exception if the heap is empty. Time complexity is O(log(n)), where n is the size of heap.

source code

val peek : 'a t -> 'a

peek heap returns the value of the minimal element in heap but it does not remove the element from the heap. Raises an exception if the heap is empty. Time complexity is O(1).

source code

val is_empty : 'a t -> bool

is_empty heap returns true if heap is empty, false otherwise.

source code

val to_array : 'a t -> 'a array

to_array heap returns the elements in heap into an (unsorted) array.

source code