diff options
| author | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2026-04-26 16:38:00 -0400 |
|---|---|---|
| committer | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2026-04-26 16:38:00 -0400 |
| commit | 97d5c458cfa039d857301e1ca7d5af3beb37131d (patch) | |
| tree | b460cd850d0537eb71806ba30358840377b27688 /static/inferno/man2/hash.2 | |
| parent | b89dc2331a50c63f8b33272a5c4c61ab98abdaa3 (diff) | |
build: Better Build System
Diffstat (limited to 'static/inferno/man2/hash.2')
| -rw-r--r-- | static/inferno/man2/hash.2 | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/static/inferno/man2/hash.2 b/static/inferno/man2/hash.2 new file mode 100644 index 00000000..522069a0 --- /dev/null +++ b/static/inferno/man2/hash.2 @@ -0,0 +1,91 @@ +.TH HASH 2 +.SH NAME +hash, HashTable \- hash table +.SH SYNOPSIS +.EX +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; +.EE +.SH DESCRIPTION +The 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 New +creates and returns a new +.B HashTable +with +.I size +slots. The hashing works best if +.I size +is a prime number. The +.B HashVal +adt contains the data values of the hash. +The +.B HashNode +adt contains the key/value pair for each element in the table. +.TP +.IB ht .insert( "key, value" ) +Adds a new +.IR key / value +pair to the table. +If an element with the same +.I key +already exists, +it will acquire the new +.IR value . +.TP +.IB ht .find( key ) +Search the table for an element with the given +.I key +and return the value found; return nil if none was found. +.TP +.IB ht .delete( key ) +Removes any element with the given +.I key +from the table. +.TP +.IB ht .all() +Returns a list of all key/value pairs stored in the table. +.PP +.B Fun1 +and +.B fun2 +provide access to two different string hashing functions. +.B Fun1 +is the function used internally; +.B fun2 +is the same as that used in the Limbo compiler. +They each compute the hash value of +.I s +and return a value between 0 and +.IR n \-1. +.SH SOURCE +.B /appl/lib/hash.b +.SH BUGS +.B HashVal +should really be a +.BR pick . |
