From 26105034da4fcce7ac883c899d781f016559310d Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 8 Nov 2018 00:38:48 +0800 Subject: switch to vuepress --- node_modules/cyclist/.npmignore | 1 + node_modules/cyclist/README.md | 39 +++++++++++++++++++++++++++++++++++++++ node_modules/cyclist/index.js | 33 +++++++++++++++++++++++++++++++++ node_modules/cyclist/package.json | 15 +++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 node_modules/cyclist/.npmignore create mode 100644 node_modules/cyclist/README.md create mode 100644 node_modules/cyclist/index.js create mode 100644 node_modules/cyclist/package.json (limited to 'node_modules/cyclist') diff --git a/node_modules/cyclist/.npmignore b/node_modules/cyclist/.npmignore new file mode 100644 index 00000000..ba99195b --- /dev/null +++ b/node_modules/cyclist/.npmignore @@ -0,0 +1 @@ +bench diff --git a/node_modules/cyclist/README.md b/node_modules/cyclist/README.md new file mode 100644 index 00000000..50c35cc5 --- /dev/null +++ b/node_modules/cyclist/README.md @@ -0,0 +1,39 @@ +# Cyclist + +Cyclist is an efficient [cyclic list](http://en.wikipedia.org/wiki/Circular_buffer) implemention for Javascript. +It is available through npm + + npm install cyclist + +## What? + +Cyclist allows you to create a list of fixed size that is cyclic. +In a cyclist list the element following the last one is the first one. +This property can be really useful when for example trying to order data +packets that can arrive out of order over a network stream. + +## Usage + +``` js +var cyclist = require('cyclist'); +var list = cyclist(4); // if size (4) is not a power of 2 it will be the follwing power of 2 + // this buffer can now hold 4 elements in total + +list.put(42, 'hello 42'); // store something and index 42 +list.put(43, 'hello 43'); // store something and index 43 + +console.log(list.get(42)); // prints hello 42 +console.log(list.get(46)); // prints hello 42 again since 46 - 42 == list.size +``` + +## API + +* `cyclist(size)` 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#size` property containing current size of buffer + +## License + +MIT diff --git a/node_modules/cyclist/index.js b/node_modules/cyclist/index.js new file mode 100644 index 00000000..baf710c3 --- /dev/null +++ b/node_modules/cyclist/index.js @@ -0,0 +1,33 @@ +var ensureTwoPower = function(n) { + if (n && !(n & (n - 1))) return n; + var p = 1; + while (p < n) p <<= 1; + return p; +}; + +var Cyclist = function(size) { + if (!(this instanceof Cyclist)) return new Cyclist(size); + size = ensureTwoPower(size); + this.mask = size-1; + this.size = size; + this.values = new Array(size); +}; + +Cyclist.prototype.put = function(index, val) { + var pos = index & this.mask; + this.values[pos] = val; + return pos; +}; + +Cyclist.prototype.get = function(index) { + return this.values[index & this.mask]; +}; + +Cyclist.prototype.del = function(index) { + var pos = index & this.mask; + var val = this.values[pos]; + this.values[pos] = undefined; + return val; +}; + +module.exports = Cyclist; \ No newline at end of file diff --git a/node_modules/cyclist/package.json b/node_modules/cyclist/package.json new file mode 100644 index 00000000..97f61ba0 --- /dev/null +++ b/node_modules/cyclist/package.json @@ -0,0 +1,15 @@ +{ + "name": "cyclist", + "version": "0.2.2", + "repository": "git://github.com/mafintosh/cyclist", + "description": "Cyclist is an efficient cyclic list implemention.", + "dependencies": {}, + "keywords": [ + "circular", + "buffer", + "ring", + "cyclic", + "data" + ], + "author": "Mathias Buus Madsen " +} -- cgit v1.2.3