-- TiogaPGSupport.Mesa
-- written by Bill Paxton, January 1981
-- last written by Paxton.  March 20, 1981  1:47 PM

DIRECTORY

TiogaFileOps,
TextLooks,
TextNode,
Rope;

TiogaPGSupport: DEFINITIONS =

BEGIN OPEN nodeI:TextNode, fOpsI:TiogaFileOps, looksI:TextLooks;

PGF: TYPE = REF PGFBody;
	-- PGF is the file-level symbol table structure for put/get
PGFBody: TYPE;

PGS: TYPE = REF PGSBody;
	-- PGS if the style-level symbol table structure for put/get
PGSBody: PRIVATE TYPE = RECORD [
	stylename: nodeI.StyleName,
	typeNext: CARDINAL ← 0, -- next available TypeIndex
	typeTable: ARRAY fOpsI.TypeIndex OF nodeI.TypeName,
	typeHashKeys: ARRAY TypeHashIndex OF TypeHashKey,
	typeHashVals: ARRAY TypeHashIndex OF TypeHashVal,
	looksNext: CARDINAL ← 0, -- next available LooksIndex
	looksTable: ARRAY fOpsI.LooksIndex OF looksI.Looks,
	looksHashKeys: ARRAY LooksHashIndex OF LooksHashKey,
	looksHashVals: ARRAY LooksHashIndex OF LooksHashVal
	];

TypeHashIndex: TYPE = [0 .. typeHashSize);
typeHashSize: PRIVATE CARDINAL =  
	IF fOpsI.numTypes > 85 THEN 256 ELSE 128;	-- Should be power of 2
TypeHashKey: PRIVATE TYPE = RECORD [key: nodeI.TypeName ← nodeI.nullTypeName];
TypeHashVal: PRIVATE TYPE = RECORD [index: fOpsI.TypeIndex];

LooksHashIndex: TYPE = [0 .. looksHashSize);
looksHashSize: PRIVATE CARDINAL = 
	IF fOpsI.numLooks > 85 THEN 256 ELSE 128;	-- Should be power of 2
LooksHashKey: PRIVATE TYPE = RECORD [key: looksI.Looks ← looksI.noLooks];
LooksHashVal: PRIVATE TYPE = RECORD [index: fOpsI.LooksIndex];

CreatePGF: PROC RETURNS [PGF];

GetPGS: PROC [stylename: nodeI.StyleName, pgf: PGF]
  RETURNS [PGS];
-- creates a new one if necessary
-- keeps record of them with the pgf

RetrievePGS: PROC [index: fOpsI.StyleIndex, pgf: PGF] RETURNS [PGS];

EnterPGS: PROC [pgs: PGS, pgf: PGF]
  RETURNS [ok: BOOLEAN, index: fOpsI.StyleIndex];

RetrieveStyleName: PROC [pgs: PGS]
  RETURNS [stylename: nodeI.StyleName] = INLINE
	{ RETURN [pgs.stylename] };

RetrieveTypeName: PROC [index: fOpsI.TypeIndex, pgs: PGS]
  RETURNS [typename: nodeI.TypeName] = INLINE
	BEGIN
	IF index >= pgs.typeNext THEN ERROR;
	RETURN [pgs.typeTable[index]];
	END;

EnterTypeName: PROC [typename: nodeI.TypeName, pgs: PGS]
  RETURNS [ok: BOOLEAN, index: fOpsI.TypeIndex];

RetrieveLooks: PROC [index: fOpsI.LooksIndex, pgs: PGS]
  RETURNS [looks: looksI.Looks] = INLINE
	BEGIN
	IF index >= pgs.looksNext THEN ERROR;
	RETURN [pgs.looksTable[index]];
	END;

EnterLooks: PROC [looks: looksI.Looks, pgs: PGS]
  RETURNS [ok: BOOLEAN, index: fOpsI.LooksIndex];

END.