Comparing version 1.1.0 to 1.2.0
@@ -8,5 +8,7 @@ const FixedFIFO = require('./fixed-size') | ||
this.tail = this.head | ||
this.length = 0 | ||
} | ||
push (val) { | ||
this.length++ | ||
if (!this.head.push(val)) { | ||
@@ -20,2 +22,3 @@ const prev = this.head | ||
shift () { | ||
if (this.length !== 0) this.length-- | ||
const val = this.tail.shift() | ||
@@ -28,2 +31,3 @@ if (val === undefined && this.tail.next) { | ||
} | ||
return val | ||
@@ -30,0 +34,0 @@ } |
{ | ||
"name": "fast-fifo", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A fast fifo implementation similar to the one powering nextTick in Node.js core", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -48,2 +48,6 @@ # fast-fifo | ||
#### `len = q.length` | ||
Get the number of entries remaining in the FIFO. | ||
## Benchmarks | ||
@@ -50,0 +54,0 @@ |
26
test.js
@@ -33,4 +33,8 @@ const tape = require('tape') | ||
t.ok(q.isEmpty()) | ||
t.equal(q.length, 0) | ||
for (const value of values) q.push(value) | ||
while (!q.isEmpty()) t.same(q.shift(), values.shift()) | ||
while (!q.isEmpty()) { | ||
t.same(q.shift(), values.shift()) | ||
t.equal(q.length, values.length) | ||
} | ||
t.same(q.shift(), undefined) | ||
@@ -40,1 +44,21 @@ t.ok(q.isEmpty()) | ||
}) | ||
tape('long length', function (t) { | ||
const q = new FIFO() | ||
const len = 0x8f7 | ||
for (let i = 0; i < len; i++) q.push(i) | ||
t.same(q.length, len) | ||
let shifts = 0 | ||
while (!q.isEmpty()) { | ||
q.shift() | ||
shifts++ | ||
} | ||
t.same(shifts, len) | ||
t.same(q.length, 0) | ||
t.end() | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6277
144
75