Launch Week Day 3: Introducing Organization Notifications in Socket.Learn More
Socket
Book a DemoSign in
Socket

graphlib

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphlib - npm Package Compare versions

Comparing version
0.6.0
to
0.7.0
+8
-0
CHANGELOG.md

@@ -0,4 +1,12 @@

v0.7.0
======
* Remove data.PriorityQueue. Use `cp-data` to get PriorityQueue.
* Remove usage of `cp-set`. We now use `cp-data` instead.
v0.6.0
======
*broken build* - please do not use this release.
* Graph toString() is not longer included in error messages. In most cases its

@@ -5,0 +13,0 @@ excessive verbosity made it difficult to debug errors in the Chrome debugger.

+1
-1

@@ -1,2 +0,2 @@

var Set = require("cp-set").Set;
var Set = require("cp-data").Set;

@@ -3,0 +3,0 @@ module.exports = components;

@@ -1,2 +0,2 @@

var PriorityQueue = require("../data/PriorityQueue");
var PriorityQueue = require("cp-data").PriorityQueue;

@@ -3,0 +3,0 @@ module.exports = dijkstra;

@@ -1,2 +0,2 @@

var Set = require("cp-set").Set;
var Set = require("cp-data").Set;

@@ -3,0 +3,0 @@ module.exports = postorder;

@@ -1,2 +0,2 @@

var Set = require("cp-set").Set;
var Set = require("cp-data").Set;

@@ -3,0 +3,0 @@ module.exports = preorder;

var Graph = require("../Graph"),
PriorityQueue = require("../data/PriorityQueue");
PriorityQueue = require("cp-data").PriorityQueue;

@@ -4,0 +4,0 @@ module.exports = prim;

@@ -1,2 +0,2 @@

var Set = require("cp-set").Set;
var Set = require("cp-data").Set;

@@ -3,0 +3,0 @@ module.exports = BaseGraph;

// This file provides a helper function that mixes-in Dot behavior to an
// existing graph prototype.
var Set = require("cp-set").Set;
var Set = require("cp-data").Set;

@@ -6,0 +6,0 @@ module.exports = compoundify;

@@ -13,3 +13,3 @@ /*

BaseGraph = require("./BaseGraph"),
Set = require("cp-set").Set;
Set = require("cp-data").Set;

@@ -16,0 +16,0 @@ module.exports = Digraph;

@@ -1,2 +0,2 @@

var Set = require("cp-set").Set;
var Set = require("cp-data").Set;

@@ -3,0 +3,0 @@ exports.all = function() {

@@ -13,3 +13,3 @@ /*

BaseGraph = require("./BaseGraph"),
Set = require("cp-set").Set;
Set = require("cp-data").Set;

@@ -16,0 +16,0 @@ module.exports = Graph;

@@ -1,1 +0,1 @@

module.exports = '0.6.0';
module.exports = '0.7.0';
{
"name": "graphlib",
"version": "0.6.0",
"version": "0.7.0",
"description": "A directed and undirected multi-graph library",

@@ -20,3 +20,3 @@ "main": "index.js",

"dependencies": {
"cp-set": "1.0.0"
"cp-data": "1.1.0"
},

@@ -23,0 +23,0 @@ "devDependencies": {

module.exports = PriorityQueue;
/**
* A min-priority queue data structure. This algorithm is derived from Cormen,
* et al., "Introduction to Algorithms". The basic idea of a min-priority
* queue is that you can efficiently (in O(1) time) get the smallest key in
* the queue. Adding and removing elements takes O(log n) time. A key can
* have its priority decreased in O(log n) time.
*/
function PriorityQueue() {
this._arr = [];
this._keyIndices = {};
}
/**
* Returns the number of elements in the queue. Takes `O(1)` time.
*/
PriorityQueue.prototype.size = function() {
return this._arr.length;
};
/**
* Returns the keys that are in the queue. Takes `O(n)` time.
*/
PriorityQueue.prototype.keys = function() {
return this._arr.map(function(x) { return x.key; });
};
/**
* Returns `true` if **key** is in the queue and `false` if not.
*/
PriorityQueue.prototype.has = function(key) {
return key in this._keyIndices;
};
/**
* Returns the priority for **key**. If **key** is not present in the queue
* then this function returns `undefined`. Takes `O(1)` time.
*
* @param {Object} key
*/
PriorityQueue.prototype.priority = function(key) {
var index = this._keyIndices[key];
if (index !== undefined) {
return this._arr[index].priority;
}
};
/**
* Returns the key for the minimum element in this queue. If the queue is
* empty this function throws an Error. Takes `O(1)` time.
*/
PriorityQueue.prototype.min = function() {
if (this.size() === 0) {
throw new Error("Queue underflow");
}
return this._arr[0].key;
};
/**
* Inserts a new key into the priority queue. If the key already exists in
* the queue this function returns `false`; otherwise it will return `true`.
* Takes `O(n)` time.
*
* @param {Object} key the key to add
* @param {Number} priority the initial priority for the key
*/
PriorityQueue.prototype.add = function(key, priority) {
if (!(key in this._keyIndices)) {
var entry = {key: key, priority: priority};
var index = this._arr.length;
this._keyIndices[key] = index;
this._arr.push(entry);
this._decrease(index);
return true;
}
return false;
};
/**
* Removes and returns the smallest key in the queue. Takes `O(log n)` time.
*/
PriorityQueue.prototype.removeMin = function() {
this._swap(0, this._arr.length - 1);
var min = this._arr.pop();
delete this._keyIndices[min.key];
this._heapify(0);
return min.key;
};
/**
* Decreases the priority for **key** to **priority**. If the new priority is
* greater than the previous priority, this function will throw an Error.
*
* @param {Object} key the key for which to raise priority
* @param {Number} priority the new priority for the key
*/
PriorityQueue.prototype.decrease = function(key, priority) {
var index = this._keyIndices[key];
if (priority > this._arr[index].priority) {
throw new Error("New priority is greater than current priority. " +
"Key: " + key + " Old: " + this._arr[index].priority + " New: " + priority);
}
this._arr[index].priority = priority;
this._decrease(index);
};
PriorityQueue.prototype._heapify = function(i) {
var arr = this._arr;
var l = 2 * i,
r = l + 1,
largest = i;
if (l < arr.length) {
largest = arr[l].priority < arr[largest].priority ? l : largest;
if (r < arr.length) {
largest = arr[r].priority < arr[largest].priority ? r : largest;
}
if (largest !== i) {
this._swap(i, largest);
this._heapify(largest);
}
}
};
PriorityQueue.prototype._decrease = function(index) {
var arr = this._arr;
var priority = arr[index].priority;
var parent;
while (index > 0) {
parent = index >> 1;
if (arr[parent].priority < priority) {
break;
}
this._swap(index, parent);
index = parent;
}
};
PriorityQueue.prototype._swap = function(i, j) {
var arr = this._arr;
var keyIndices = this._keyIndices;
var tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
keyIndices[arr[i].key] = i;
keyIndices[arr[j].key] = j;
};