Next: Sealers, Previous: Queue, Up: actor-lib: A standard library of sorts [Contents][Index]
The (goblins actor-lib ring-buffer)
module provides an actor implementing
a ring buffer data structure.
Construct new ^ring-buffer actor with a capacity of capacity.
The actor has the following methods:
empty?
: Return #t
if ring buffer is empty.
full?
: Return #t
if ring buffer is full.
capacity
: Return the capacity of the ring buffer.
length
: Return the number of items currently stored in the ring buffer.
put value
: Append value to the ring buffer.
take
: Dequeue an item from the ring buffer.
ref index
: Return the item index within the ring buffer.
head amount
: Return up to amount items from the front of the ring
buffer (i.e. the oldest items).
tail amount
: Return up to amount items from the end of the ring
buffer (i.e. the newest items).
resize new-capacity
: Resizes the ring buffer to have a new
capacity of new-capacity. If the new-capacity is smaller than the
current capacity the oldest items within the ring buffer will be dropped.
clear
: Removes all items from the ring buffer, returning it to be empty.
> (define ring-buffer (spawn ^ring-buffer 5)) > ($ ring-buffer 'empty?) => #t > ($ ring-buffer 'put 'one) > ($ ring-buffer 'put 'two) > ($ ring-buffer 'put 'three) > ($ ring-buffer 'put 'four) > ($ ring-buffer 'put 'five) > ($ ring-buffer 'head 5) => (one two three four five) > ($ ring-buffer 'put 'six) > ($ ring-buffer 'head 5) => (two three four five six) > ($ ring-buffer 'resize 3) > ($ ring-buffer 'head 3) => (four five six) > ($ ring-buffer 'take) => four > ($ ring-buffer 'full?) => #f
Next: Sealers, Previous: Queue, Up: actor-lib: A standard library of sorts [Contents][Index]