Low-level functions

type'a t

The type of arrays of weak pointers (weak arrays). A weak
pointer is a value that the garbage collector may erase at
any time.
A weak pointer is said to be full if it points to a value,
empty if the value was erased by the GC.
Note that weak arrays cannot be marshaled using
output_value or the functions of the Marshal
module.

Weak.set ar n (Some el) sets the nth cell of ar to be a
(full) pointer to el; Weak.set ar n None sets the nth
cell of ar to empty.
Raise Invalid_argument"Weak.set" if n is not in the range
0 to Weak.length a - 1.

Weak.get_copy ar n returns None if the nth cell of ar is
empty, Some x (where x is a (shallow) copy of the value) if
it is full.
In addition to pitfalls with mutable values, the interesting
difference with get is that get_copy does not prevent
the incremental GC from erasing the value in its current cycle
(get may delay the erasure to the next GC cycle).
Raise Invalid_argument"Weak.get" if n is not in the range
0 to Weak.length a - 1.

Weak.blit ar1 off1 ar2 off2 len copies len weak pointers
from ar1 (starting at off1) to ar2 (starting at off2).
It works correctly even if ar1 and ar2 are the same.
Raise Invalid_argument"Weak.blit" if off1 and len do
not designate a valid subarray of ar1, or if off2 and len
do not designate a valid subarray of ar2.

Weak hash tables

A weak hash table is a hashed set of values. Each value may
magically disappear from the set when it is not used by the
rest of the program any more. This is normally used to share
data structures without inducing memory leaks.
Weak hash tables are defined on values from a Hashtbl.HashedType
module; the equal relation and hash function are taken from that
module. We will say that v is an instance of x if equal x v
is true.

The equal relation must be able to work on a shallow copy of
the values and give the same result as with the values themselves.