![]() |
![]() |
![]() |
|
Ptrhash provides mapping between two arbitrary types. However mapping source is treated as pointer, i.e. structural equality is not tested, and pointer of object is used as hashing input. | |
type <'a, 'b>t; | |
Type of hash tables from 'a to 'b. | |
<'a, 'b>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, 'b>t h, 'a k, 'b 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. | |
'b find(<'a, 'b>t h, 'a k); | |
Lookup element with key k in h. Raise Not_found if element is not in hash table. Otherwise return it. | |
void remove(<'a, 'b>t h, 'a k); | |
Remove one element with key k from h. Raise Not_found if element is not in hash table. | |
void remove_all(<'a, 'b>t h, 'a k); | |
Remove all elements with key k from h. If no such elements are found, do nothing. | |
<'b>list find_all(<'a, 'b>t h, 'a k); | |
Return list of all elements with key k from h. If no such elements are found return Nil. | |
bool mem(<'a, 'b>t h, 'a k); | |
Return true iff element with key k is in h. | |
int length(<'a, 'b>t h); | |
Return number of elements stored in h. | |
<'a, 'b>t copy(<'a, 'b>t h); | |
Return copy of h. Time of this operation is O(length(h)). | |
void replace(<'a, 'b>t, 'a, 'b); | |
Same as remove_all(h, k); add(h, k, v);. | |
<'a>list keys(<'a, 'b>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. | |
<'b>list values(<'a, 'b>t h); | |
Return list of values of elements stored in h. See Ptrhash::keys() for ordering notes. | |
void iter(<'a, 'b>t h, *(void ('a, 'b)) 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. Warning: this traverses hash in *random* order, i.e. the order depends on random things, like where malloc() is going to give you memory. This might come out important, when for example doing bootstrap comparisons in compiler. | |
<'a, 'b>t of_assoc_list(<*('a, 'b)>list assoc); | |
Create new hash table and add each (key, value) pair from assoc. Return created hashtable. |