DEFINITION MODULE ListHand;  (* LISTHAND.DEF *)

FROM Strings IMPORT CompareStr, Assign;
FROM Storage IMPORT ALLOCATE, DEALLOCATE;
FROM SYSTEM IMPORT TSIZE;
EXPORT QUALIFIED findentry, rementry, newentry, inc_count, do_order,
   (* TYPEs *)   childPt, Pt;

TYPE Pt=POINTER TO idList;
     idList=RECORD
            name:ARRAY [0..9] OF CHAR;
            count:INTEGER;
            leftchild:Pt;
            rightchild:Pt;
            END;
     childPt=(nul,left,right);

PROCEDURE findentry(ident:ARRAY OF CHAR; VAR pointer:Pt; VAR child:childPt;
 VAR found:BOOLEAN);
(* This searches for a node that matches ident, returning the pointer to the
    previous node in pointer, the child in child, with found TRUE if it is
    found.  If a matching node cannot be found, found is returned FALSE, and
    pointer points to the node to insert after (child indicating which child
    it should be).                                                      *)

PROCEDURE rementry(pointer:Pt; child:childPt);
(* This removes the entry pointed to be pointer and child.              *)

PROCEDURE newentry(pointer:Pt; child:childPt; ident:ARRAY OF CHAR);
(* This creates a newentry at pointer, child with ident as supplied.    *)

PROCEDURE inc_count(pointer:Pt; child:childPt):CARDINAL;
(* Incements the count filed in the entry at pointer, child.            *)

PROCEDURE do_order;
(* Calls the routine to display the whole tree in order.                *)

END ListHand.
