{"_id":"double-ended-queue","_rev":"15-362d42c308885156faad88279dc8e8d8","name":"double-ended-queue","description":"Extremely fast double-ended queue implementation","dist-tags":{"latest":"2.1.0-0"},"versions":{"0.9.7":{"name":"double-ended-queue","description":"Extremely fast double-ended queue implementation","version":"0.9.7","keywords":["data-structure","data-structures","queue","deque","double-ended-queue"],"scripts":{"test":"grunt test"},"homepage":"https://github.com/petkaantonov/deque","repository":{"type":"git","url":"git://github.com/petkaantonov/deque.git"},"bugs":{"url":"http://github.com/petkaantonov/deque/issues"},"license":"MIT","author":{"name":"Petka Antonov","email":"petka_antonov@hotmail.com","url":"http://github.com/petkaantonov/"},"devDependencies":{"grunt":"~0.4.1","grunt-contrib-jshint":"~0.6.4","jshint-stylish":"latest","acorn":"~0.3.1","mocha":"~1.12.1","grunt-cli":"~0.1.9","bluebird":"~0.11","benchmark":"latest"},"main":"./js/deque.js","_id":"double-ended-queue@0.9.7","dist":{"shasum":"8ae0a7265df66cdc3f07dce558e9716adb586ab8","tarball":"https://registry.npmjs.org/double-ended-queue/-/double-ended-queue-0.9.7.tgz"},"_from":"./","_npmVersion":"1.3.14","_npmUser":{"name":"esailija","email":"petka_antonov@hotmail.com"},"maintainers":[{"name":"esailija","email":"petka_antonov@hotmail.com"}],"directories":{}},"2.0.0-0":{"name":"double-ended-queue","description":"Extremely fast double-ended queue implementation","version":"2.0.0-0","keywords":["data-structure","data-structures","queue","deque","double-ended-queue"],"scripts":{"test":"grunt test"},"homepage":"https://github.com/petkaantonov/deque","repository":{"type":"git","url":"git://github.com/petkaantonov/deque.git"},"bugs":{"url":"http://github.com/petkaantonov/deque/issues"},"license":"MIT","author":{"name":"Petka Antonov","email":"petka_antonov@hotmail.com","url":"http://github.com/petkaantonov/"},"devDependencies":{"grunt":"~0.4.1","grunt-contrib-jshint":"~0.6.4","jshint-stylish":"latest","acorn":"~0.3.1","mocha":"~1.12.1","grunt-cli":"~0.1.9","bluebird":"~0.11","benchmark":"~1.0.0","deque":"0.0.4","q":"~0.9.7","semver-utils":"~1.1.0"},"main":"./js/deque.js","_id":"double-ended-queue@2.0.0-0","dist":{"shasum":"7847fda1c00fb722245aff83643a4887670efd2c","tarball":"https://registry.npmjs.org/double-ended-queue/-/double-ended-queue-2.0.0-0.tgz"},"_from":"./","_npmVersion":"1.3.14","_npmUser":{"name":"esailija","email":"petka_antonov@hotmail.com"},"maintainers":[{"name":"esailija","email":"petka_antonov@hotmail.com"}],"directories":{}},"2.1.0-0":{"name":"double-ended-queue","description":"Extremely fast double-ended queue implementation","version":"2.1.0-0","keywords":["data-structure","data-structures","queue","deque","double-ended-queue"],"scripts":{"test":"grunt test"},"homepage":"https://github.com/petkaantonov/deque","repository":{"type":"git","url":"git://github.com/petkaantonov/deque.git"},"bugs":{"url":"http://github.com/petkaantonov/deque/issues"},"license":"MIT","author":{"name":"Petka Antonov","email":"petka_antonov@hotmail.com","url":"http://github.com/petkaantonov/"},"devDependencies":{"grunt":"~0.4.1","grunt-contrib-jshint":"~0.6.4","jshint-stylish":"latest","acorn":"~0.3.1","mocha":"~1.12.1","grunt-cli":"~0.1.9","bluebird":"~0.11","benchmark":"~1.0.0","deque":"0.0.4","q":"~0.9.7","semver-utils":"~1.1.0"},"main":"./js/deque.js","gitHead":"51eada75cea686f1eb0c8bb5be486ac630e9b7ee","_id":"double-ended-queue@2.1.0-0","_shasum":"103d3527fd31528f40188130c841efdd78264e5c","_from":".","_npmVersion":"2.1.12","_nodeVersion":"0.10.34","_npmUser":{"name":"esailija","email":"petka_antonov@hotmail.com"},"maintainers":[{"name":"esailija","email":"petka_antonov@hotmail.com"}],"dist":{"shasum":"103d3527fd31528f40188130c841efdd78264e5c","tarball":"https://registry.npmjs.org/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz"},"directories":{}}},"readme":"#Introduction\n\nExtremely fast [double-ended queue](http://en.wikipedia.org/wiki/Double-ended_queue) implementation. Double-ended queue can also be used as a:\n\n- [Stack](http://en.wikipedia.org/wiki/Stack_\\(abstract_data_type\\))\n- [Queue](http://en.wikipedia.org/wiki/Queue_\\(data_structure\\))\n\nThe implementation is GC and CPU cache friendly [circular buffer](http://en.wikipedia.org/wiki/Circular_buffer). [It will run circles around any \"linked list\" implementation](#performance).\n\nEvery queue operation is done in constant `O(1)` - including random access from `.get()`.\n\n#Topics\n\n- [Quick start](#quick-start)\n- [Why not use an Array?](#why-not-use-an-array)\n- [Using double-ended queue as a normal queue](#using-double-ended-queue-as-a-normal-queue)\n- [API reference and examples](#api)\n- [Performance](#performance)\n\n#Quick start\n\n npm install double-ended-queue\n\n```js\nvar Deque = require(\"double-ended-queue\");\n\nvar deque = new Deque([1,2,3,4]);\ndeque.shift(); //1\ndeque.pop(); //4\n```\n\n#Why not use an Array?\n\nArrays take linear `O(N)` time to do `shift` and `unshift` operations. That means in theory that an array with 1000 items is 1000x slower to do those operations than a deque with 1000 items. 10000x slower with 10000 items and so on.\n\nV8 implements [a trick for small arrays](https://code.google.com/p/v8/issues/detail?id=3059) where these operations are done in constant time, however even with this trick deque is still 4x faster.\n\nBut arrays use \"native\" methods, they must be faster!\n\nIn V8, there is almost no advantage for a method to be a built-in. In fact many times built-ins are at a severe disadvantage of having to implement far more complex semantics than is actually needed in practice. For example, sparse array handling punishes almost every built-in array method even though nobody uses sparse arrays as is evidenced by the popularity of the underscore library which doesn't handle sparse arrays in the same way across different browsers.\n\n#Using double-ended queue as a normal queue\n\nQueue is a more commonly needed data structure however a separate implementation does not provide any advantage in terms of performance. Aliases are provided specifically for the queue use-case. You may use `.enqueue(items...)` to enqueue item(s) and `.dequeue()` to dequeue an item.\n\n#API\n\n- [`new Deque()`](#new-deque---deque)\n- [`new Deque(Array items)`](#new-dequearray-items---deque)\n- [`new Deque(int capacity)`](#new-dequeint-capacity---deque)\n- [`push(dynamic items...)`](#pushdynamic-items---int)\n- [`unshift(dynamic items...)`](#unshiftdynamic-items---int)\n- [`pop()`](#pop---dynamic)\n- [`shift()`](#shift---dynamic)\n- [`toArray()`](#toarray---array)\n- [`peekBack()`](#peekback---dynamic)\n- [`peekFront()`](#peekfront---dynamic)\n- [`get(int index)`](#getint-index---dynamic)\n- [`isEmpty()`](#isempty---boolean)\n- [`clear()`](#clear---void)\n\n#####`new Deque()` -> `Deque`\n\nCreates an empty double-ended queue with initial capacity of 16. If you know the optimal size before-hand, use [`new Deque(int capacity)`](#new-dequeint-capacity---deque).\n\n```js\nvar deque = new Deque();\ndeque.push(1, 2, 3);\ndeque.shift(); //1\ndeque.pop(); //3\n```\n\n