pax_global_header00006660000000000000000000000064122076661050014517gustar00rootroot0000000000000052 comment=c5f9f06083ca2f411c6105d442bb44ab2e6a15ca node-dequeue-1.0.5/000077500000000000000000000000001220766610500141025ustar00rootroot00000000000000node-dequeue-1.0.5/.gitignore000066400000000000000000000000111220766610500160620ustar00rootroot00000000000000*.tmproj node-dequeue-1.0.5/LICENSE000066400000000000000000000026011220766610500151060ustar00rootroot00000000000000This is the 2-Clause BSD license, aka FreeBSD, copy and pasted from http://opensource.org/licenses/BSD-2-Clause . Copyright (c) 2012, Sean M. Egan All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. node-dequeue-1.0.5/README.md000066400000000000000000000042011220766610500153560ustar00rootroot00000000000000A Simple Double Ended Queue Datastructure ========================================= Dequeue is implemented as a doubly linked circular list with a titular head node. By "titular head node", I mean an empty node to designate the beginning and end of the circularly linked list. I first saw this construction in the linux kernel source and it seem simple and elegant. I added the `.length` property to use it like I was using an Array. I was using a javascript Array as a FIFO. Somewhere between 100,000 and 200,000 entries the program performance went to hell (dev host is a MBP w/8GB RAM). 15 minutes later, I implemented a simple dequeue and my FIFO scales up to millions of entries. It is a drop-in replacement for javascript-arrays-as-fifo. ## Example: Dequeue as a replacement for an Array as a FIFO var Dequeue = require('dequeue') //var fifo = [] var fifo = new Dequeue() fifo.length === 0 //=> true fifo.push(d1) fifo.length === 1 //=> true fifo.unshift(d2) fifo.pop() === d1 //=> true fifo.push(d3) fifo.shift() === d2 //=> true fifo.length === 1 //=> true; only d3 is in the dequeue ## API ### `deque = new Dequeue()` ### `deque.push(value)` Push a value on the end. ### `value = deque.pop()` Remove a value off the end. ### `deque.unshift(value)` Push a value on the beginning. ### `value = deque.shift()` Remove a value off the beginning. ### `value = deque.last()` Examine the value of the end without removing it. ### `value = deque.first()` Examine the value of the beginning without removing it. ### `deque.empty()` Remove all entries. This is NOT a test for an empty dequeue; use `deque.length` for that. ## Future Development Something this simple does not really need a roadmap. However, I am thinking of adding APIs to facilitate walking the Linked List via an iterator. It will be simple and fully backward compatible. ## About the Code I was convinced by [a blog posting](http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding) [by Issac Z. Schlueter](http://blog.izs.me/) that I don't need semicolons. So I don't use them. node-dequeue-1.0.5/lib/000077500000000000000000000000001220766610500146505ustar00rootroot00000000000000node-dequeue-1.0.5/lib/dequeue.js000066400000000000000000000032101220766610500166370ustar00rootroot00000000000000 var Dequeue = exports = module.exports = function Dequeue() { this.head = new Node() this.length = 0 } Dequeue.prototype.push = function(d){ var n = new Node(d) this.head.prepend(n) this.length += 1 return this } Dequeue.prototype.unshift = function(d){ var n = new Node(d) this.head.append(n) this.length += 1 return this } Dequeue.prototype.pop = function(){ if (this.head.prev === this.head) return var n = this.head.prev.remove() this.length -= 1 return n.data } Dequeue.prototype.shift = function(){ if (this.head.next === this.head) return var n = this.head.next.remove() this.length -= 1 return n.data } Dequeue.prototype.last = function(){ if (this.head.prev === this.head) return return this.head.prev.data } Dequeue.prototype.first = function(){ if (this.head.next === this.head) return return this.head.next.data } Dequeue.prototype.empty = function(){ if (this.length === 0 ) return //no node points to head; not necessary for GC, but it makes me feel better. this.head.next.prev = null this.head.prev.next = null //head only points to itself; as a fresh node would this.head.next = this.head this.head.prev = this.head this.length = 0 return } function Node(d) { this.data = d this.next = this this.prev = this } Node.prototype.append = function(n) { n.next = this.next n.prev = this this.next.prev = n this.next = n return n } Node.prototype.prepend = function(n) { n.prev = this.prev n.next = this this.prev.next = n this.prev = n return n } Node.prototype.remove = function() { this.next.prev = this.prev this.prev.next = this.next return this }node-dequeue-1.0.5/lib/index.js000066400000000000000000000000571220766610500163170ustar00rootroot00000000000000exports = module.exports = require("./dequeue")node-dequeue-1.0.5/package.json000066400000000000000000000013131220766610500163660ustar00rootroot00000000000000{ "name" : "dequeue" , "main" : "./lib/index.js" , "version" : "1.0.5" , "description" : "A simple double ended queue datastructure" , "keywords" : ["datastructure", "queue", "double ended queue", "fifo", "FIFO", "linked list"] , "homepage" : "https://github.com/lleo/node-dequeue" , "repository" : { "type": "git" , "url": "https://github.com/lleo/node-dequeue" } , "bugs" : { "url": "https://github.com/lleo/node-dequeue/issues" , "email": "lleoem@gmail.com" } , "author" : { "name": "LLeo" , "email": "lleoem@gmail.com" , "url": "http://lleo-blog.blogspot.com/" } , "engines" : {"node" : "*"} , "dependencies" : {} }