-- CoordRectPQ.mesa

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

-- customized by E. McCreight, May 21, 1982  2:20 PM
-- written by E. McCreight, February 8, 1982  2:04 PM

DIRECTORY
  ChipNetDefs,
  ReticleBandFormat;

CoordRectPQ: DEFINITIONS =
  BEGIN
  checkTree: PRIVATE BOOLEAN = FALSE;

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

  CoordRectPQHandle: TYPE = LONG POINTER TO PQObject ← NIL;
  PQHandle: PRIVATE TYPE = CoordRectPQHandle;
  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
    ];

  CoordRectPQUnderflow: SIGNAL;

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

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

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

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

  CoordRectPQSize: PROCEDURE[p: PQHandle] RETURNS[CARDINAL] =
    INLINE
    {RETURN[p.size]};

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

  Val: PROCEDURE[item: Item] RETURNS[Domain] = INLINE
    {RETURN[-item.x2]};

  END. -- of CoordRectPQ