ADTRingBuffer
The RingBuffer module implements buffer with with fixed size and type where data is pushed to the tail and popped from the head. This is therefore a FIFO (First in first out) queue.
The size of the buffer must be of power of two and the available capacity is equal to the buffer size minus one, due to the last element used as an end marker.
Types
RingBuffer* = RECORD
data : ARRAY Size OF Type;
head, tail : CARDINAL;
END;
Procedures
Init
Initialize
PROCEDURE Init*(VAR this : RingBuffer);
RingBuffer.Capacity
Return capacity of buffer
PROCEDURE (VAR this : RingBuffer) Capacity*(): LENGTH;
RingBuffer.Size
Return current size of buffer
PROCEDURE (VAR this : RingBuffer) Size*(): LENGTH;
RingBuffer.Clear
Clear content of buffer
PROCEDURE (VAR this : RingBuffer) Clear*();
RingBuffer.Push
Push value to tail. Return TRUE if the buffer was not full
PROCEDURE (VAR this : RingBuffer) Push*(value- : Type): BOOLEAN;
RingBuffer.Pop
Pop value from head. Return TRUE if data was avaiable
PROCEDURE (VAR this : RingBuffer) Pop*(VAR value : Type): BOOLEAN;
RingBuffer.Peek
Peek value at index. Return TRUE if data was avaiable
PROCEDURE (VAR this : RingBuffer) Peek*(index : CARDINAL; VAR value : Type): BOOLEAN;