type 'a t

A bounded heap of values of type 'a.

val create : int -> _ t

create n is a heap that holds at most n elements.

type 'a entry

An element in a heap.

type ptr = private int

The index of an entry.

val ptr : 'a entry -> ptr

ptr e is the index of e.

  • raises Invalid_arg

    if e has already been freed.

exception No_space
val alloc : 'a t -> 'a -> extra_data:'b -> 'a entry

alloc t a ~extra_data adds the value a to t and returns a pointer to that value, or raises No_space if no space exists in t.

  • parameter extra_data

    Prevent this from being GC'd until free is called.

val free : 'a t -> ptr -> 'a

free t p returns the element referenced by p and removes it from the heap. Has undefined behaviour if p has already been freed.

val in_use : 'a t -> int

in_use t is the number of entries currently allocated.