HashPairCollectionsPublicImpl.Mesa
Last tweaked by Mike Spreitzer on August 28, 1987 10:45:05 am PDT
DIRECTORY HashPairCollectionsPrivate, HashTables, Collections, PairCollections;
HashPairCollectionsPublicImpl:
CEDAR
PROGRAM
IMPORTS HashPairCollectionsPrivate, HashTables, Collections, PairCollections
EXPORTS PairCollections
=
BEGIN OPEN HT:HashTables, Colls:Collections, Collections, PairCollections, HashPairCollectionsPrivate;
CreateHashReln:
PUBLIC
PROC [spaces: SpacePair ← [
NIL,
NIL], functional: BoolPair ← [
FALSE,
FALSE], mappable: BoolPair ← [
TRUE,
TRUE]]
RETURNS [VarPairColl] ~ {
ability: Abilities;
FOR dir: Direction
IN Direction
DO
IF spaces[Source[dir]]=NIL THEN spaces[Source[dir]] ← Colls.refs;
ability[dir] ← IF functional[dir] THEN map ELSE IF mappable[dir] THEN image ELSE none;
ENDLOOP;
{bestDir: Direction ~ IF ability[rightToLeft] > ability[leftToRight] THEN rightToLeft ELSE leftToRight;
hr: HashRelation ~
NEW [HashRelationPrivate ← [
spaces: spaces,
ability: ability,
bestDir: bestDir,
bestAbility: ability[bestDir],
tables: [HT.Create[spaces[left]], HT.Create[spaces[right]]]
]];
RETURN [AsVar[[FetchClass[hr.ability, variable], hr]]];
}};
CreateHashCopy:
PUBLIC
PROC [pc: PairColl, spaces: SpacePair ← [
NIL,
NIL], mappable: BoolPair ← [
FALSE,
FALSE]]
RETURNS [copy: HashFn] ~ {
FOR side: Side
IN Side
DO
IF spaces[side]=NIL THEN spaces[side] ← pc.Spaces[][side];
IF pc.QualityOf[$Image, LIST[IF side=left THEN $leftToRight ELSE $rightToLeft]] >= goodDefault THEN mappable[From[side]] ← TRUE;
ENDLOOP;
copy ← CreateHashReln[spaces, pc.Functional, mappable];
[] ← copy.AddColl[pc];
};
END.