Cyclist is an efficient cyclic list implemention.
npm install cyclist
var cyclist = require'cyclist';var list = cyclist4; // the size of the buffer should be a 2 magnitude// this buffer can now hold 4 elements in totallistput42 'hello 42'; // store something and index 42listput43 'hello 43'; // store something and index 43console.loglistget42; // prints hello 42console.loglistget46; // prints hello 42 again since 46 - 42 == list.size
You can use
.fit(minElementsCount) to make sure the buffer can fit a certain
amount of elements after it has been created.
listfit16; // list can now hold at least 16 elements
cyclist(minSize)creates a new buffer
cyclist#get(index)get an object stored in the buffer
cyclist#put(index,value)insert an object into the buffer
cyclist#del(index)delete an object from an index
cyclist#fit(minSize)resize the buffer if size is less than minSize
cyclist#sizeproperty containing current size of buffer