-- BinaryTree.mesa, (from TreeDefs by Peter A. Arndt)
--	definitions for a binary tree that just stores a string per node.
-- Alto/Mesa 6.1 version
-- Revised by Newman: 14-Mar-83 16:55:20

BinaryTree: DEFINITIONS =
BEGIN

-- type declarations:

Tree: TYPE = POINTER TO Object;
Object: TYPE;
Membership: TYPE = {first, second, both};
ReportProc: TYPE = PROC [id: STRING, membership: Membership];
UserProc: TYPE = PROC [id: STRING];

-- procedure declarations:

CompareTrees: PROC [first, second: Tree, report: ReportProc];
  --Call the ReportProc for each member of either tree, telling whether it's in one tree or both.

DestroyTree: PROC [tree: Tree, z: MDSZone];
  --Free all storage associated with this tree, using zone "z" which must be the same zone used to create the tree.

Enter: PROC [tree: Tree, s: STRING, z: MDSZone] RETURNS [newTree: Tree];
  --Enter "s" in the tree, producing "newTree".   This operation consumes "tree", which should no longer be referenced.  "s" is not consumed (it is copied into "z").  Allocation is done from zone "z" which must be the same zone that was used to put previous entries into "tree".
  --A tree is created by calling Enter [NIL, "some string", z].

EnumerateTree: PROC [tree: Tree, userProc: UserProc];
  --Call the UserProc for each member of the tree.

MergeTrees: PROC [first, second: Tree, z: MDSZone] RETURNS [newTree: Tree];
  --Create a new tree with all the members of "first" and "second".  This operation consumes "first" and "second", which should no longer be referenced.  Allocation is done from zone "z" which must be the same zone that was used to put previous entries into "first" and "second".
  
Present: PROC [tree: Tree, s: STRING] RETURNS [present: BOOLEAN];
  --Tell whether this string is in the tree.

END.

13-Apr-82 19:15:05 - Newman - Created from TreeDefs by Peter A. Arndt.
14-Mar-83 16:55:32 - Newman - Added UNCOUNTED ZONE parameters.
 5-May-83 16:56:11 - Newman - no LONGs, UNCOUNTED ZONE => MDSZone for Alto.