•fifo
fifo
make-fifo
fifo-empty?
fifo-length
fifo-pop!
fifo-push!
9.3

fifo🔗ℹ

parasaurolophus

 (require fifo) package: fifo

In fact, all of the procedures in this module complete in approximately constant time except fifo-length, whose performance is proportional to the number of items in the FIFO queue (being effectively the mutable list version of length).

A simple FIFO queue implemented using a mutable list wrapped in a vector whose elements point to the head and tail of the list to achieve more or less constant performance when adding or removing items from the queue.

https://github.com/parasaurolophus/fifo

Theory of operation, in pseudo-code:

(define fifo (make‑fifo))

fifo is [’(),’()]

(fifo‑push! fifo ’a)

fifo is [e1, e1] where e1 is (mcons ’a ’())

(fifo‑push! fifo ’b)

fifo is [e1, e2] where e2 is (mcons ’b ’()) and e1’s mcdr has been updated to e2

(fifo‑push! fifo ’c)

fifo is [e1, e3] where e3 is (mcons ’c ’()) and e2’s mcdr has been updated to e3

(fifo‑pop! fifo)

returns ’a and fifo is [e2, e3]

(fifo‑pop! fifo)

returns ’b and fifo is [e3, e3]

(fifo‑pop! fifo)

returns ’c and fifo is [’(), ’()]

(fifo‑pop! fifo)

returns #<void> and fifo is unchanged

procedure

(make-fifo [elements]) → vector?

  elements : ... = any/c
Return a new FIFO initialized with the given elements.

procedure

(fifo-empty? fifo) → boolean?

  fifo : vector?
Return #t if and only if fifo contains any elements, #f otherwise.

procedure

(fifo-length fifo) → number?

  fifo : vector?
Return the number of elements in fifo.

procedure

(fifo-pop! fifo) → any

  fifo : vector?
Remove and return the next element from fifo or void

procedure

(fifo-push! fifo element) → void?

  fifo : vector?
  element : any/c
Add element to the end of fifo.