ImagerFontAtomImpl.mesa
Copyright © 1984, 1985 by Xerox Corporation. All rights reserved.
Doug Wyatt, May 22, 1985 5:19:35 pm PDT
DIRECTORY
Checksum USING [ComputeChecksum],
IIFontPrivate USING [FontAtom, FontAtomRep],
IITransformation USING [Copy, Equal, Transformation, TransformationRep],
IITypeface USING [Typeface],
PrincOps USING [zXOR];
IIFontAtomImpl: CEDAR MONITOR
IMPORTS Checksum, IITransformation
EXPORTS IIFontPrivate
~ BEGIN
FontAtom: TYPE ~ IIFontPrivate.FontAtom;
FontAtomRep: TYPE ~ IIFontPrivate.FontAtomRep;
Typeface: TYPE ~ IITypeface.Typeface;
Transformation: TYPE ~ IITransformation.Transformation;
TransformationRep: TYPE ~ IITransformation.TransformationRep;
hashTableSize: NAT ~ 253;
HashIndex: TYPE ~ [0..hashTableSize);
HashTable: TYPE ~ REF HashTableRep;
HashTableRep: TYPE ~ ARRAY HashIndex OF FontAtomList;
FontAtomList: TYPE ~ LIST OF FontAtom;
hashTable: HashTable ~ NEW[HashTableRep ← ALL[NIL]];
entries: INT ← 0;
collisions: INT ← 0;
misses: INT ← 0;
Munch: PROC [LONG CARDINAL] RETURNS [CARDINAL]
~ TRUSTED MACHINE CODE { PrincOps.zXOR };
Hash: PROC [typeface: Typeface, m: Transformation] RETURNS [CARDINAL] ~ TRUSTED INLINE {
RETURN[Checksum.ComputeChecksum[cs: Munch[LOOPHOLE[typeface]],
nWords: SIZE[TransformationRep], p: LOOPHOLE[m]]];
};
MakeFontAtom: PUBLIC ENTRY PROC [typeface: Typeface, m: Transformation]
RETURNS
[FontAtom] ~ {
ENABLE UNWIND => NULL;
hash: CARDINAL ~ Hash[typeface, m];
hashIndex: HashIndex ~ hash MOD hashTableSize;
head: FontAtomList ~ hashTable[hashIndex];
FOR each: FontAtomList ← head, each.rest UNTIL each=NIL DO
f: FontAtom ~ each.first;
IF f.typeface=typeface AND IITransformation.Equal[f.m, m] THEN RETURN[f]
ELSE misses ← misses+1;
ENDLOOP;
{
f: FontAtom ~ NEW[FontAtomRep ← [typeface: typeface, m: IITransformation.Copy[m]]];
hashTable[hashIndex] ← CONS[f, head];
entries ← entries+1;
IF head#NIL THEN collisions ← collisions+1;
RETURN[f];
};
};
END.