• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Cyclist
2
3Cyclist is an efficient [cyclic list](http://en.wikipedia.org/wiki/Circular_buffer) implemention for Javascript.
4It is available through npm
5
6	npm install cyclist
7
8## What?
9
10Cyclist allows you to create a list of fixed size that is cyclic.
11In a cyclist list the element following the last one is the first one.
12This property can be really useful when for example trying to order data
13packets that can arrive out of order over a network stream.
14
15## Usage
16
17``` js
18var cyclist = require('cyclist');
19var list = cyclist(4); // if size (4) is not a power of 2 it will be the follwing power of 2
20                       // this buffer can now hold 4 elements in total
21
22list.put(42, 'hello 42'); // store something and index 42
23list.put(43, 'hello 43'); // store something and index 43
24
25console.log(list.get(42)); // prints hello 42
26console.log(list.get(46)); // prints hello 42 again since 46 - 42 == list.size
27```
28
29## API
30
31* `cyclist(size)` creates a new buffer
32* `cyclist#get(index)` get an object stored in the buffer
33* `cyclist#put(index,value)` insert an object into the buffer
34* `cyclist#del(index)` delete an object from an index
35* `cyclist#size` property containing current size of buffer
36
37## License
38
39MIT
40