-- LeftFeaturePQ.mesa

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

-- last modified by E. McCreight, July 29, 1982  2:52 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;
  PQObject: PRIVATE TYPE = RECORD [
    zone: UNCOUNTED ZONE,
    size: CARDINAL ← 0,
    s: PQSeqPtr
    ];

  PQSeqPtr: PRIVATE TYPE = LONG POINTER TO PQSeq ← NIL;
  PQSeq: PRIVATE TYPE = RECORD[
    heap: SEQUENCE max: CARDINAL 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[CARDINAL] =
    INLINE
    {RETURN[p.size]};

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

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

  END. -- of LeftFeaturePQ