-- LeftFeaturePQ.mesa

-- A generic package to organize items
-- in a priority queue, sorted by increasing order of
-- Val.

-- last modified by E. McCreight, September 27, 1984  12:55 PM
-- customized for LeftFeature by E. McCreight,
--    May 6, 1982  2:34 PM
-- written by E. McCreight, February 8, 1982  2:04 PM

DIRECTORY
  ppdefs,
  ChipNetDefs;

LeftFeaturePQ: DEFINITIONS IMPORTS ChipNetDefs =
  BEGIN
  checkTree: PRIVATE BOOLEAN = FALSE;

  Domain: PRIVATE TYPE = ChipNetDefs.Coord;
  Item: PRIVATE TYPE = ChipNetDefs.FeaturePtr;

  LeftFeaturePQHandle: TYPE = LONG POINTER TO PQObject ← NIL;
  PQHandle: PRIVATE TYPE = LeftFeaturePQHandle;
  maxNSeqs: CARDINAL = 16;
  PQObject: PRIVATE TYPE = RECORD [
    zone: UNCOUNTED ZONE,
    size: LONG INTEGER ← 0,
    topSeq: [0..maxNSeqs) ← 0,
    s: ARRAY [0..maxNSeqs) OF PQSeqPtr ← ALL[NIL]
    ];

  PQSeqPtr: PRIVATE TYPE = LONG POINTER TO PQSeq ← NIL;
  maxItemsPerSeq: CARDINAL = 16000;
    -- WARNING: This many Items must fit in no more than 32700 words,
    --    because of free storage package limitations!!
  PQSeq: PRIVATE TYPE = RECORD[
    heap: SEQUENCE max: [0..maxItemsPerSeq] OF Item
    ];

  LeftFeaturePQUnderflow: SIGNAL;

  NewLeftFeaturePQ: PROCEDURE[zone: UNCOUNTED ZONE,
    max: CARDINAL ← 50]
    RETURNS[PQHandle];

  DestroyLeftFeaturePQ: PROCEDURE[p: PQHandle]
    RETURNS[PQHandle];

  InsertLeftFeaturePQ: PROCEDURE[p: PQHandle, item: Item];

  ExtractLeftFeaturePQ: PROCEDURE[p: PQHandle] RETURNS[item: Item];

  MapEqualLeftFeaturePQ: PROCEDURE[p: PQHandle,
    proc: PROCEDURE[Item]];

  DeleteEqualLeftFeaturePQ: PROCEDURE[p: PQHandle];

  LeftFeaturePQSize: PROCEDURE[p: PQHandle] RETURNS[LONG INTEGER] =
    INLINE
    {RETURN[p.size]};

  LeftFeaturePQMin: PROCEDURE[p: PQHandle] RETURNS[item: Item] =
    INLINE
    {RETURN[p.s[0][0]]};

  ValLess: PROCEDURE[item1, item2: Item] RETURNS[BOOLEAN] = INLINE
    {RETURN[item1.cover.x1<item2.cover.x1]};

  END. -- of LeftFeaturePQ