tiny-queue
Advanced tools
Comparing version 0.1.0 to 0.2.0
24
index.js
@@ -5,9 +5,2 @@ 'use strict'; | ||
// on an array, which is slow. | ||
// The returned Queue object, once instantiated, only supports | ||
// three operations: | ||
// queue.push() | ||
// queue.shift() | ||
// queue.length | ||
// So it's basically a drop-in replacement for most naive usages | ||
// of an array as a queue. | ||
@@ -39,2 +32,19 @@ function Queue() { | ||
Queue.prototype.slice = function (start, end) { | ||
start = typeof start === 'undefined' ? 0 : start; | ||
end = typeof end === 'undefined' ? Infinity : end; | ||
var output = []; | ||
var i = 0; | ||
for (var node = this.first; node; node = node.next) { | ||
if (--end < 0) { | ||
break; | ||
} else if (++i > start) { | ||
output.push(node.item); | ||
} | ||
} | ||
return output; | ||
} | ||
module.exports = Queue; |
{ | ||
"name": "tiny-queue", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Simple FIFO queue implementation to avoid having to do shift() on an array, which is slow.", | ||
@@ -22,3 +22,27 @@ "main": "index.js", | ||
}, | ||
"homepage": "https://github.com/nolanlawson/tiny-queue" | ||
"homepage": "https://github.com/nolanlawson/tiny-queue", | ||
"devDependencies": { | ||
"tape": "^2.13.1" | ||
}, | ||
"scripts": { | ||
"test": "tape test.js" | ||
}, | ||
"testling": { | ||
"files": [ | ||
"test.js" | ||
], | ||
"browsers": [ | ||
"iexplore/8..latest", | ||
"chrome/22..latest", | ||
"chrome/canary", | ||
"firefox/24..latest", | ||
"firefox/nightly", | ||
"opera/15..latest", | ||
"opera/next", | ||
"safari/5.0.5..latest", | ||
"iphone/latest", | ||
"ipad/latest", | ||
"android-browser/latest" | ||
] | ||
} | ||
} |
@@ -5,8 +5,13 @@ tiny-queue | ||
A simple FIFO queue implementation to avoid having to do `shift()` | ||
on an array, which is slow. It's implemented in the straightforward `root -> node1 -> node2 -> etc.` architecture that we all wrote in CS 101. | ||
on an array, which is slow. It's implemented in the straightforward `root -> node1 -> node2 -> etc.` | ||
architecture that we all wrote in CS 101. | ||
This can typically be used as a drop-in replacement for an array, and it's only 24 lines of code. | ||
This can typically be used as a drop-in replacement for an array, and it's only 38 lines of code. | ||
Usage: | ||
### Status | ||
[![browser support](https://ci.testling.com/nolanlawson/tiny-queue.png)](https://ci.testling.com/nolanlawson/tiny-queue) | ||
### Usage | ||
``` | ||
@@ -30,4 +35,6 @@ npm install tiny-queue | ||
### API | ||
The returned `Queue` object, once instantiated, only supports | ||
three operations: | ||
four operations: | ||
@@ -37,2 +44,3 @@ ```js | ||
queue.shift() | ||
queue.slice() // returns a regular Array | ||
queue.length | ||
@@ -39,0 +47,0 @@ ``` |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
29748
14
74
1
48
1