IPSimpleTree:
CEDAR
DEFINITIONS =
BEGIN
--Intro: This is an extremely simple minded implementation of tree.
-- Nodes are records with (i) own name, (ii) areaEstimate, (iii) name of parent,
-- (iv) names of children.
-- The 'any' field is used to hold a number of things, look at the Impl.
Ref: TYPE = REF Rep;
Rep:
TYPE =
RECORD[
tab: SymTab.Ref,
initialized: BOOL ← FALSE,
root: Rope.ROPE ← NIL
];
Nodes: TYPE = LIST OF Node;
Node: TYPE = REF NodeRep;
NodeRep:
TYPE =
RECORD[
name: Rope.ROPE,
areaEstimate: INT ← 0,
any: REF ← NIL,
parent: Rope.ROPE ← NIL,
children: LIST OF Rope.ROPE ← NIL];
Create: PROC [] RETURNS [Ref];
--(A) Tree Constructors:
AddNode: PROC[st: Ref, ndName, parent: Rope.ROPE, children: LIST OF Rope.ROPE, areaEst: INT ← 0, any: REF ← NIL];
RemoveNode: PROC[st: Ref, ndName: Rope.ROPE] RETURNS [done: BOOL];
-- (B) Tree Queries:
GetRoot: PROC[st: Ref] RETURNS [Node];
GetLeaves: PROC[st: Ref] RETURNS [count: NAT, leaves: Nodes];
GetNode:
PROC[st: Ref, nodeName: Rope.
ROPE, raiseError:
BOOL ←
TRUE]
RETURNS [Node];
-- IF (nodeName is not a namraise e of node) AND raiseError
-- THEN raise ! IP.Error[missingRegistration, "<nodeName> is not a node"]
GetChildren: PROC[st: Ref, node: Node] RETURNS [Nodes];
GetParent: PROC[st: Ref, node: Node] RETURNS [Node];
END.