Permalink
Browse files

moved cirq and df to own modules

  • Loading branch information...
1 parent 9a3a872 commit b891a1b27c1e5d843a4095255aae2c0c76f6add6 @coolaj86 committed Jul 28, 2013
Showing with 8 additions and 578 deletions.
  1. +6 −0 .gitmodules
  2. +1 −0 cirq
  3. +0 −98 cirq/README.md
  4. +0 −61 cirq/lib/cirq.js
  5. +0 −24 cirq/max-int.js
  6. +0 −41 cirq/test/bench-cirq.js
  7. +0 −45 cirq/test/bench-shift.js
  8. +0 −86 cirq/test/cirq-test.js
  9. +1 −0 df
  10. +0 −53 df/README.md
  11. +0 −15 df/example.js
  12. +0 −12 df/example.linux.txt
  13. +0 −5 df/example.osx.txt
  14. +0 −90 df/index.js
  15. +0 −17 df/package.json
  16. +0 −31 df/tests.js
View
@@ -19,3 +19,9 @@
[submodule "dom-storage"]
path = dom-storage
url = https://github.com/coolaj86/node-dom-storage.git
+[submodule "df"]
+ path = df
+ url = https://github.com/coolaj86/node-df-js.git
+[submodule "cirq"]
+ path = cirq
+ url = https://github.com/coolaj86/cirqjs.git
1 cirq
Submodule cirq added at 1dde5b
View
@@ -1,98 +0,0 @@
-CirQ
-====
-
-A simple Circular Buffer / Queue with great test coverage.
-
- var CirQ = require('cirq')
- , maxLength = 1
- , cirq = new CirQ(maxLength)
- , assert = require('assert')
- ;
-
- // the default maxLength is `4294967295`, which is `Math.pow(2,32) - 1);`
- // this is the maximum safe integer value
- cirq.push('a');
- cirq.push('b');
-
- assert.deepEqual(['b'], cirq.toArray());
-
- assert.strictEqual('b', cirq.pop());
-
- assert.deepEqual([], cirq.toArray());
-
-API
-===
-
- * `new CirQ(maxLength)`
- * `push(item)`
- * `pop()`
- * `toArray()`
-
-Why
-===
-
-Because I didn't run a performance test first.
-
-Despite rumors, `[].shift()` is probably efficient enough (until about 500,000 elements).
-
-:'(
-
- function bench(max, postMax) {
- console.log(max, postMax);
-
- var now = new Date().valueOf()
- , q = new CirQ(max)
- , i
- ;
-
- for (i = 0; i < max; i += 1) {
- q.push('xyz');
- }
- console.log(new Date().valueOf() - now);
- now = new Date().valueOf();
-
- for (i = 0; i < postMax; i += 1) {
- // q.shift(); // for Array
- q.push('abc');
- }
- console.log(new Date().valueOf() - now);
-
- console.log();
- }
-
-CirQ
-
- 5000 1000
- 1 ms
- 0 ms
-
- 50000 10000
- 19 ms
- 2 ms
-
- 500000 100000
- 146 ms
- 26 ms
-
-
-Array (shift and push)
-
- 5000 1000
- 0 ms
- 0 ms
-
- 50000 10000
- 11 ms
- 1 ms
-
- 500000 100
- 57 ms
- 167 ms
-
- 500000 1000
- 67 ms
- 1631 ms
-
- 5000000 1
- 407 ms
- 11 ms
View
@@ -1,61 +0,0 @@
-(function () {
- "use strict";
-
- // wtfjs x == x+1
- var MAX_INT = 4294967295; // Math.pow(2, 32) - 1;
-
- function CirQ(maxlen) {
- if (!maxlen) {
- maxlen = MAX_INT;
- }
- this.maxlen = maxlen;
- this.cirq = {};
- this.oldest = 0;
- this.next = 0;
- this.length = 0;
- }
-
- // wrapping addition
- function wadd(i, max) {
- return (i + 1) % max;
- }
-
- CirQ.prototype.push = function (item) {
- if (this.next === this.oldest && this.length) {
- this.oldest = wadd(this.oldest, this.maxlen);
- }
- this.cirq[this.next] = item;
- this.length = Math.min(this.length + 1, this.maxlen);
- this.next = wadd(this.next, this.maxlen);
- //console.log('<<', this.oldest, this.next, this.cirq);
- };
-
- CirQ.prototype.pop = function () {
- var res = this.cirq[this.oldest];
- delete this.cirq[this.oldest];
-
- // stuck at head, can't go further
- if (this.length) {
- this.oldest = wadd(this.oldest, this.maxlen);
- }
- this.length = Math.max(this.length - 1, 0);
-
- //console.log('^^', this.oldest, this.next, this.cirq);
- return res;
- };
-
- CirQ.prototype.toArray = function () {
- var res = []
- , i = this.oldest
- ;
-
- while (res.length !== this.length) {
- res.push(this.cirq[i]);
- i = wadd(i, this.maxlen);
- }
-
- return res;
- };
-
- module.exports = CirQ;
-}());
View
@@ -1,24 +0,0 @@
-(function () {
- "use strict";
-
- var x = 0
- , scale = 1
- , start = new Date().valueOf()
- ;
-
- while (x + 1 != x) {
- // 10000000
- if (!(x % 10000000)) {
- console.log(x);
- }
-
- if (x >= scale) {
- console.log(x);
- scale *= 10;
- }
-
- x += 1
- }
-
- console.log(x, new Date().valueOf() - start);
-}());
View
@@ -1,41 +0,0 @@
-(function () {
- "use strict";
-
- var CirQ = require(__dirname + '/../lib/cirq')
- ;
-
- function benchCirQ(max, postMax) {
- console.log(max, postMax);
-
- var now = new Date().valueOf()
- , cirq = new CirQ(max)
- , i
- ;
-
- for (i = 0; i < max; i += 1) {
- cirq.push('xyz');
- }
- console.log(new Date().valueOf() - now);
- now = new Date().valueOf();
-
- for (i = 0; i < postMax; i += 1) {
- cirq.push('abc');
- }
- console.log(new Date().valueOf() - now);
-
- console.log();
- }
-
- // warm-up
- benchCirQ(5000, 1000);
-
- benchCirQ(5000, 1000);
- // 1
- // 1
-
- benchCirQ(50000, 10000);
- // 20
- // 2
-
- benchCirQ(500000, 100000);
-}());
View
@@ -1,45 +0,0 @@
-(function () {
- "use strict";
-
- function benchShift(max, postMax) {
- console.log(max, postMax);
-
- var arr = []
- , now
- , i
- ;
-
- now = new Date().valueOf()
- for (i = 0; i < max; i += 1) {
- arr.push('xyz');
- }
- console.log(new Date().valueOf() - now);
-
- now = new Date().valueOf();
- for (i = 0; i < postMax; i += 1) {
- arr.shift();
- arr.push('abc');
- }
- console.log(new Date().valueOf() - now);
-
- console.log();
- }
-
- // warm-up run
- benchShift(5000, 1000);
-
- benchShift(5000, 1000);
- // 0 ~ 1 ms
- // 0 ~ 1 ms
-
- benchShift(50000, 10000);
- // 10 ~ 13 ms
- // 0 ~ 2 ms
-
- benchShift(500000, 1000);
- // ~ 60 ms
- // ~ 1200 ms
-
- benchShift(5000000, 1);
-
-}());
View
@@ -1,86 +0,0 @@
-(function () {
- "use strict";
-
- var assert = require('assert')
- , CirQ = require(__dirname + '/../lib/cirq')
- , cirq
- ;
-
- cirq = new CirQ(4);
-
- assert.ok(undefined === cirq.pop());
- assert.ok(undefined === cirq.pop());
-
- cirq.push('a');
- cirq.push('b');
- cirq.push('c');
-
- assert.deepEqual(['a','b','c'], cirq.toArray());
-
- assert.strictEqual('a', cirq.pop());
- assert.strictEqual('b', cirq.pop());
- assert.strictEqual('c', cirq.pop());
- assert.ok(undefined === cirq.pop());
- assert.ok(undefined === cirq.pop());
-
- cirq.push('d');
- cirq.push('e');
- cirq.push('f');
- cirq.push('g');
-
- assert.deepEqual(['d','e','f', 'g'], cirq.toArray());
-
- assert.strictEqual('d', cirq.pop());
- assert.strictEqual('e', cirq.pop());
- assert.strictEqual('f', cirq.pop());
- assert.strictEqual('g', cirq.pop());
- assert.ok(undefined === cirq.pop());
- assert.ok(undefined === cirq.pop());
-
- cirq.push('h'); // gets overwritten
- cirq.push('i');
- cirq.push('j');
- cirq.push('k');
- cirq.push('l');
-
- assert.strictEqual('i', cirq.pop());
- assert.strictEqual('j', cirq.pop());
- assert.strictEqual('k', cirq.pop());
- assert.strictEqual('l', cirq.pop());
- assert.ok(undefined === cirq.pop());
- assert.ok(undefined === cirq.pop());
-
- cirq.push('m'); // overwritten
- cirq.push('n'); //
- cirq.push('o'); //
- cirq.push('p'); //
- cirq.push('q');
- cirq.push('r');
- cirq.push('s');
- cirq.push('t');
-
- assert.deepEqual(['q','r','s', 't'], cirq.toArray());
-
- assert.strictEqual('q', cirq.pop());
- assert.strictEqual('r', cirq.pop());
- assert.strictEqual('s', cirq.pop());
- assert.strictEqual('t', cirq.pop());
- assert.ok(undefined === cirq.pop());
- assert.ok(undefined === cirq.pop());
-
- // might as well go to z
- cirq.push('u');
- assert.strictEqual('u', cirq.pop());
- cirq.push('v');
- assert.strictEqual('v', cirq.pop());
- cirq.push('w');
- assert.strictEqual('w', cirq.pop());
- cirq.push('x');
- assert.strictEqual('x', cirq.pop());
- cirq.push('y');
- assert.strictEqual('y', cirq.pop());
- cirq.push('z');
- assert.strictEqual('z', cirq.pop());
-
- console.log('PASS');
-}());
1 df
Submodule df added at c3e3ff
Oops, something went wrong.

0 comments on commit b891a1b

Please sign in to comment.