(*********************************************************************)
(* Title:	HashStrings - Definitions			     *)
(* Author: 	Mick Jordan,107,x304				     *)
(* 		Copyright (C) 1985 by Acorn Research Centre	     *)
(*********************************************************************)

(*
  $Revision: 1.2 $
  $Author: mjj $
  $Date: 85/04/10 11:55:39 $
  $Source: /util/m2/lib/Standard/RCS/HashStrings.def,v $
  $State: Exp $
*)

(*
    A package for hash tables of character strings,
    in standard language form.
*)

DEFINITION MODULE HashStrings;
FROM SYSTEM IMPORT WORD;
FROM Strings IMPORT String, CaseMode;

EXPORT QUALIFIED HashTable, HashId, 
    NewC, New, Dispose, EnterChars, EnterString, LookupChars, LookupString, 
    Assoc, Retrieve, StringAt, CharsAt;

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

PROCEDURE NewC(size: CARDINAL; caseMode: CaseMode): HashTable;
(*  Creates a new hashtable identified by the returned value,
    with the case-sensitivity of the hashing function
    specified by 'caseMode' (IgnoreCase, ConsiderCase).
    The number of entries in the table is unlimited, 
    but the efficiency will drop off once the number nears 'size'.
*)
PROCEDURE New(size: CARDINAL): HashTable;
(*   Equal to NewC(size, ConsiderCase) for backwards compatibility.
*)
PROCEDURE Dispose(ht: HashTable);
(*  Disposes hashtable 'ht'.
*)
PROCEDURE EnterString(ht: HashTable; s: String; VAR h: HashId): BOOLEAN;
(*  Enter a copy of 's' into the hash table 'ht'. 
    If already entered, return FALSE and set 'h' to HashId;
*)
PROCEDURE EnterChars(ht: HashTable; 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 LookupString(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 LookupChars(ht: HashTable; chars: ARRAY OF CHAR;
                      VAR h: HashId): BOOLEAN;
(*  ditto for character array string.
*)
PROCEDURE Assoc(ht: HashTable; h: HashId; w: WORD);
(*  Associate the value 'w' with the hashtable entry 'h'.
*)
PROCEDURE Retrieve(ht: HashTable; h: HashId): WORD;
(*  Retrieve the stored value associated with 'h'.
*)
PROCEDURE StringAt(ht: HashTable; h: HashId): String;
(*  Return the string associated with hashid 'h'.
*)
PROCEDURE CharsAt(ht: HashTable; h: HashId; VAR chars: ARRAY OF CHAR);

END HashStrings.

(*
$Log:	HashStrings.def,v $
Revision 1.2  85/04/10  11:55:39  mjj
Add case-insensitive hashing.

*)

