![]() | ![]() | ![]() |
|
This module provides mutable hash tables from string to any type.
type <'a>t; | |
Type of hash tables holding values of type 'a. |
<'a>t create(int size_hint); | |
Create new hash, empty table. size_hint is order of initial size of hash table. Hash table will grow as necessary. |
void add(<'a>t h, string k, 'a v); | |
Add element v with key k to h. If there is already element with the same key, this new element shadows it, subsequent calls to find(h, k) will return v. However after remove(h, k), find(h, k) will return shadowed element. |
'a find(<'a>t h, string k); | |
Look element with key k in h. Raise Not_found if element is not in hash table. Otherwise return it. |
void remove(<'a>t h, string k); | |
Remove one element with key k from h. Raise Not_found if element is not in hash table. |
void remove_all(<'a>t h, string k); | |
Remove all elements with key k from h. If no such elements are found, do nothing. |
<'a>list find_all(<'a>t h, string k); | |
Return list of all elements with key k from h. If no such elements are found return Nil. |
bool mem(<'a>t h, string k); | |
Return true iff element with key k is in h. |
int length(<'a>t h); | |
Return number of elements stored in h. |
void iter(<'a>t h, *(void (string, 'a)) f); | |
Execute f on each element of h, passing it its key and value. It is undefined what elements will be visited if h is modified (elements are inserted or removed) during iteration. |
<'a>t copy(<'a>t h); | |
Return copy of h. Time of this operation is O(length(h)). |
void replace(<'a>t h, string k, 'a v); | |
Same as remove_all(h, k); add(h, k, v);. |
<string>list keys(<'a>t h); | |
Return list of keys of elements stored in h. Keys are returned in arbitrary order, however keys(h) and value(h) will maintain the same order if there are no insertions nor deletions on h between them. |
<'a>list values(<'a>t); | |
Return list of values of elements stored in h. See Hashtbl::keys() for ordering notes. |
<'a>t of_assoc_list(<*(string, 'a)>list assoc); | |
Create new hash table and add each (key, value) pair from assoc. Return created hashtable. |
int prime_around(int x); | |
Return prime number p, such that p >= x and p is in about the same binary order of magnitude as x. Additionally p >= 13. It is undefined for x > 2^30. |