Remove unused fast-list module from npm

This commit is contained in:
isaacs
2012-03-22 16:43:28 -07:00
parent 67f1778065
commit a7cd76bb3b
5 changed files with 0 additions and 285 deletions

View File

@@ -1 +0,0 @@
node_modules/

View File

@@ -1,4 +0,0 @@
language: node_js
node_js:
- 0.4
- 0.6

View File

@@ -1,116 +0,0 @@
# The Problem
You've got some thing where you need to push a bunch of stuff into a
queue and then shift it out. Or, maybe it's a stack, and you're just
pushing and popping it.
Arrays work for this, but are a bit costly performance-wise.
# The Solution
A linked-list implementation that takes advantage of what v8 is good at:
creating objects with a known shape.
This is faster for this use case. How much faster? About 50%.
$ node bench.js
benchmarking /Users/isaacs/dev-src/js/fast-list/bench.js
Please be patient.
{ node: '0.6.2-pre',
v8: '3.6.6.8',
ares: '1.7.5-DEV',
uv: '0.1',
openssl: '0.9.8l' }
Scores: (bigger is better)
new FastList()
Raw:
> 22556.39097744361
> 23054.755043227666
> 22770.398481973436
> 23414.634146341465
> 23099.133782483157
Average (mean) 22979.062486293868
[]
Raw:
> 12195.121951219513
> 12184.508268059182
> 12173.91304347826
> 12216.404886561955
> 12184.508268059182
Average (mean) 12190.891283475617
new Array()
Raw:
> 12131.715771230503
> 12184.508268059182
> 12216.404886561955
> 12195.121951219513
> 11940.298507462687
Average (mean) 12133.609876906768
Winner: new FastList()
Compared with next highest ([]), it's:
46.95% faster
1.88 times as fast
0.28 order(s) of magnitude faster
Compared with the slowest (new Array()), it's:
47.2% faster
1.89 times as fast
0.28 order(s) of magnitude faster
This lacks a lot of features that arrays have:
1. You can't specify the size at the outset.
2. It's not indexable.
3. There's no join, concat, etc.
If any of this matters for your use case, you're probably better off
using an Array object.
## Installing
```
npm install fast-list
```
## API
```javascript
var FastList = require("fast-list")
var list = new FastList()
list.push("foo")
list.unshift("bar")
list.push("baz")
console.log(list.length) // 2
console.log(list.pop()) // baz
console.log(list.shift()) // bar
console.log(list.shift()) // foo
```
### Methods
* `push`: Just like Array.push, but only can take a single entry
* `pop`: Just like Array.pop
* `shift`: Just like Array.shift
* `unshift`: Just like Array.unshift, but only can take a single entry
* `drop`: Drop all entries
* `item(n)`: Retrieve the nth item in the list. This involves a walk
every time. It's very slow. If you find yourself using this,
consider using a normal Array instead.
* `map(fn, thisp)`: Like `Array.prototype.map`. Returns a new FastList.
* `reduce(fn, startValue, thisp)`: Like `Array.prototype.reduce`
* `forEach(fn, this)`: Like `Array.prototype.forEach`
* `filter(fn, thisp)`: Like `Array.prototype.filter`. Returns a new
FastList.
* `slice(start, end)`: Retrieve an array of the items at this position.
This involves a walk every time. It's very slow. If you find
yourself using this, consider using a normal Array instead.
### Members
* `length`: The number of things in the list. Note that, unlike
Array.length, this is not a getter/setter, but rather a counter that
is internally managed. Setting it can only cause harm.

View File

@@ -1,144 +0,0 @@
;(function() { // closure for web browsers
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)
if (!this._head) this._head = this._tail
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 --
if (this.length === 1) this._head = this._tail
else if (this.length === 0) this._head = this._tail = null
return t.data
}
, unshift: function (data) {
this._head = new Item(data, null, this._head)
if (!this._tail) this._tail = this._head
this.length ++
}
, shift: function () {
if (this.length === 0) return undefined
var h = this._head
this._head = h.next
if (h.next) {
h.next = this._head.prev = null
}
this.length --
if (this.length === 1) this._tail = this._head
else if (this.length === 0) this._head = this._tail = null
return h.data
}
, item: function (n) {
if (n < 0) n = this.length + n
var h = this._head
while (n-- > 0 && h) h = h.next
return h ? h.data : undefined
}
, slice: function (n, m) {
if (!n) n = 0
if (!m) m = this.length
if (m < 0) m = this.length + m
if (n < 0) n = this.length + n
if (m === n) {
return []
}
if (m < n) {
throw new Error("invalid offset: "+n+","+m+" (length="+this.length+")")
}
var len = m - n
, ret = new Array(len)
, i = 0
, h = this._head
while (n-- > 0 && h) h = h.next
while (i < len && h) {
ret[i++] = h.data
h = h.next
}
return ret
}
, drop: function () {
FastList.call(this)
}
, forEach: function (fn, thisp) {
var p = this._head
, i = 0
, len = this.length
while (i < len && p) {
fn.call(thisp || this, p.data, i, this)
p = p.next
i ++
}
}
, map: function (fn, thisp) {
var n = new FastList()
this.forEach(function (v, i, me) {
n.push(fn.call(thisp || me, v, i, me))
})
return n
}
, filter: function (fn, thisp) {
var n = new FastList()
this.forEach(function (v, i, me) {
if (fn.call(thisp || me, v, i, me)) n.push(v)
})
return n
}
, reduce: function (fn, val, thisp) {
var i = 0
, p = this._head
, len = this.length
if (!val) {
i = 1
val = p && p.data
p = p && p.next
}
while (i < len && p) {
val = fn.call(thisp || this, val, p.data, this)
i ++
p = p.next
}
return val
}
}
if ("undefined" !== typeof(exports)) module.exports = FastList
else if ("function" === typeof(define) && define.amd) {
define("FastList", function() { return FastList })
} else (function () { return this })().FastList = FastList
})()

View File

@@ -1,20 +0,0 @@
{
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
"name": "fast-list",
"description": "A fast linked list (good for queues, stacks, etc.)",
"version": "1.0.2",
"repository": {
"type": "git",
"url": "git://github.com/isaacs/fast-list.git"
},
"main": "fast-list.js",
"dependencies": {},
"devDependencies": {
"bench": "~0.3.2",
"tap": "~0.1.0"
},
"scripts": {
"test": "tap test.js",
"bench": "node bench.js"
}
}