RefQImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Swinehart, October 22, 1985 3:23:59 pm PDT
DIRECTORY RefQ;
RefQImpl: CEDAR PROGRAM EXPORTS RefQ SHARES RefQ = {
OPEN RefQ;
Enqueue: PUBLIC PROC [queue: Queue, value: REF] RETURNS [qPlusValue: Queue] = {
RETURN[IF value=NIL THEN queue ELSE EnqueueQ[queue, LIST[value]]];
};
EnqueueQ: PUBLIC PROC [queue: Queue, newQ: LIST OF REF] RETURNS [longerQ: Queue] = {
IF newQ=NIL THEN RETURN[queue];
IF queue=NIL THEN RETURN[newQ];
longerQ ← queue;
FOR q: Queue←queue, q.rest DO IF q.rest#NIL THEN LOOP; q.rest←newQ; RETURN; ENDLOOP;
};
Dequeue: PUBLIC PROC [queue: Queue, subqueue: Queue←NIL, mode: DequeueMode←remove]
RETURNS [shorterQ: Queue]= {
prev: LIST OF REF;
shorterQ ← queue;
IF queue=NIL THEN RETURN;
SELECT mode FROM
remove => IF subqueue=NIL THEN subqueue ← queue;
truncate => IF subqueue=NIL THEN RETURN;
ENDCASE=>ERROR;
prev←NIL;
FOR ls: Queue ← queue, ls.rest WHILE ls#NIL DO
IF ls#subqueue THEN { prev ← ls; LOOP; };
SELECT TRUE FROM
prev=NIL OR mode=truncate => shorterQ ← subqueue.rest;
mode=remove => prev.rest ← subqueue.rest;
ENDCASE=>ERROR;
RETURN;
ENDLOOP;
};
Map: PUBLIC PROC[queue: Queue, p: MapType] RETURNS[quit: BOOLFALSE] = {
FOR ls: Queue ← queue, ls.rest WHILE ls#NIL DO
IF p[ls] THEN RETURN[TRUE];
ENDLOOP;
};
}.