IntToIntTab.mesa
Copyright Ó 1987, 1991 by Xerox Corporation. All rights reversed.
Christian Jacobi, May 13, 1987 10:43:20 am PDT
A IntToIntTab is a hash table which associates INT keys with INT values. IntToIntTab is like RefTab except for the Key and Val types.
IntToIntTab: CEDAR DEFINITIONS = BEGIN
Table: TYPE = REF IntToIntTabRep;
IntToIntTabRep: TYPE = MONITORED RECORD [impl: REF IntToIntTabImplRep];
IntToIntTabImplRep: TYPE;
Key: TYPE = INT;
Val: TYPE = INT;
Create: PROC [mod: NAT ¬ 17] RETURNS [Table];
creates new table with suggested initial hash size
GetSize: PROC [table: Table] RETURNS [INT];
returns number of key-value pairs in table
Fetch: PROC [table: Table, key: Key] RETURNS [found: BOOL, val: Val];
looks up key in table, returns associated value (if any)
if found is TRUE, val is value associated with given key
if found is FALSE, val is -1
Replace: PROC [table: Table, key: Key, val: Val] RETURNS [BOOL];
returns TRUE after overwriting old value for existing key-value pair
if no previous value for key, returns FALSE without inserting new pair
Store: PROC [table: Table, key: Key, val: Val] RETURNS [BOOL];
returns TRUE after inserting new pair
returns FALSE after overwriting old value for existing key-value pair
Insert: PROC [table: Table, key: Key, val: Val] RETURNS [BOOL];
returns TRUE after inserted new pair
if previous value existed for key, returns FALSE without changing value
Delete: PROC [table: Table, key: Key] RETURNS [BOOL];
deletes key-value pair associated with given key
returns TRUE if deletion actually occurred, FALSE if no such key
Erase: PROC [table: Table];
deletes all key-value pairs in given table
EachPairAction: TYPE = PROC [key: Key, val: Val] RETURNS [quit: BOOL ¬ FALSE];
Pairs: PROC [table: Table, action: EachPairAction] RETURNS [BOOL];
enumerates pairs currently in table in unspecified order
pairs inserted/deleted during enumeration may or may not be seen
applies action to each pair until action returns TRUE or no more pairs
returns TRUE if some action returns TRUE
UpdateOperation: TYPE = {none, store, delete};
UpdateAction: TYPE = PROC [found: BOOL, val: Val]
RETURNS [op: UpdateOperation ¬ none, new: Val ¬ -1];
Update: PROC [table: Table, key: Key, action: UpdateAction];
atomically performs an update action
looks up key and calls action, which returns the desired operation
If op=none, the table is not changed; if op=store, the new value is stored; if op=delete, key is removed from the table.
Copy: PROC [table: Table] RETURNS [Table];
atomically copies the table.
END.