Comparing version 1.2.0 to 1.3.0
@@ -11,2 +11,8 @@ module.exports = class FixedFIFO { | ||
clear () { | ||
this.top = this.btm = 0 | ||
this.next = null | ||
this.buffer.fill(undefined) | ||
} | ||
push (data) { | ||
@@ -13,0 +19,0 @@ if (this.buffer[this.top] !== undefined) return false |
@@ -11,2 +11,8 @@ const FixedFIFO = require('./fixed-size') | ||
clear () { | ||
this.head = this.tail | ||
this.head.clear() | ||
this.length = 0 | ||
} | ||
push (val) { | ||
@@ -13,0 +19,0 @@ this.length++ |
{ | ||
"name": "fast-fifo", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "A fast fifo implementation similar to the one powering nextTick in Node.js core", | ||
@@ -8,7 +8,7 @@ "main": "index.js", | ||
"devDependencies": { | ||
"standard": "^12.0.1", | ||
"tape": "^4.10.1" | ||
"standard": "^17.1.0", | ||
"brittle": "^3.3.2" | ||
}, | ||
"scripts": { | ||
"test": "standard && tape test.js" | ||
"test": "standard && brittle test.js" | ||
}, | ||
@@ -15,0 +15,0 @@ "repository": { |
@@ -40,2 +40,6 @@ # fast-fifo | ||
#### `q.clear()` | ||
Remove all values from the FIFO. | ||
#### `bool = q.isEmpty()` | ||
@@ -42,0 +46,0 @@ |
86
test.js
@@ -1,5 +0,5 @@ | ||
const tape = require('tape') | ||
const test = require('brittle') | ||
const FIFO = require('./') | ||
tape('basic', function (t) { | ||
test('basic', function (t) { | ||
const q = new FIFO() | ||
@@ -31,16 +31,15 @@ const values = [ | ||
t.same(q.shift(), undefined) | ||
t.is(q.shift(), undefined) | ||
t.ok(q.isEmpty()) | ||
t.equal(q.length, 0) | ||
t.is(q.length, 0) | ||
for (const value of values) q.push(value) | ||
while (!q.isEmpty()) { | ||
t.same(q.shift(), values.shift()) | ||
t.equal(q.length, values.length) | ||
t.is(q.shift(), values.shift()) | ||
t.is(q.length, values.length) | ||
} | ||
t.same(q.shift(), undefined) | ||
t.is(q.shift(), undefined) | ||
t.ok(q.isEmpty()) | ||
t.end() | ||
}) | ||
tape('long length', function (t) { | ||
test('long length', function (t) { | ||
const q = new FIFO() | ||
@@ -51,3 +50,3 @@ | ||
t.same(q.length, len) | ||
t.is(q.length, len) | ||
@@ -60,6 +59,67 @@ let shifts = 0 | ||
t.same(shifts, len) | ||
t.same(q.length, 0) | ||
t.is(shifts, len) | ||
t.is(q.length, 0) | ||
}) | ||
t.end() | ||
test('clear', function (t) { | ||
const q = new FIFO() | ||
q.push('a') | ||
q.push('a') | ||
q.clear() | ||
t.is(q.shift(), undefined) | ||
t.is(q.length, 0) | ||
for (let i = 0; i < 50; i++) { | ||
q.push('a') | ||
} | ||
q.clear() | ||
t.is(q.shift(), undefined) | ||
t.is(q.length, 0) | ||
}) | ||
test('basic length', function (t) { | ||
const q = new FIFO() | ||
q.push('a') | ||
t.is(q.length, 1) | ||
q.push('a') | ||
t.is(q.length, 2) | ||
q.shift() | ||
t.is(q.length, 1) | ||
q.shift() | ||
t.is(q.length, 0) | ||
q.shift() | ||
t.is(q.length, 0) | ||
}) | ||
test('peek', function (t) { | ||
const q = new FIFO() | ||
q.push('a') | ||
t.is(q.length, 1) | ||
t.is(q.peek(), 'a') | ||
t.is(q.peek(), 'a') | ||
q.push('b') | ||
t.is(q.length, 2) | ||
t.is(q.peek(), 'a') | ||
t.is(q.peek(), 'a') | ||
t.is(q.shift(), 'a') | ||
t.is(q.peek(), 'b') | ||
t.is(q.peek(), 'b') | ||
t.is(q.shift(), 'b') | ||
t.is(q.peek(), undefined) | ||
t.is(q.peek(), undefined) | ||
}) | ||
test('invalid hwm', function (t) { | ||
t.exception(() => new FIFO(3)) | ||
}) |
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
7908
8
199
79