pax_global_header00006660000000000000000000000064117761714210014521gustar00rootroot0000000000000052 comment=483b979fb1540cdfa3acb708a045d02a88c8736b node-dequeue-1.0.3/000077500000000000000000000000001177617142100141025ustar00rootroot00000000000000node-dequeue-1.0.3/.gitignore000066400000000000000000000000111177617142100160620ustar00rootroot00000000000000*.tmproj node-dequeue-1.0.3/README.md000066400000000000000000000037361177617142100153720ustar00rootroot00000000000000A 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. ### `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.3/lib/000077500000000000000000000000001177617142100146505ustar00rootroot00000000000000node-dequeue-1.0.3/lib/dequeue.js000066400000000000000000000026471177617142100166540ustar00rootroot00000000000000 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.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.3/lib/index.js000066400000000000000000000000571177617142100163170ustar00rootroot00000000000000exports = module.exports = require("./dequeue")node-dequeue-1.0.3/package.json000066400000000000000000000013131177617142100163660ustar00rootroot00000000000000{ "name" : "dequeue" , "main" : "./lib/index.js" , "version" : "1.0.3" , "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" : {} }