Skip to content

Latest commit

 

History

History
81 lines (49 loc) · 1.89 KB

File metadata and controls

81 lines (49 loc) · 1.89 KB

Table of Contents

RingBuffer

RingBuffer implements classic fixed length ring buffer, or circular queue.

The methods match the Array signature for push, pop, unshift, and shift.

For buffer operation either use push/shift together, or unshift/pop together.

RingBuffer is substantially faster than an Array for this use case.

  • capacity Number maximum number of values in the buffer

clear

Empties the ring buffer.

back

Returns the back of the buffer, or undefined if empty

front

Returns the front of the buffer, or undefined if empty

push

Pushes a value onto the back of the buffer. If length === capacity, the value at the front of the buffer is discarded.

  • value any value to push

Returns the current length of the buffer

pop

Removes a value from the back of the buffer and returns it. The newly empty buffer location is set to undefined to release any object references.

Returns the value removed from the back of the buffer or undefined if empty.

shift

Removes a value from the front of the buffer and returns it. The newly empty buffer location is set to undefined to release any object references.

Returns the value removed from the front of the buffer or undefined if empty.

unshift

Pushes a value on the front of the buffer. If length === capacity, the value at the back is discarded.

  • value any to push onto the front

Returns the current length of the buffer.

iterator

Iterator that goes from front to back.

Returns Generator iterates from front to back