| HASH(2) | System Calls Manual | HASH(2) |
hash, HashTable - hash table
include "hash.m";
hash := load Hash Hash->PATH;
new: fn(size:int):ref HashTable;
HashTable: adt{
insert: fn(h:self ref HashTable, key:string, val:HashVal);
find: fn(h:self ref HashTable, key:string):ref HashVal;
delete: fn(h:self ref HashTable, key:string);
all: fn(h:self ref HashTable): list of HashNode;
};
HashVal: adt{
i: int;
r: real;
s: string;
};
HashNode: adt{
key: string;
val: ref HashVal;
};
fun1, fun2: fn(s:string, n:int):int;
The hash module provides support for arrays that are indexed by keys of type string.
The values may be any combination of int, real, or string. New creates and returns a new HashTable with size slots. The hashing works best if size is a prime number. The HashVal adt contains the data values of the hash. The HashNode adt contains the key/value pair for each element in the table.
Fun1 and fun2 provide access to two different string hashing functions. Fun1 is the function used internally; fun2 is the same as that used in the Limbo compiler. They each compute the hash value of s and return a value between 0 and n-1.
/appl/lib/hash.b
HashVal should really be a pick.