Circular Array
Fixed size circular array datastructure
This data structure give an fixed size array, who reuse slots by overwriting existing items and allow to move first and last indexes
How to use
circularIndex
Function who returns the bounded index
./src/circularIndex.mjs
./browser/circularIndex.js
const boundedindex = circularIndex
CircularArray
./src/CircularArray.mjs
./browser/CircularArray.js
const array = 'zero' 'one' 'two' 'three' 'four'const circularArray = CircularArrayCircularArray circularArrayfirstIndex = 2 circularArray // 'zero' circularArray // first index is now set to 1 and last index to 0 circularArray // 'four'
Availlable properties
firstIndex
firstItem
lastIndex
lastItem
Availlable methods
static fromArray(array)
indexToVirtualIndex(index)
getItem(index)
setItem(index, value)
selectPrevious()
selectNext()
Overwritten methods:
unshift(...itemList)
push(...itemList)
shift()
pop()
And all methods of Array.prototype
with untested result
How to install
With Yarn
yarn add fixed-size-circular-array
or with NPM
npm install --save fixed-size-circular-array