priorityqueuejs
Advanced tools
Comparing version 0.2.0 to 1.0.0
@@ -0,1 +1,15 @@ | ||
1.0.0 / 2015-02-23 | ||
================== | ||
* Respect queue behavior when elements have the same priority, thank you | ||
@xgbuils. | ||
* Fixes default comparator to also work with `Number` objects. | ||
0.2.0 / 2014-02-06 | ||
================== | ||
* Add #forEach(fn) method, thank you @kessler. | ||
* Now you can find a pre-built file for people who don't use component when | ||
developing for the browser. | ||
0.1.0 / 2013-03-03 | ||
@@ -2,0 +16,0 @@ ================== |
@@ -32,3 +32,3 @@ /** | ||
PriorityQueue.DEFAULT_COMPARATOR = function(a, b) { | ||
if (a instanceof Number && b instanceof Number) { | ||
if (typeof a === 'number' && typeof b === 'number') { | ||
return a - b; | ||
@@ -90,7 +90,7 @@ } else { | ||
if (left < size && this._compare(left, largest) > 0) { | ||
if (left < size && this._compare(left, largest) >= 0) { | ||
largest = left; | ||
} | ||
if (right < size && this._compare(right, largest) > 0) { | ||
if (right < size && this._compare(right, largest) >= 0) { | ||
largest = right; | ||
@@ -122,3 +122,3 @@ } | ||
if (this._compare(current, parent) < 0) break; | ||
if (this._compare(current, parent) <= 0) break; | ||
@@ -125,0 +125,0 @@ this._swap(parent, current); |
{ | ||
"name": "priorityqueuejs", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "a simple priority queue data structure", | ||
@@ -5,0 +5,0 @@ "author": "Jano González <info@janogonzalez.com>", |
@@ -19,2 +19,5 @@ # priorityqueue.js | ||
If you just want a pre-built file for using in the web, check the [releases]( | ||
https://github.com/janogonzalez/priorityqueuejs/releases) section. | ||
## Example | ||
@@ -21,0 +24,0 @@ |
@@ -43,2 +43,9 @@ describe('PriorityQueue()', function() { | ||
}); | ||
it('works with `Number` objects', function() { | ||
var a = Number(10) | ||
var b = Number(1000) | ||
expect(PriorityQueue.DEFAULT_COMPARATOR(a, b)).to.be.below(0); | ||
}); | ||
}); | ||
@@ -199,2 +206,18 @@ }); | ||
}); | ||
describe('when there are elements with the same priority', function() { | ||
it('retains the queue behavior', function () { | ||
var queue = new PriorityQueue(function (a, b) { return b.pri - a.pri; }); | ||
var a = { pri: 1, val: 1 } | ||
var b = { pri: 1, val: 2 } | ||
var c = { pri: 1, val: 3 } | ||
queue.enq(a); | ||
queue.enq(b); | ||
queue.enq(c); | ||
expect(queue.deq()).to.be(a); | ||
expect(queue.deq()).to.be(b); | ||
expect(queue.deq()).to.be(c); | ||
}); | ||
}); | ||
}); |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
15012
359
1
104