Class: CircularBuffer

CircularBuffer

Implementation of a CircularBuffer The term circular buffer (also called a ring or cyclic buffer) refers to an area in memory which is used to store incoming data. When the buffer is filled, new data is written starting at the beginning of the buffer and overwriting the old. Reference: CircularBuffer in Boost

 var CircularBuffer=require('dsjslib').CircularBuffer
 var cb=new CircularBuffer(100)
 cb.add(foo)

new CircularBuffer(capacity)

Parameters:
Name Type Argument Description
capacity Number <optional>

default is 32

Source:

Methods

add(obj) → {CircularBuffer}

Add data to buffer. This will overwrite older items if the buffer is full

Parameters:
Name Type Description
obj

Item being added , null and undefined are not supported

Source:
Returns:

this

Type
CircularBuffer

back() → {*}

Get the last element

Source:
Returns:

last element, null if buffer is empty

Type
*

clear()

Clear the contents of this buffer

Source:

entries() → {Array}

Get all buffer entries

Source:
Returns:

Array of all entries in Buffer

Type
Array

front() → {*}

Get the first element

Source:
Returns:

first element, null if buffer is empty

Type
*

get(index) → {*}

Get the item at given index. Returns null if no item exists at given index.

Parameters:
Name Type Description
index Number

index to fetch

Source:
Returns:

item at given index

Type
*

isEmpty() → {boolean}

Check if the buffer is empty

Source:
Returns:

True if buffer is empty

Type
boolean

isFull() → {boolean}

Check if the buffer is full

Source:
Returns:

True if buffer is full

Type
boolean

remove()

Remove the least recent item from the buffer

Source:

size() → {Number}

Return the total number of items in the buffer. this will always be <= buffer capacity

Source:
Returns:

count of items in buffer

Type
Number