DIRECTORY Basics, Collections, PairCollections, List, Rope; StdPairCollections4: CEDAR PROGRAM IMPORTS Collections, PairCollections EXPORTS Collections = BEGIN OPEN Colls:Collections, PairColls:PairCollections, Collections, PairCollections; 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]}; DefaultQuaIntFn: PUBLIC PROC [coll: Collection, dir: Direction] RETURNS [MaybeValue] ~ { mpc: MaybeValue ~ coll.QuaPairColl[]; IF NOT mpc.found THEN RETURN [noMaybe]; IF mpc.val=NIL THEN RETURN [[TRUE, NIL]]; {pc: PairColl ~ DeRef[mpc.val]; RETURN DeRef[mpc.val].QuaIntFn}}; DefaultQuaPairColl: PUBLIC PROC [coll: Collection] RETURNS [MaybeValue] ~ { space: Space ~ coll.SpaceOf; IF space=NIL OR NOT IsPairSpace[space] THEN RETURN [noMaybe]; {pc: PairColl ~ [ quaClasses [coll.MayDuplicate] [coll.OrderStyleOf] [coll.MutabilityOf], coll.Refify ]; RETURN [[TRUE, pc.Refify]]}}; QuaClasses: TYPE ~ ARRAY --mayDuplicate--BOOL OF ARRAY OrderStyle OF ARRAY Mutability OF PairCollClass; quaClasses: REF QuaClasses ~ NEW [QuaClasses _ ALL[ALL[ALL[NIL]]]]; QuaPrimitive: PROC [pc: PairColl, op: ATOM, args: ArgList _ NIL] RETURNS [PrimitiveAnswer] ~ { coll: Collection ~ Colls.DeRef[pc.data]; SELECT op FROM $Widen => RETURN [yes]; $HasPair => RETURN [IF coll.QualityOf[$HasMember]>cant THEN yes ELSE no]; $Scan, $Extremum, $Get3, $Size, $Copy, $Insulate, $ValueOf, $Freeze, $Thaw, $AddColl, $OrderingOf => RETURN [IF coll.QualityOf[op, args]>cant THEN yes ELSE no]; $RemColl => RETURN [IF coll.QualityOf[$RemoveColl]>cant THEN yes ELSE no]; $Spaces => RETURN [IF coll.QualityOf[$SpaceOf]>cant THEN yes ELSE no]; ENDCASE => RETURN [no]; }; QuaWiden: PROC [pc: PairColl] RETURNS [Collection--of REF Pair--] ~ { coll: Collection ~ Colls.DeRef[pc.data]; RETURN [coll]}; QuaHasPair: PROC [pc: PairColl, pair: Pair] RETURNS [BOOL] ~ { coll: Collection ~ Colls.DeRef[pc.data]; RETURN coll.HasMember[Wp[pair]]}; QuaScan: PROC [pc: PairColl, Test: Tester, bkwd: BOOL] RETURNS [MaybePair] ~ { coll: Collection ~ Colls.DeRef[pc.data]; Pass: PROC [val: Value] RETURNS [pass: BOOL] ~ {pass _ Test[Np[val]]}; RETURN Nmv[coll.Scan[Pass, bkwd]]}; QuaExtremum: PROC [pc: PairColl, bkwd, remove: BOOL] RETURNS [MaybePair] ~ { coll: Collection ~ Colls.DeRef[pc.data]; RETURN Nmv[coll.class.Extremum[coll, bkwd, remove]]}; QuaGet3: PROC [pc: PairColl, pair: Pair] RETURNS [prev, same, next: MaybePair] ~ { coll: Collection ~ Colls.DeRef[pc.data]; wPrev, wSame, wNext: MaybeValue; [wPrev, wSame, wNext] _ coll.Get3[Wp[pair]]; prev _ Nmv[wPrev]; same _ Nmv[wSame]; next _ Nmv[wNext]; RETURN}; QuaSize: PROC [pc: PairColl, limit: LNAT] RETURNS [LNAT] ~ { coll: Collection ~ Colls.DeRef[pc.data]; RETURN coll.Size[limit]}; QuaCopy: PROC [pc: PairColl] RETURNS [VarPairColl] ~ { coll: Collection ~ Colls.DeRef[pc.data]; RETURN DeRef[coll.Copy.AsPairColl].AsVar}; QuaInsulate: PROC [pc: PairColl] RETURNS [UWPairColl] ~ { coll: Collection ~ Colls.DeRef[pc.data]; RETURN DeRef[coll.Insulate.AsPairColl].AsUW}; QuaValueOf: PROC [pc: PairColl] RETURNS [ConstPairColl] ~ { coll: Collection ~ Colls.DeRef[pc.data]; RETURN DeRef[coll.ValueOf.AsPairColl].AsConst}; QuaFreeze: PROC [pc: PairColl] RETURNS [ConstPairColl] ~ { coll: Collection ~ Colls.DeRef[pc.data]; RETURN DeRef[coll.Freeze.AsPairColl].AsConst}; QuaThaw: PROC [pc: PairColl] ~ { coll: Collection ~ Colls.DeRef[pc.data]; coll.Thaw; RETURN}; QuaAddColl: PROC [pc, other: PairColl, if: IfNewsPair, where: Where] RETURNS [some: NewsSetPair] ~ { coll: Collection ~ Colls.DeRef[pc.data]; oColl: Collection ~ other.Widen[]; collWhere: Colls.Where ~ WITH where SELECT FROM x: any Where => [any[]], x: end Where => [end[x.end]], x: rel Where => [rel[Wp[x.pair], x.reln]], ENDCASE => ERROR; IF if#alwaysAdd THEN Cant[pc]; IF pc.Functional#ALL[FALSE] THEN ERROR; [] _ coll.AddColl[oColl, collWhere]; RETURN}; QuaRemColl: PROC [pc, other: PairColl, style: RemoveStyle] RETURNS [hadSome, hadAll: BoolPair] ~ { coll: Collection ~ Colls.DeRef[pc.data]; oColl: Collection ~ other.Widen[]; IF pc.Functional#ALL[FALSE] THEN ERROR; [] _ coll.RemoveColl[oColl, style]; RETURN}; QuaSpaces: PROC [pc: PairColl] RETURNS [SpacePair] ~ { coll: Collection ~ Colls.DeRef[pc.data]; space: Space ~ coll.SpaceOf; RETURN NarrowSpace[space]}; QuaOrderingOf: PROC [pc: PairColl] RETURNS [Ordering] ~ { coll: Collection ~ Colls.DeRef[pc.data]; RETURN NarrowOrdering[coll.OrderingOf]}; Start: PROC ~ { FOR mayDuplicate: BOOL IN BOOL DO FOR orderStyle: OrderStyle IN OrderStyle DO FOR mutability: Mutability IN Mutability DO quaClasses[mayDuplicate][orderStyle][mutability] _ CreateClass[[ Primitive: QuaPrimitive, Widen: QuaWiden, HasPair: QuaHasPair, Scan: QuaScan, Extremum: QuaExtremum, Get3: QuaGet3, Size: QuaSize, Copy: QuaCopy, Insulate: QuaInsulate, ValueOf: QuaValueOf, Freeze: QuaFreeze, Thaw: QuaThaw, AddColl: QuaAddColl, RemColl: QuaRemColl, Spaces: QuaSpaces, OrderingOf: QuaOrderingOf, functional: [FALSE, FALSE], mayDuplicate: mayDuplicate, orderStyle: orderStyle, mutability: mutability ]]; ENDLOOP ENDLOOP ENDLOOP; RETURN}; Start[]; END. bStdPairCollections4.Mesa Last tweaked by Mike Spreitzer on October 16, 1987 10:31:53 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˜šžœœœ$œ˜XK˜%Kšœœ œœ ˜'Kš œ œœœœœ˜)K˜Kšœ˜!—K˜šžœœœœ˜KK˜Kš œœœœœœ ˜=˜˜ K˜K˜K˜—K˜ K˜—Kšœœ˜—K˜Kšœ œœΟcœœœ œœ œ˜gKš œ œœœœœœ˜CK˜š ž œœœœœ˜^K˜(šœ˜Kšœ œ˜Kš œ œœ!œœ˜IKš œeœœœœ˜ Kš œ œœ"œœ˜JKš œ œœœœ˜FKšœœ˜—K˜—K˜šžœœœ Ÿœ˜EK˜(Kšœ ˜—K˜šž œœœœ˜>K˜(Kšœ˜!—K˜š žœœžœœœ˜NK˜(Kšžœœœœ˜FKšœ˜#—K˜šž œœœœ˜LK˜(Kšœ/˜5—K˜šžœœœ"˜RK˜(K˜ K˜,K˜Kšœ˜Kšœ˜Kšœ˜—K˜š žœœœœœ˜