-- SymTab - definitions for symbol table abstraction
-- last change: Russ Atkinson -  9-Jun-81 18:01:39
-- last change: Nori Suzuki - 11-Oct-81 20:36:56
-- filed on: [Indigo]<Sakura>Parser>SymTab.mesa

DIRECTORY
  Rope USING [Ref];

SymTab: DEFINITIONS = BEGIN

  Ref: TYPE = REF SymTabRep;
  Key: TYPE = Rope.Ref;
  Val: TYPE = REF;
  EachPairAction: TYPE = PROC [key: Key, val: Val] RETURNS [quit: BOOLEAN];
  SymTabRep: TYPE;

  Create: PROC [mod: CARDINAL ← 17, case: BOOLEAN ← TRUE] RETURNS [Ref];
    -- creates new table with suggested hash size
    -- if case is TRUE, keys are compared exactly
    -- if case is FALSE, case is ignored in comparing keys

  GetSize: PROC [x: Ref] RETURNS [CARDINAL];
    -- returns number of key-value pairs in table

  Fetch: PROC [x: Ref, key: Key] RETURNS [found: BOOLEAN, storedKey: Key, val: Val];
    -- looks up key in table, returns associated value (if any)
    -- if found is TRUE, key is the stored key and val is value associated with given key
    -- if found is FALSE, val is NIL

  Store: PROC [x: Ref, key: Key, val: Val] RETURNS [BOOLEAN];
    -- stores new key-value pair, overwriting previous value for given key
    -- returns TRUE if new value, FALSE if previous value overwritten

  Insert: PROC [x: Ref, key: Key, val: Val] RETURNS [BOOLEAN];
    -- inserts new key-value pair, except if previous value for given key
    -- returns TRUE if inserted, FALSE if previous value for key

  Delete: PROC [x: Ref, key: Key] RETURNS [BOOLEAN];
    -- deletes key-value pair associated with given key
    -- returns TRUE if deletion actually occurred, FALSE if no such key

  Pairs: PROC [x: Ref, action: EachPairAction] RETURNS [BOOLEAN];
    -- enumerates pairs currently in symbol 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

  END.