forsyth20121205-174063a80cc13 years agoHistory
91 lines · 1.7 KB · Text
RawDownload
.TH HASH 2.SH NAMEhash, HashTable \- hash table.SH SYNOPSIS.EXinclude "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;.EE.SH DESCRIPTIONThe hash module provides support for arrays that are indexed by keys of type.BR string . The values may be any combination of.BR int ,.BR real ,or.BR string ..B Newcreates and returns a new.B HashTablewith.I sizeslots. The hashing works best if.I sizeis a prime number. The.B HashValadt contains the data values of the hash.The.B HashNodeadt contains the key/value pair for each element in the table..TP.IB ht .insert( "key, value" )Adds a new.IR key / valuepair to the table.If an element with the same.I keyalready exists,it will acquire the new.IR value ..TP.IB ht .find( key )Search the table for an element with the given.I keyand return the value found; return nil if none was found..TP.IB ht .delete( key )Removes any element with the given.I keyfrom the table..TP.IB ht .all()Returns a list of all key/value pairs stored in the table..PP.B Fun1and.B fun2provide access to two different string hashing functions..B Fun1is the function used internally;.B fun2is the same as that used in the Limbo compiler.They each compute the hash value of .I sand return a value between 0 and.IR n \-1..SH SOURCE.B /appl/lib/hash.b.SH BUGS.B HashValshould really be a.BR pick .