FIFOImpl.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Pradeep Sindhu September 20, 1986 8:21:09 pm PDT
DIRECTORY FIFO;
FIFOImpl: CEDAR PROGRAM
EXPORTS FIFO =
BEGIN OPEN FIFO;
Create: PUBLIC PROC [] RETURNS [fifo: FIFO] = {
fifo ← NEW [FIFORec];
};
Size: PUBLIC PROC [fifo: FIFO] RETURNS [INT] = {
RETURN [fifo.size]
};
Get: PUBLIC PROC [fifo: FIFO] RETURNS [data: REF] = {
IF fifo.head=NIL THEN RETURN [NIL];
data ← fifo.head.data;
fifo.head ← fifo.head.next;
fifo.size ← fifo.size-1;
IF fifo.head=NIL THEN fifo.tail ← NIL
};
Put: PUBLIC PROC [fifo: FIFO, data: REF] = {
fifoEl: FIFOElement ← NEW [FIFOElementRec];
fifoEl.data ← data;
IF fifo.tail=NIL
THEN {fifo.head ← fifo.tail ← fifoEl; fifo.size ← 1}
ELSE {fifo.tail.next ← fifoEl; fifo.tail ← fifoEl; fifo.size ← fifo.size+1}
};
END.