DIRECTORY Basics, Collections, PairCollections, List, Rope; StdPairCollections5: CEDAR PROGRAM IMPORTS Collections, PairCollections EXPORTS PairCollections = BEGIN OPEN Colls:Collections, PairColls:PairCollections, PairCollections, Collections; Wp: PROC [pair: Pair] RETURNS [REF ANY] ~ INLINE {RETURN [NEW [Pair _ pair]]}; Np: PROC [pair: REF ANY] RETURNS [Pair] ~ INLINE {RETURN [NARROW[pair, REF Pair]^]}; Nmv: PROC [mv: MaybeValue] RETURNS [MaybePair] ~ INLINE {RETURN [IF mv.found THEN [TRUE, Np[mv.val]] ELSE noMaybePair]}; Wmp: PROC [mp: MaybePair] RETURNS [MaybeValue] ~ INLINE {RETURN [IF mp.found THEN [TRUE, Wp[mp.pair]] ELSE noMaybe]}; DefaultWiden: PUBLIC PROC [pc: PairColl] RETURNS [Collection--of REF Pair--] ~ { RETURN [[ wideClasses [pc.MayDuplicate] [pc.OrderStyleOf] [pc.MutabilityOf], pc.Refify ]]; }; WideClasses: TYPE ~ ARRAY --mayDuplicate--BOOL OF ARRAY OrderStyle OF ARRAY Mutability OF CollectionClass; wideClasses: REF WideClasses ~ NEW [WideClasses]; WidePrimitive: PROC [coll: Collection, op: ATOM, args: ArgList _ NIL] RETURNS [PrimitiveAnswer] ~ { pc: PairColl ~ PairColls.DeRef[coll.data]; SELECT op FROM $IsPairColl, $QuaPairColl => RETURN [yes]; $HasMember => RETURN [IF pc.QualityOf[$HasPair]>cant THEN yes ELSE no]; $Scan, $Extremum, $Get3, $Size, $Copy, $Insulate, $ValueOf, $Freeze, $Thaw, $AddColl, $OrderingOf => RETURN [IF pc.QualityOf[op, args]>cant THEN yes ELSE no]; $RemoveColl => RETURN [IF pc.QualityOf[$RemColl]>cant THEN yes ELSE no]; $SpaceOf => RETURN [IF pc.QualityOf[$Spaces]>cant THEN yes ELSE no]; ENDCASE => RETURN [no]; }; WideHasMember: PROC [coll: Collection, elt: Value] RETURNS [BOOL] ~ { pc: PairColl ~ PairColls.DeRef[coll.data]; RETURN pc.HasPair[Np[elt]]}; WideEnumerate: PROC [coll: Collection, Consumer: PROC [elt: Value], bkwd: BOOL] ~ { pc: PairColl ~ PairColls.DeRef[coll.data]; rp: REF Pair ~ NEW [Pair]; Pass: PROC [pair: Pair] ~ {rp^ _ pair; Consumer[rp]}; pc.Enumerate[Pass, bkwd]; RETURN}; WideScan: PROC [coll: Collection, Test: Tester, bkwd: BOOL] RETURNS [MaybeValue] ~ { pc: PairColl ~ PairColls.DeRef[coll.data]; rp: REF Pair ~ NEW [Pair]; Pass: PROC [pair: Pair] RETURNS [pass: BOOL] ~ {rp^ _ pair; pass _ Test[rp]}; RETURN Wmp[pc.Scan[Pass, bkwd]]}; WideExtremum: PROC [coll: Collection, bkwd, remove: BOOL] RETURNS [MaybeValue] ~ { pc: PairColl ~ PairColls.DeRef[coll.data]; RETURN Wmp[pc.class.Extremum[pc, bkwd, remove]]}; WideGet3: PROC [coll: Collection, elt: Value] RETURNS [prev, same, next: MaybeValue] ~ { pc: PairColl ~ PairColls.DeRef[coll.data]; nPrev, nSame, nNext: MaybePair; [nPrev, nSame, nNext] _ pc.Get3[Np[elt]]; prev _ Wmp[nPrev]; same _ Wmp[nSame]; next _ Wmp[nNext]; RETURN}; WideSize: PROC [coll: Collection, limit: LNAT _ LNAT.LAST] RETURNS [LNAT] ~ { pc: PairColl ~ PairColls.DeRef[coll.data]; RETURN pc.Size[limit]}; WideCopy: PROC [coll: Collection] RETURNS [VarColl] ~ { pc: PairColl ~ PairColls.DeRef[coll.data]; RETURN pc.Copy.Widen.AsVar}; WideInsulate: PROC [coll: Collection] RETURNS [UWColl] ~ { pc: PairColl ~ PairColls.DeRef[coll.data]; RETURN pc.Insulate.Widen.AsUW}; WideValueOf: PROC [coll: Collection] RETURNS [ConstColl] ~ { pc: PairColl ~ PairColls.DeRef[coll.data]; RETURN pc.ValueOf.Widen.AsConst}; WideFreeze: PROC [coll: Collection] RETURNS [ConstColl] ~ { pc: PairColl ~ PairColls.DeRef[coll.data]; RETURN pc.Freeze.Widen.AsConst}; WideThaw: PROC [coll: Collection] ~ { pc: PairColl ~ PairColls.DeRef[coll.data]; pc.Thaw; RETURN}; WideAddColl: PROC [coll, other: Collection, where: Where] RETURNS [someNew, allNew: BOOL] ~ { pc: PairColl ~ PairColls.DeRef[coll.data]; oPC: PairColl ~ PairColls.DeRef[other.AsPairColl]; fnl: BoolPair ~ pc.Functional; dir: Direction ~ IF fnl[leftToRight] THEN leftToRight ELSE IF fnl[rightToLeft] THEN rightToLeft ELSE ERROR Cant[coll]--don't know how to compute someNew & allNew--; pcWhere: PairColls.Where ~ WITH where SELECT FROM x: any Where => [any[]], x: end Where => [end[x.end]], x: rel Where => [rel[Np[x.elt], x.reln]], ENDCASE => ERROR; some: NewsSetPair ~ pc.AddColl[oPC, alwaysAdd, pcWhere]; allNew _ NOT some[dir][same]; someNew _ some[dir][different] OR some[dir][new]; RETURN}; WideRemoveColl: PROC [coll, other: Collection, style: RemoveStyle] RETURNS [hadSome, hadAll: BOOL] ~ { pc: PairColl ~ PairColls.DeRef[coll.data]; oPC: PairColl ~ PairColls.DeRef[other.AsPairColl]; fnl: BoolPair ~ pc.Functional; dir: Direction ~ IF fnl[leftToRight] THEN leftToRight ELSE IF fnl[rightToLeft] THEN rightToLeft ELSE ERROR Cant[coll]--don't know how to compute someNew & allNew--; hadSomePair, hadAllPairs: BoolPair; [hadSomePair, hadAllPairs] _ pc.RemColl[oPC, style]; RETURN [hadSomePair[dir], hadAllPairs[dir]]}; WideQuaPairColl: PROC [coll: Collection] RETURNS [MaybeValue] ~ { pc: PairColl ~ PairColls.DeRef[coll.data]; RETURN [[TRUE, pc.Refify]]}; WideSpaceOf: PROC [coll: Collection] RETURNS [Space] ~ { pc: PairColl ~ PairColls.DeRef[coll.data]; RETURN [WidenSpacePair[pc.Spaces]]}; WideOrderingOf: PROC [coll: Collection] RETURNS [Ordering] ~ { pc: PairColl ~ PairColls.DeRef[coll.data]; RETURN [pc.OrderingOf.WidenOrdering]}; WidePreserveValue: PROC [coll: Collection, val: Value] RETURNS [Value] ~ { rp: REF Pair ~ NARROW[val]; RETURN [NEW [Pair _ rp^]]}; Start: PROC ~ { FOR mayDuplicate: BOOL IN BOOL DO FOR orderStyle: OrderStyle IN OrderStyle DO FOR mutability: Mutability IN Mutability DO wideClasses[mayDuplicate][orderStyle][mutability] _ CreateClass[[ Primitive: WidePrimitive, HasMember: WideHasMember, Scan: WideScan, Extremum: WideExtremum, Get3: WideGet3, Size: WideSize, Copy: WideCopy, Insulate: WideInsulate, ValueOf: WideValueOf, Freeze: WideFreeze, Thaw: WideThaw, AddColl: WideAddColl, RemoveColl: WideRemoveColl, QuaPairColl: WideQuaPairColl, SpaceOf: WideSpaceOf, OrderingOf: WideOrderingOf, PreserveValue: WidePreserveValue, mayDuplicate: mayDuplicate, orderStyle: orderStyle, mutability: mutability ]]; ENDLOOP ENDLOOP ENDLOOP; RETURN}; Start[]; END. bStdPairCollections5.Mesa Last tweaked by Mike Spreitzer on October 16, 1987 10:31:36 am PDT Κ˜code™KšœB™B—K˜KšΟk œ2˜;K˜šΟnœœ˜"Kšœ˜$Kšœ˜K˜—K˜Kšœœžœž œ/˜VK˜š žœœœœœ˜'Kšœœœœ˜&—K˜š žœœœœœ˜'Kš œœœœœ ˜,—K˜šžœœœ ˜.Kš œœœœ œœœ˜I—K˜šžœœœ ˜.Kš œœœœ œœœ ˜F—K˜š ž œœœœ Οcœ˜Pšœ˜ šœ ˜ K˜K˜K˜—K˜ K˜—K˜—K˜Kšœ œœŸœœœ œœ œ˜jKšœ œœ˜1K˜š ž œœœœœ˜cKšœ*˜*šœ˜Kšœœ˜*Kš œœœœœ˜GKš œeœœœœ˜žKš œœœœœ˜HKš œ œœœœ˜DKšœœ˜—K˜—K˜šž œœ œœ˜EK˜*Kšœ˜—K˜š ž œœžœœœ˜SK˜*Kšœœœ˜Kšžœœ+˜5Kšœ˜Kšœ˜—K˜š žœœžœœœ˜TK˜*Kšœœœ˜Kšžœœœœ"˜MKšœ˜!—K˜šž œœ"œœ˜RK˜*Kšœ+˜1—K˜šžœœ œ#˜XK˜*K˜K˜)K˜Kšœ˜Kšœ˜Kšœ˜—K˜šžœœœœœœœ˜MK˜*Kšœ˜—K˜šžœœœ˜7K˜*Kšœ˜—K˜šž œœœ ˜:K˜*Kšœ˜—K˜šž œœœ˜K˜*Kšœ ˜&—K˜šžœœ œ ˜JKšœœœ˜Kšœœ˜—K˜šžœœ˜šœœœœœœœ œœœ ˜yšœA˜AKšž œ˜Kšž œ˜Kšžœ ˜Kšžœ˜Kšžœ ˜Kšžœ ˜Kšžœ ˜Kšžœ˜Kšžœ˜Kšžœ ˜Kšžœ ˜Kšžœ˜Kšž œ˜Kšž œ˜Kšžœ˜Kšž œ˜Kšž œ˜!Kšœ˜Kšœ˜Kšœ˜K˜—Kšœœœ˜—Kšœ˜—K˜K˜K˜Kšœ˜—…—`έ