Tanguv0.35.0
Collections7 exports
Raw Markdown

/circular-buffer

Fixed-capacity ring buffer (Circular-Buffer) supporting O(1) push/pop and wraparound iteration.

(use /circular-buffer)

Functions & symbols#

Circular-Buffer#

constructor
(Circular-Buffer capacity [fill-value]) -> Circular-Buffer

Creates a fixed-capacity ring buffer.

ParameterTypeOptionalDescription
capacityIntrequiredMaximum capacity > 0
fillAnyoptionalOptional pre-fill value
Returns:Any
(let ring (cb/Circular-Buffer 4))

Iter#

constructor
(Iter buf) -> Iter

Returns a forward iterator over elements from oldest to newest.

ParameterTypeOptionalDescription
bufCircular-BufferrequiredRing buffer instance
Returns:Any
(for [x (cb/Iter ring)] (say x))

as-array#

function
(as-array buf) -> Array

Materializes the buffered elements in chronological order as an Array.

ParameterTypeOptionalDescription
bufCircular-BufferrequiredRing buffer
Returns:Any
(cb/as-array ring)

count-of#

function
(count-of buf) -> Int

Returns the current number of stored elements.

ParameterTypeOptionalDescription
bufCircular-BufferrequiredRing buffer
Returns:Any
(count-of ring)

into-iter#

function
(into-iter buf) -> Iter

Returns an iterator implementing `Into-Iter`.

ParameterTypeOptionalDescription
bufCircular-BufferrequiredRing buffer
Returns:Any
(into-iter ring)

push#

function
(push buf value) -> Circular-Buffer

Appends `value` at the tail, evicting the oldest element when full.

ParameterTypeOptionalDescription
bufCircular-BufferrequiredTarget ring buffer
valueAnyrequiredItem to append
Returns:Any
(cb/push ring 42)

put#

function
(put buf value) -> Circular-Buffer

Alias of `push`: writes `value` into the ring buffer.

ParameterTypeOptionalDescription
bufCircular-BufferrequiredTarget ring buffer
valueAnyrequiredItem to insert
Returns:Any
(cb/put ring 42)