DIRECTORY Collections, LichenDataStructure, RefTab;

LichenArrayStuff: CEDAR DEFINITIONS
=

{OPEN LichenDataStructure, Colls:Collections;

MakeArrayNewConnection: PROC [act: CellType, rangeA: Range2, delta: KingMove, epA, epB: Port, may: BOOL] RETURNS [connected: BOOL];
EnumerateConnectedEltPorts: PROC [a: Array, ep: Port, Consume: PROC [Port]];
ArrayEltPortsConnected: PROC [a: Array, ai1, ai2: ArrayIndex, ep1, ep2: Port] RETURNS [BOOL];
GetArrayPortForPort: PROC [act: CellType, a: Array, index: ArrayIndex, ep: Port, mayAdd: BOOL] RETURNS [arrayPort: Port];
CreateArrayRep: PROC [eltType: CellType, size, jointsPeriod: Size2, borders: ARRAY Dim OF ARRAY End OF NAT] RETURNS [a: Array];
NoteNewEltPort: PROC [a: Array, ep: Port];

CanonizeShift: PROC [pat: ArrayWirePattern, shift: Int2] RETURNS [Int2];
EnumCharacteristic: PROC [a: Array, range: Range2, Consume: PROC [part: ArrayPart, gi2: Nat2, gi: NATURAL, air: Range2]];
EnumCharacteristicDeltoid: PROC [a: Array, gi2A: Nat2, delta: KingMove, PerGi: PROC [aiA, aiB: ArrayIndex, partB: ArrayPart, gi2B: Nat2, giB: NATURAL]];
GI2ToCharacteristic: PROC [a: Array, gi2: Nat2] RETURNS [ArrayIndex];
IndicesForPart: PROC [a: Array, part: ArrayPart] RETURNS [Range2];
GisForPart: PROC [a: Array, part: ArrayPart] RETURNS [gi2Min, ngi2: Nat2, ngi: NATURAL];

<<MakeArrayConnection: PROC [ct: CellType, d: Dim, lowRange: Range2, rp1, rp2: SidedPort, may: BOOL] RETURNS [connected: BOOL];
GIPair: TYPE = ARRAY End OF NATURAL;

PackArrayIndex: PROC [ArrayIndex] RETURNS [PackedArrayIndex];
UnpackArrayIndex: PROC [PackedArrayIndex] RETURNS [ArrayIndex];

Central: PROC [a: Array, ai: ArrayIndex] RETURNS [BOOL];

HasMiddle: PROC [gp: GroupingParms] RETURNS [has: BOOL]
= INLINE {has _ gp.middle.maxPlusOne > gp.middle.min};
ComputeGroupingsIndex: PROC [a: Array, ai: ArrayIndex] RETURNS [gi2, gii2: Nat2, gi, cgii: NATURAL];
GPMiddle: PROC [gp: GroupingParmses] RETURNS [r2: Range2]
= INLINE {r2 _ [gp[Foo].middle, gp[Bar].middle]};
Gi2ToAir: PROC [a: Array, gi2: Nat2] RETURNS [air: Range2, ngii2: Nat2, ngii: NATURAL];
GiToGi2: PROC [a: Array, gi: NATURAL] RETURNS [gi2: Nat2]
= INLINE {
gi2[Foo] _ gi / a.groupingParmses[Bar].sum;
gi2[Bar] _ gi - gi2[Foo] * a.groupingParmses[Bar].sum};
ComputeJointGroupingsIndex: PROC [a: Array, j: Joint, jii: Nat2] RETURNS [jgi2: Nat2, jgi, ctii: NATURAL, jiir: Range2];
ArrayJointIndex: PROC [a: Array, phase: Nat2] RETURNS [i: INT]
= INLINE {i _ a.jointsPeriod[Bar]*phase[Foo] + phase[Bar]};

Jgi2ToLair: PROC [a: Array, phase: Nat2, j: Joint, jgi2: Nat2] RETURNS [lair, jiir: Range2, jCount: NATURAL];
Jgi2ToGi: PROC [a: Array, d: Dim, phase: Nat2, j: Joint, jgi2: Nat2, side: End] RETURNS [gi2: Nat2, gi: NATURAL];
Jgi2ToGip: PROC [a: Array, d: Dim, phase: Nat2, j: Joint, jgi2: Nat2] RETURNS [gip: GIPair];
AgiToAi: PROC [a: Array, gi2, gii2: Nat2] RETURNS [ai: ArrayIndex];
EnumJgiOfGi: PROC [a: Array, gi2: Nat2, Consume: PROC [d: Dim, j: Joint, side: End, jgi2, phase: Nat2]];

GetArrayJoint: PROC [a: Array, d: Dim, phase: Nat2] RETURNS [j: Joint]
= INLINE {j _ NARROW[a.joints[d][ArrayJointIndex[a, phase]]]};
FetchTies: PROC [j: Joint, jgi: NATURAL] RETURNS [ties: VarSet--of Tie--]
~ INLINE {RETURN [Colls.DeRef[j.ties[jgi]].AsVar]};
FetchTie: PROC [j: Joint, side: End, jgi: NATURAL, g: Group] RETURNS [tie: Tie]
= INLINE {rt: RefTable = NARROW[j.toTie[side][jgi]]; tie _ NARROW[rt.Fetch[g].val]};
BestGroup: PROC [g: Group] RETURNS [bg: Group]
= INLINE {IF g = NIL THEN bg _ g ELSE FOR bg _ g, bg.better WHILE bg.better # NIL DO NULL ENDLOOP};
BestTie: PROC [x: Tie] RETURNS [bx: Tie]
= INLINE {FOR bx _ x, bx.better WHILE bx.better # NIL DO NULL ENDLOOP};

GetArrayPortForGroup: PROC [act: CellType, a: Array, index: ArrayIndex, g: Group, mayAdd: BOOL] RETURNS [arrayPort: Port];
EnumerateGroupsContainingPort: PROC [a: Array, ep: Port, Consume: PROC [gi2: Nat2, gi: NATURAL, g: Group]];
EnumerateArrayWiresContainingGroup: PROC [a: Array, gi2: Nat2, gi: NATURAL, g: Group, Consume: PROC [ArrayWire], addIfMissing: BOOL];
EnumerateGroupsOfArrayWire: PROC [a: Array, aw: ArrayWire, Consume: PROC [gi2: Nat2, gi: NATURAL, g: Group, membership: BoolSeq--group instance index _ isMember--]];
PortToGroup: PROC [a: Array, gi: NATURAL, ep: Port] RETURNS [g: Group] = INLINE {
gs: Groupings = NARROW[a.groupingses[gi]];
g _ NARROW[gs.toGroup.Fetch[ep].val];
};

EnumerateJoints: PROC [a: Array, Consume: PROC [d: Dim, phase: Nat2, j: Joint]];
EnumerateTies: PROC [a: Array, Consume: PROC [d: Dim, phase: Nat2, jgi: NATURAL, jgi2: Nat2, j: Joint, tie: Tie]];
EnumerateTiesOfGroup: PROC [a: Array, gi2: Nat2, g: Group, Consume: PROC [d: Dim, phase: Nat2, jgi: NATURAL, jgi2: Nat2, j: Joint, tie: Tie, side: End]];
GroupInWireAt: PROC [a: Array, gi2: Nat2, g: Group, aw: ArrayWire, ai: ArrayIndex] RETURNS [BOOL];
ArrayEltPortsConnectedByJoint: PROC [a: Array, d: Dim, lowIndex: ArrayIndex, rp1, rp2: SidedPort] RETURNS [hypothetically, really: BOOL];
GroupsHypotheticallyConnected: PROC [a: Array, j: Joint, jgi: NATURAL, gs: ARRAY End OF Group] RETURNS [BOOL];
GroupsActuallyConnected: PROC [a: Array, j: Joint, jgi: NATURAL, lai: Nat2, gs: ARRAY End OF Group] RETURNS [BOOL];

FetchRPD: PROC [a: Array, d: Dim, rp: SidedPort] RETURNS [rpd: SidedPortData]
= INLINE {rpd _ NARROW[a.toRole[d][rp.side].Fetch[rp.port].val]};
GetRoot: PROC [a: Array, d: Dim, rp: SidedPortData, clai: NATURAL] RETURNS [root: NATURAL];
GetNext: PROC [rp: SidedPortData, clai: NATURAL] RETURNS [next: NATURAL];
RPDNeedsLinks: PROC [a: Array, d: Dim, rpd: SidedPortData] RETURNS [needs: BOOL];
IsIncompleteArray: PROC [ct: CellType] RETURNS [BOOL];

MakeGroupsForPort: PROC [a: Array, ep: Port];
GetGroup: PROC [a: Array, gi: NATURAL, ep: Port, mayAdd: BOOL] RETURNS [g: Group];
MakeGroup: PROC [a: Array, gi2: Nat2, gs: Groupings] RETURNS [g: Group];
AddPortToGroup: PROC [a: Array, gi: NATURAL, ep: Port, g: Group, links: BOOL];
RemovePortFromGroup: PROC [a: Array, gi: NATURAL, ep: Port, g: Group];
UnrolePort: PROC [a: Array, ep: Port];
AddTie: PROC [j: Joint, jgi: NATURAL, tie: Tie];
FlushArrayWires: PROC [a: Array, doomedArrayPorts: VarSet--of port of a--];
TrimEmptyGroups: PROC [a: Array];
ArrayWireForGroup: PROC [a: Array, index: ArrayIndex, gi: NATURAL, g: Group, mayAdd: BOOL] RETURNS [aw: ArrayWire];
SetArrayPortForGroup: PROC [a: Array, index: ArrayIndex, gi: NATURAL, g: Group, ap: Port];
SetArrayPortForPort: PROC [a: Array, index: ArrayIndex, ep, ap: Port];
EnsurePortForGroups: PROC [act: CellType, gis, giis: ARRAY End OF Nat2, gss: GroupListPair] RETURNS [ap: Port];
CrossATie: PROC [ct: CellType, d: Dim, fromP: Port, fromS: End] RETURNS [toP: Port];
ComputeTieCompleteAt: PROC [a: Array, d: Dim, tie: Tie, clai: NATURAL] RETURNS [complete: BOOL];
RetractFalseHypotheses: PROC [act: CellType];
TrimArray: PROC [a: Array];

DeleteGroup: PROC [a: Array, g: Group];
DeleteTie: PROC [j: Joint, jgi: NATURAL, tie: Tie];>>

FmtIndex: PROC [a: Array, index: ArrayIndex] RETURNS [asRope: ROPE];
Subscript: PROC [ROPE, INT] RETURNS [ROPE];
Subscript2: PROC [ROPE, ArrayIndex] RETURNS [ROPE];

}.
���B��LichenArrayStuff.mesa
Last tweaked by Mike Spreitzer on September 28, 1987 4:57:05 pm PDT
<low side's groupings index, high side's gi> f joint groupings index
Can not be called on incomplete arrays.
Can not be called on incomplete arrays.
Remove SidedPortData.links where possible.
Remove Ties with one empty side.
�Ê²��–
"cedar" style˜�code™K™C—K˜�KšÏk	œ*˜3K˜�šÏnœœ˜#Kšœ˜—K˜�Kšœœžœ
˜-K˜�Kš
žœœGœœ
œ˜ƒKšžœœžœœ	˜LKšžœœ2œœ˜]Kšžœœ@œœ˜yKšžœœ9œœœœœœ˜Kšžœœ˜*K˜�Kšž
œœ&œ˜HKš
žœœžœœ"œ˜yKš
žœœ)žœœ;œ˜˜Kšžœœœ˜EKšžœœœ
˜BKšž
œœœœ˜XK˜�KšœžœœDœœ
œ˜Kš	œœœœœ˜$K˜�Kšžœœœ˜=Kšžœœœ˜?K˜�Kšžœœœœ˜8K˜�šž	œœœœ˜7Kšœœ.˜6—Kšžœœœœ˜dšžœœœ
˜9Kšœœ)˜1—Kšžœœœ"œ˜Wšžœœœœ˜9šœœ˜
Kšœ+˜+Kšœ7˜7——šžœœ!œœ˜xKšœ-Ïmœ™D—šžœœœœ˜>Kšœœ3˜;—K˜�Kšž
œœ/œœ˜mKšžœœBœœ˜qKšž	œœ7œ˜\Kšžœœœ˜CKšžœœžœœ3˜hK˜�šž
œœ!œ˜FKšœœœ*˜>—š
ž	œœœœÏc
œ˜IKšœœœ#˜3—šžœœœœ˜OKšœœœœ˜T—šž	œœœ˜.Kšœœœœœœœœ
œœœœ˜c—šžœœ
œ
˜(Kšœœœœ
œœœœ˜G—K˜�Kšžœœ@œœ˜zKš
žœœžœœœ
˜kKšž"œœœžœœœ˜…Kšžœœžœœœ Ðcm œ˜¥š
žœœœœœ˜QKšœœ˜*Kšœœ˜%K˜—K˜�Kšžœœžœœ"˜PKš
ž
œœžœœœ#˜rKš
žœœ!žœœœ.˜™Kšž
œœ@œœ˜bKšžœœ?œœ˜‰Kšžœœœœœœœ˜nKšžœœœœœœœ˜sK˜�šžœœ#œ˜MKšœœœ+˜A—Kš
žœœ-œœœ˜[Kš
žœœœœœ˜IKšž
œœ(œ	œ˜QKšžœœœœ˜6K˜�Kšžœœ˜-Kš
žœœœœœ˜RKšž	œœ&œ˜HKšžœœœœ˜Nšžœœœ˜FK™'—šž
œœ˜&K™'—Kšžœœœ˜0Kšžœœ$ œ˜KKšžœœ˜!Kš
žœœ#œœœ˜sKšžœœ#œ˜ZKšžœœ-˜FKš
žœœœœœ˜oKšž	œœ1œ
˜TKš
žœœ$œœœ˜`Kšžœœ˜-šž	œœ˜K™*K™ —K˜�Kšžœœ˜'Kšž	œœœ˜5K˜�Kšžœœœ
œ˜DKšž	œœœœœœ˜+Kš
ž
œœœœœ˜3K˜�K˜—�…—����®��$¢��