Permalink
Browse files

the module

  • Loading branch information...
isaacs committed Nov 22, 2011
1 parent 8e56b69 commit b280846e70e38f9beb77a8211f73a69524f528ef
Showing with 50 additions and 0 deletions.
  1. +50 −0 fast-list.js
View
@@ -0,0 +1,50 @@
module.exports = FastList
function Item (data, prev, next) {
this.next = next
if (next) next.prev = this
this.prev = prev
if (prev) prev.next = this
this.data = data
}
function FastList () {
if (!(this instanceof FastList)) return new FastList
this._head = null
this._tail = null
this.length = 0
}
FastList.prototype =
{ push: function (data) {
this._tail = new Item(data, this._tail, null)
this.length ++
}
, pop: function () {
if (this.length === 0) return undefined
var t = this._tail
this._tail = t.prev
if (t.prev) {
t.prev = this._tail.next = null
}
this.length --
return t.data
}
, unshift: function (data) {
this._head = new Item(data, null, this._head)
this.length ++
}
, shift: function () {
if (this._lenth === 0) return undefined
var h = this._head
this._head = h.next
if (h.next) {
h.next = this._head.prev = null
}
this.length --
return h.data
}
, drop: function () {
FastList.call(this)
}
}

0 comments on commit b280846

Please sign in to comment.