GraphsImpl.Mesa
Last Edited by: Spreitzer, June 6, 1985 4:35:40 pm PDT
DIRECTORY Graphs, Rope;
GraphsImpl:
CEDAR
PROGRAM
IMPORTS Rope
EXPORTS Graphs =
BEGIN OPEN Graphs;
NewVertexType:
PUBLIC
PROC [vtr: VertexTypeRep]
RETURNS [vt: VertexType] = {
vt ← NEW [VertexTypeRep ← vtr];
IF vt.GetLabel = NIL THEN vt.GetLabel ← GetNoLabel;
IF vt.LabelEdges = NIL THEN vt.LabelEdges ← LabelEdgesFromExpand;
IF vt.CrossLabeledEdge = NIL THEN vt.CrossLabeledEdge ← CrossLabeledEdgeFromExpand;
IF vt.GetIndexedNeighbor = NIL THEN vt.GetIndexedNeighbor ← GetIndexedNeighborFromExpand;
IF vt.GetNeighborCount = NIL THEN vt.GetNeighborCount ← GetNeighborCountFromLabels;
};
GetNoLabel: PROC [vertex: Vertex] RETURNS [label: Label] = {label ← unlabeled};
LabelEdgesFromExpand:
PROC [vertex: Vertex, consume: LabelConsumer] = {
PerEdge:
PROC [edge: Edge, data:
REF
ANY] =
{consume.proc[edge.label, consume.data]};
TRUSTED {vertex.type.Expand[vertex, [PerEdge]]}};
Abort: ERROR = CODE;
CrossLabeledEdgeFromExpand:
PROC [vertex: Vertex, edgeLabel: Label]
RETURNS [neighbor: Vertex] = {
PerEdge:
PROC [edge: Edge, data:
REF
ANY] = {
IF edge.label.Equal[edgeLabel] THEN {neighbor ← edge.otherSide; Abort};
};
neighbor ← NIL;
TRUSTED {vertex.type.Expand[vertex, [PerEdge] !Abort => CONTINUE]};
};
GetIndexedNeighborFromExpand:
PROC [vertex: Vertex, index:
INT
--origin 1--]
RETURNS [neighbor: Vertex] = {
i: INT ← 0;
PerEdge:
PROC [edge: Edge, data:
REF
ANY] = {
i ← i + 1;
IF index = i THEN {neighbor ← edge.otherSide; Abort};
};
neighbor ← NIL;
TRUSTED {vertex.type.Expand[vertex, [PerEdge] !Abort => CONTINUE]};
};
GetNeighborCountFromLabels:
PROC [vertex: Vertex]
RETURNS [neighborCount:
INT] = {
PerLabel:
PROC [edgeLabel: Label, data:
REF
ANY] = {
neighborCount ← neighborCount + 1;
};
neighborCount ← 0;
TRUSTED {vertex.type.LabelEdges[vertex, [PerLabel] !Abort => CONTINUE]};
};
Setup[];
END.