The interface provides a subset of the OCaml Stdlib.Hashtbl module with some changes:
The functorial interface of the Stdlib.Hashtbl is not provided. Instead the constructor functions, create, of_seq, and rebuild, take an optional HashedType module as an argument. By default create returns a randomized hash table.
The add_seq and replace_seq operations are not provided at all.
Non-instance specific operations related to randomization (e.g. randomize, is_randomized) are not provided.
Non-instance specific operations related to hashing (e.g. hash, seeded_hash, hash_param, seeded_hash_param) are not provided.
Please note that the design is intentionally based on Stdlib.Hashtbl and copies its semantics as accurately as possible. Some of the operations come with warnings.
The hash table implementation is designed to avoid starvation. Read-only accesses can generally proceed in parallel without interference. Write accesses that do not change the number of bindings can proceed in parallel as long as they hit different internal buckets. Write accesses that change the number of bindings use a scalable Accumulator and only make infrequent random checks to determine whether the hash table should be resized.
The default hash is computed as Stdlib.Hashtbl.hash (Random.bits ()).
The default equal is (=).
The default min_buckets is unspecified and a given min_buckets may be adjusted by the implementation.
The default max_buckets is the minimum of 1 lsl 30 and suitably adjusted Sys.max_array_length and a given max_buckets may be adjusted by the implementation.
The n_way argument is passed to the internal Accumulator used to keep track of the number of bindings.
n_way_of t returns the maximum number of non-interfering parallel updates allowed by the internal Accumulator used to keep track of the number of bindings in the hash table t.
of_seq assoc creates a new hash table from the given association sequence assoc. The associations are added in the same order as they appear in the sequence, using replace, which means that if two pairs have the same key, only the latest one will appear in the table. See create for the optional arguments.
⚠️ of_seq (to_seq t) does not necessarily copy the bindings of a hash table correctly.
to_seq t takes a snapshot of the keys and values in the hash table and returns them as an association sequence. Bindings of each individual key appear in the sequence in reverse order of their introduction.
⚠️ of_seq (to_seq t) does not necessarily copy the bindings of a hash table correctly.
rebuild t returns a copy of the given hash table t optionally rehashing all of the bindings.
See create for descriptions of the optional arguments. Unlike create, rebuild uses the given hash table t as a template to get defaults for the optional arguments.
copy t is equivalent to rebuild t. In other words, the returned hash table uses the same hashed_type (and other parameters) as the given hash table t.
Sourceval iter : ('a->'b-> unit)->('a, 'b)t-> unit
iter f t is equivalent to Seq.iter (fun (k, v) -> f k v) (to_seq t).
Sourceval filter_map_inplace : ('k->'v->'v option)->('k, 'v)t-> unit
filter_map_inplace f t applies f to all bindings in the hash table t and updates each binding depending on the result of f. If f returns None, the binding is discarded. If f returns Some new_value, the binding is updated to associate the key to the new_value.
⚠️ The given f may be called multiple times for the same bindings from multiple domains in parallel.