DEFINITION MODULE DCHash; (*============================================================== Version : 2.0 16 Sep 1990 C. Lins Compiler : Generic pc Modula-2 Component: Hash Table - Sequential Bounded Managed Iterator Collision resolution using direct chaining REVISION HISTORY v1.00 22 Apr 1989 C. Lins: Initial Modula-2 implementation v1.01 12 Jun 1989 C. Lins: Removed notFound procedure parameter from Update. Changed semantics to automatically insert the new entry if not found in the table. v1.02 18 Jun 1989 C. Lins: Eliminated separation of key and data. v1.03 22 Jul 1989 C. Lins: Revised active hash table iterator. v1.04 21 Aug 1989 C. Lins: Added selector HashOf to return hashing function. v1.05 29 Aug 1989 C. Lins: Separate key and data. v2.00 16 Sep 1990 C. Lins Created generic pc version (C) Copyright 1990 Charles A. Lins ==============================================================*) FROM HashTypes IMPORT (*--type*) Exceptions, FoundProc, NotFoundProc, States, UpdateProc, LoopProc, AccessProc, HashFunction, Key, Data; FROM ErrorHandling IMPORT (*--type*) HandlerProc; FROM TypeManager IMPORT (*--type*) TypeID; (*-------------------------*) CONST ModuleID = 2; PROCEDURE TableError () : Exceptions (*--out *); PROCEDURE SetHandler ( theError : Exceptions (*--in *); theHandler : HandlerProc (*--in *)); PROCEDURE GetHandler ( theError : Exceptions (*--in *)) : HandlerProc (*--out *); TYPE HashTable; VAR NullTable : HashTable; PROCEDURE Create ( keyTypeID : TypeID (*--in *); dataTypeID : TypeID (*--in *); theSize : CARDINAL (*--in *); hashFunc : HashFunction (*--in *)) : HashTable (*--out *); PROCEDURE Destroy (VAR theTable : HashTable (*--inout*)); PROCEDURE Clear ( theTable : HashTable (*--inout*)); PROCEDURE Assign ( theTable : HashTable (*--in *); VAR toTable : HashTable (*--inout*)); PROCEDURE Insert ( theTable : HashTable (*--inout*); theKey : Key (*--in *); theData : Data (*--in *)); PROCEDURE Remove ( theTable : HashTable (*--inout*); theKey : Key (*--in *); notFound : NotFoundProc (*--in *)); PROCEDURE Update ( theTable : HashTable (*--inout*); theKey : Key (*--in *); theData : Data (*--in *); updateEntry: UpdateProc (*--in *)); PROCEDURE IsDefined ( theTable : HashTable (*--in *)) : BOOLEAN (*--out *); PROCEDURE IsEmpty ( theTable : HashTable (*--in *)) : BOOLEAN (*--out *); PROCEDURE KeyTypeOf ( theTable : HashTable (*--in *)) : TypeID (*--out *); PROCEDURE DataTypeOf( theTable : HashTable (*--in *)) : TypeID (*--out *); PROCEDURE HashOf ( theTable : HashTable (*--in *)) : HashFunction (*--out *); PROCEDURE SizeOf ( theTable : HashTable (*--in *)) : CARDINAL (*--out *); PROCEDURE ExtentOf ( theTable : HashTable (*--in *)) : CARDINAL (*--out *); PROCEDURE IsPresent ( theTable : HashTable (*--in *); theKey : Key (*--in *); found : FoundProc (*--in *); notFound : NotFoundProc (*--in *)); PROCEDURE LoopOver ( theTable : HashTable (*--in *); process : LoopProc (*--in *)); PROCEDURE Traverse ( theTable : HashTable (*--in *); process : AccessProc (*--in *)); TYPE HashTableEntry; TYPE IterateProc = PROCEDURE (CARDINAL, States, HashTableEntry); PROCEDURE Iterate ( theTable : HashTable (*--in *); process : IterateProc (*--in *)); PROCEDURE IsNull ( theEntry : HashTableEntry(*--in *)) : BOOLEAN (*--out *); PROCEDURE KeyOf ( theEntry : HashTableEntry(*--in *)) : Key (*--out *); PROCEDURE DataOf ( theEntry : HashTableEntry(*--in *)) : Data (*--out *); PROCEDURE NextOf ( theEntry : HashTableEntry(*--in *)) : HashTableEntry(*--out *); END DCHash.