Download Cyclone User`s Manual

Transcript
typedef struct Table<‘a, ‘b> @table_t<‘a,‘b>;
A table_t<‘a,‘b> is a hash table with keys of type ‘a and values
of type ‘b.
table_t<‘a, ‘b> create(int sz, int(@‘H cmp)(‘a, ‘a), int(@‘H hash)(‘a)
create(sz,cmp,hash) returns a new hash table that starts out with
sz buckets. cmp should be a comparison function on keys: cmp(k1,k2)
should return a number less than, equal to, or greater than 0 according
to whether k1 is less than, equal to, or greater than k2. hash should
be a hash function on keys. cmp and hash should satisfy the following
property: if cmp(k1,k2) is 0, then hash(k1) must equal hash(k2).
void insert(table_t<‘a, ‘b> t, ‘a key, ‘b val);
insert(t,key,val) binds key to value in t.
‘b lookup(table_t<‘a, ‘b> t, ‘a key);
lookup(t,key) returns the value associated with key in t, or throws
Not_found if there is no value associate with key in t.
void resize(table_t<‘a, ‘b> t);
resize(t) increases the size (number of buckets) in table t. resize
is called automatically by functions like insert when the buckets of a
hash table get large, however, it can also be called by the programmer
explicitly.
void remove(table_t<‘a, ‘b> t, ‘a key);
remove(t,key) removes the most recent binding of key from t; the
next-most-recent binding of key (if any) is restored. If there is no value
associated with key in t, remove returns silently.
int hash_string(string_t s);
hash_string(s) returns a hash of a string s. It is provided as a convenience for making hash tables mapping strings to values.
int hash_stringptr(stringptr_t p);
hash_stringptr(p) returns a hash of a string pointer p.
140