aboutsummaryrefslogtreecommitdiff
path: root/node_modules/cyclist
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/cyclist
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/cyclist')
-rw-r--r--node_modules/cyclist/.npmignore1
-rw-r--r--node_modules/cyclist/README.md39
-rw-r--r--node_modules/cyclist/index.js33
-rw-r--r--node_modules/cyclist/package.json15
4 files changed, 88 insertions, 0 deletions
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 <mathiasbuus@gmail.com>"
+}