HashCollectionsPublicImpl.Mesa
Last tweaked by Mike Spreitzer on August 28, 1987 10:09:21 am PDT
DIRECTORY Basics, HashCollectionsPrivate, Collections, PrincOps, Rope;
HashCollectionsPublicImpl:
CEDAR
PROGRAM
IMPORTS HashCollectionsPrivate, Collections
EXPORTS Collections
=
BEGIN OPEN HashCollectionsPrivate, Collections;
initSize: NAT ~ 5;
IsHash:
PUBLIC
PROC [coll: Collection]
RETURNS [
BOOL]
~ {RETURN [ISTYPE[coll.data, HashColl]]};
CreateHashSet:
PUBLIC
PROC [space: Space ← refs]
RETURNS [HashSet] ~ {
realSpace: Space ~ IF space=NIL THEN refs ELSE space;
hc: HashColl ~
NEW [HashCollPrivate ← [
space: realSpace,
sizeLimit: initSize,
elts: NEW [Seq[initSize]]
]];
coll: Collection ~ [classes[variable], hc];
RETURN [coll.AsVar];
};
CreateHashCopy:
PUBLIC
PROC [coll: Collection, space: Space ←
NIL
--NIL means to use the same space as the given collection--]
RETURNS [HashSet] ~ {
copy: Collection ~ CreateHashSet[IF space=NIL THEN coll.SpaceOf ELSE space];
[] ← copy.AddColl[coll];
RETURN [copy.AsVar];
};
CreateHashSetFromProc:
PUBLIC
PROC [
Produce:
PROC [
Consume:
PROC [Value]], space: Space ← refs]
RETURNS [HashSet] ~ {
copy: HashSet ~ CreateHashSet[space];
Consume: PROC [elt: Value] ~ {[] ← copy.AddElt[elt]};
Produce[Consume];
RETURN [copy];
};
END.