package tezos-context

  1. Overview
  2. Docs

An implementation of append-only arenas of fixed-length strings, with support for manual expansion.

type t
val create : elt_length:int -> initial_capacity:int -> t

create ~elt_length:len ~initial_capacity:n is an empty arena of strings of length len, with space sufficient to store n values.

val is_full : t -> bool

is_full t is true iff t has no remaining space for elements.

val expand : t -> int -> unit

expand t n re-allocates arena t to support storing up to n-many elements. Existing elements in the arena retain their original ids.

  • raises Invalid_argument

    if n is less than the current capacity of t.

type id

The type of references to allocated elements in an arena.

val allocate : t -> string -> id

allocate t s adds the string s to arena t, returning a reference to the storage location that may later be dereferenced to get back s.

  • raises Invalid_argument

    if t is_full. The behaviour is undefined if the length of s is not equal to the elt_length of t.

val dereference : t -> id -> string

dereference t id is the string that was passed to the allocate call that returned id. The behaviour is undefined if id was not created by an allocation within t.

val elt_equal : t -> id -> string -> bool

elt_equal t id s is equivalent to String.equal (dereference t id) s, but more efficient.

OCaml

Innovation. Community. Security.