package grenier

  1. Overview
  2. Docs

Module Physh.MapSource

Maps from objects, compared by physical equality, to arbitrary values. A key has at most one binding.

Sourcetype ('a, 'b) t

A mutable map from keys of type 'a to values of type 'b.

Sourceval create : unit -> ('a, 'b) t

create () returns a new, empty map. It does not allocate any storage until the first binding is added: empty maps are cheap.

Sourceval length : ('a, 'b) t -> int

length t is the number of bindings of t. Constant time.

Sourceval is_empty : ('a, 'b) t -> bool

is_empty t is length t = 0.

Sourceval find : ('a, 'b) t -> 'a -> 'b

find t k returns the value bound to k.

Sourceval find_opt : ('a, 'b) t -> 'a -> 'b option

find_opt t k returns Some v if k is bound to v, None otherwise.

Sourceval mem : ('a, 'b) t -> 'a -> bool

mem t k is true if k is bound in t.

Sourceval add : ('a, 'b) t -> 'a -> 'b -> unit

add t k v binds k to v, replacing any existing binding.

Sourceval add_if_new : ('a, 'b) t -> 'a -> 'b -> 'b option

add_if_new t k v binds k to v if k is not bound. Returns the previous binding: None if k was absent (it is now bound to v), Some v' if k was bound to v' (left unchanged).

Sourceval add_overwrite : ('a, 'b) t -> 'a -> 'b -> 'b option

add_overwrite t k v binds k to v, replacing any existing binding. Returns the previous binding: None if k was absent, Some v' if k was bound to v'.

Sourceval remove : ('a, 'b) t -> 'a -> unit

remove t k removes the binding of k. Does nothing if k is not bound.

Sourceval clear : ('a, 'b) t -> unit

clear t removes all bindings of t, keeping its storage for reuse.

Sourceval reset : ('a, 'b) t -> unit

reset t removes all bindings of t and releases its storage: t is then as cheap as a new map.

Sourceval iter : ('a -> 'b -> unit) -> ('a, 'b) t -> unit

iter f t applies f k v to each binding of t, in an unspecified order. f can look up t; if it modifies t, it is unspecified whether the added (or removed) bindings are visited, and which value is passed for an overwritten binding.

Sourceval fold : ('a -> 'b -> 'acc -> 'acc) -> ('a, 'b) t -> 'acc -> 'acc

fold f t acc is f kN vN (... (f k1 v1 acc)), where (k1, v1) ... (kN, vN) are the bindings of t, in an unspecified order. Same restrictions as iter.