PriorityQueue: CEDAR DEFINITIONS = BEGIN Ref: TYPE = REF Rep; Rep: TYPE = MONITORED RECORD [pred: SortPred, data: REF, size: NAT, seq: Seq]; Seq: TYPE = REF SeqRep; SeqRep: TYPE = RECORD [elements: SEQUENCE space: NAT OF Item]; Item: TYPE = REF; SortPred: TYPE = PROC [x: Item, y: Item, data: REF _ NIL] RETURNS [BOOL]; MaxSize: NAT = 3*(LAST[NAT]/4); PQempty: ERROR; PQover: ERROR; Create: PROC [pred: SortPred, data: REF _ NIL] RETURNS [Ref]; Predict: PROC [size: INT, pred: SortPred, data: REF _ NIL] RETURNS [Ref]; Top: PROC [pq: Ref] RETURNS [Item]; Size: PROC [pq: Ref] RETURNS [INT]; Empty: PROC [pq: Ref] RETURNS [BOOL]; Insert: PROC [pq: Ref, item: Item]; Remove: PROC [pq: Ref] RETURNS [Item]; Copy: PROC [pq: Ref] RETURNS [Ref]; END. °PriorityQueue.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Russ Atkinson, February 5, 1985 11:50:13 am PST A PriorityQueue is a mutable collection of items such that one can insert items in any order and retrieve them in a user-specified best-first order. Each priority queue is monitorized to protect against simultaneous access clashes. Public types type or sorting predicate a SortPred should return TRUE if x is "better" than y data will be same ref as given to Create or Predict largest size permitted in current implementation empty priority queue error priority queue overflow Operations on PriorityQueueRef objects. ... creates a new priority queue with given sorting predicate ... is just like create, but also uses a predicted size. If size > MaxSize, then MaxSize is used instead (the error, if any, will be detected by Insert). ... returns "best" element in queue (signal PQempty if empty) ... returns number of items in queue ... returns true if queue is empty, false if not empty ... inserts new item into the queue (signal PQover if resulting size goes over MaxSize) ... removes "best" item from queue (signal PQempty if empty) ... returns copy of queue Κe˜codešœ™Kšœ Οmœ1™Kšœžœžœ˜K˜šΟnœžœžœžœžœžœžœ˜IKšœ™Kšœžœ™5Kšœ3™3—K˜šœ žœžœžœ˜Kšœ0™0—šœ žœ˜Kšœ™—šœžœ˜Kšœ™—K˜—šœ'™'K˜š Ÿœžœžœžœžœ˜=Kšœ=™=K˜—š Ÿœžœžœžœžœžœ˜IKšœš™šK˜—šŸœžœ žœ˜#Kšœ=™=K˜—šŸœžœ žœžœ˜#Kšœ$™$K˜—šŸœžœ žœžœ˜%Kšœ6™6K˜—šŸœžœ˜#KšœW™WK˜—šŸœžœ žœ˜&Kšœ<™