Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

priorityqueuejs

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

priorityqueuejs - npm Package Compare versions

Comparing version 0.2.0 to 1.0.0

14

History.md

@@ -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 @@ ==================

8

index.js

@@ -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);
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc