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