ImagerFontIDImpl.mesa
Copyright © 1984, 1985 by Xerox Corporation. All rights reserved.
Doug Wyatt, March 12, 1985 1:52:18 pm PST
DIRECTORY
Basics USING [LowHalf],
Checksum USING [ComputeChecksum],
ImagerFontPrivate USING [FontID, FontIDRep],
ImagerTransformation USING [Copy, Transformation, TransformationRep];
ImagerFontIDImpl: CEDAR MONITOR
IMPORTS Basics, Checksum, ImagerTransformation
EXPORTS ImagerFontPrivate
~ BEGIN
FontID: TYPE ~ ImagerFontPrivate.FontID;
FontIDRep: TYPE ~ ImagerFontPrivate.FontIDRep;
Transformation: TYPE ~ ImagerTransformation.Transformation;
TransformationRep: TYPE ~ ImagerTransformation.TransformationRep;
hashTableSize: NAT ~ 253;
HashIndex: TYPE ~ [0..hashTableSize);
HashTable: TYPE ~ REF HashTableRep;
HashTableRep: TYPE ~ ARRAY HashIndex OF FontIDList;
FontIDList: TYPE ~ LIST OF FontID;
hashTable: HashTable ~ NEW[HashTableRep ← ALL[NIL]];
entries: INT ← 0;
collisions: INT ← 0;
misses: INT ← 0;
EqualT:
PROC[p, q: Transformation]
RETURNS[
BOOL] ~ {
RETURN[p.a=q.a AND p.b=q.b AND p.c=q.c AND p.d=q.d AND p.e=q.e AND p.f=q.f];
};
Hash:
PROC[atom:
ATOM, m: Transformation]
RETURNS[
CARDINAL] ~
TRUSTED
INLINE {
RETURN[Checksum.ComputeChecksum[cs: Basics.LowHalf[LOOPHOLE[atom]],
nWords: SIZE[TransformationRep], p: LOOPHOLE[m]]];
};
GetID:
PUBLIC
ENTRY
PROC [atom:
ATOM, m: Transformation]
RETURNS [FontID] ~ {
ENABLE UNWIND => NULL;
hash: CARDINAL ~ Hash[atom, m];
hashIndex: HashIndex ~ hash MOD hashTableSize;
head: FontIDList ~ hashTable[hashIndex];
FOR each: FontIDList ← head, each.rest
UNTIL each=
NIL
DO
id: FontID ~ each.first;
IF id.atom=atom AND EqualT[id.m, m] THEN RETURN[id]
ELSE misses ← misses+1;
ENDLOOP;
{
id: FontID ~ NEW[FontIDRep ← [atom: atom, m: ImagerTransformation.Copy[m]]];
hashTable[hashIndex] ← CONS[id, head];
entries ← entries+1;
IF head#NIL THEN collisions ← collisions+1;
RETURN[id];
};
};
END.