package grenier

  1. Overview
  2. Docs

Module Physh.SetSource

Sets of objects, compared by physical equality.

Sourcetype 'a t

A mutable set of elements of type 'a.

Sourceval create : unit -> 'a t

create () returns a new, empty set. It does not allocate any storage until the first element is added: empty sets are cheap.

Sourceval length : 'a t -> int

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

Sourceval is_empty : 'a t -> bool

is_empty t is length t = 0.

Sourceval mem : 'a t -> 'a -> bool

mem t x is true if x is an element of t.

Sourceval add : 'a t -> 'a -> unit

add t x adds x to t. Does nothing if x is already present.

Sourceval add_if_new : 'a t -> 'a -> bool

add_if_new t x adds x to t and returns true if x was already present (in which case t is unchanged). This is the "visited" test of a traversal, in a single lookup.

Sourceval remove : 'a t -> 'a -> unit

remove t x removes x from t. Does nothing if x is absent.

Sourceval clear : 'a t -> unit

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

Sourceval reset : 'a t -> unit

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

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

iter f t applies f to each element of t, in an unspecified order. f can look up t; if it modifies t, it is unspecified whether the added (or removed) elements are visited.

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

fold f t acc is f xN (... (f x1 acc)), where x1 ... xN are the elements of t, in an unspecified order. Same restrictions as iter.