(*
    Title: 	HashStrings - Definitions
    LastEdit:	"Thu May 24 17:31:47 1984"
    Author: 	Mick Jordan
		Cambridge University Computer Laboratory

    package for hash tables of character strings
*)

DEFINITION MODULE HashStrings;
FROM SYSTEM IMPORT WORD;
FROM SYSTEMTYPES IMPORT STRING;

EXPORT QUALIFIED HASHTABLE, HASHID, 
    Enter, EnterChars, Lookup, LookupChars, 
    Assoc, Retrieve, New, Dispose, StringAt;

TYPE HASHTABLE;
(* a unique identifier identifying a particular hash table *)
TYPE HASHID;
(*  a unique identifier associated with an entry in the hash table *)

PROCEDURE New(VAR ht: HASHTABLE; size: CARDINAL);
(*  Creates a new hashtable identified by 'ht'. 
    It has 'size' entries.
*)
PROCEDURE Dispose(ht: HASHTABLE);
(*  Disposes hashtable 'ht'.
*)
PROCEDURE Enter(ht: HASHTABLE; s: STRING; VAR h: HASHID): BOOLEAN;
(*  Enter 's' into the hash table 'ht'.
    If already entered, return FALSE and set 'h' to HASHID;
*)

PROCEDURE EnterChars(ht: HASHTABLE; VAR chars: ARRAY OF CHAR; 
                        VAR h: HASHID): BOOLEAN;
(*  Enter 'chars' into the hash table 'ht'.
    If already entered, return FALSE and set 'h' to HASHID;
*)

PROCEDURE LookupChars(ht: HASHTABLE; chars: ARRAY OF CHAR; 
                      VAR h: HASHID): BOOLEAN;
(*  Searches for 'chars' in the hashtable, returning TRUE
    if found, and setting 'h' to the associated HASHID.
    Otherwise return FALSE and 'h' undefined.
*)
PROCEDURE Lookup(ht: HASHTABLE; s: STRING; VAR h: HASHID): BOOLEAN;
(*  Searches for 's' in the hashtable, returning TRUE
    if found, and setting 'h' to the associated HASHID.
    Otherwise return FALSE and 'h' undefined.
*)

PROCEDURE Assoc(ht: HASHTABLE; h: HASHID; w: WORD);
(*  Associate the value 'w' with the hashtable entry 'h'.
*)

PROCEDURE Retrieve(ht: HASHTABLE; h: HASHID; VAR w: WORD);
(*  Retrieve the stored value associated with 'h'.
*)
PROCEDURE StringAt(ht: HASHTABLE; h: HASHID; VAR s: STRING);
(*  Return the string associated with hashid 'h'.
*)

END HashStrings.
