graphology-indices
Advanced tools
Comparing version 0.16.6 to 0.17.0
@@ -1,6 +0,17 @@ | ||
export default class BFSQueue<T = string> { | ||
import Graph, {Attributes, NodePredicate} from 'graphology-types'; | ||
import FixedDeque from 'mnemonist/fixed-deque'; | ||
export default class BFSQueue< | ||
T = string, | ||
NodeAttributes extends Attributes = Attributes | ||
> { | ||
graph: Graph<NodeAttributes>; | ||
size: number; | ||
seen: Set<string>; | ||
constructor(order: number); | ||
seen: Set<T>; | ||
private queue: FixedDeque<T>; | ||
constructor(graph: Graph<NodeAttributes>); | ||
forEachNodeYetUnseen(callback: NodePredicate<NodeAttributes>): void; | ||
has(node: string): boolean; | ||
hasAlreadySeenEverything(): boolean; | ||
countUnseenNodes(): number; | ||
push(node: string): boolean; | ||
@@ -7,0 +18,0 @@ pushWith(node: string, item: T): boolean; |
@@ -11,4 +11,5 @@ /** | ||
function BFSQueue(order) { | ||
this.queue = new FixedDeque(Array, order); | ||
function BFSQueue(graph) { | ||
this.graph = graph; | ||
this.queue = new FixedDeque(Array, graph.order); | ||
this.seen = new Set(); | ||
@@ -18,2 +19,29 @@ this.size = 0; | ||
BFSQueue.prototype.hasAlreadySeenEverything = function () { | ||
return this.seen.size === this.graph.order; | ||
}; | ||
BFSQueue.prototype.countUnseenNodes = function () { | ||
return this.graph.order - this.seen.size; | ||
}; | ||
BFSQueue.prototype.forEachNodeYetUnseen = function (callback) { | ||
var seen = this.seen; | ||
var graph = this.graph; | ||
graph.someNode(function (node, attr) { | ||
// Useful early exit for connected graphs | ||
if (seen.size === graph.order) return true; // break | ||
// Node already seen? | ||
if (seen.has(node)) return false; // continue | ||
var shouldBreak = callback(node, attr); | ||
if (shouldBreak) return true; | ||
return false; | ||
}); | ||
}; | ||
BFSQueue.prototype.has = function (node) { | ||
@@ -20,0 +48,0 @@ return this.seen.has(node); |
@@ -1,6 +0,16 @@ | ||
export default class DFSStack<T = string> { | ||
import Graph, {Attributes, NodePredicate} from 'graphology-types'; | ||
export default class DFSStack< | ||
T = string, | ||
NodeAttributes extends Attributes = Attributes | ||
> { | ||
graph: Graph<NodeAttributes>; | ||
size: number; | ||
seen: Set<string>; | ||
constructor(order: number); | ||
seen: Set<T>; | ||
private stack: Array<T>; | ||
constructor(graph: Graph<NodeAttributes>); | ||
forEachNodeYetUnseen(callback: NodePredicate<NodeAttributes>): void; | ||
has(node: string): boolean; | ||
hasAlreadySeenEverything(): boolean; | ||
countUnseenNodes(): number; | ||
push(node: string): boolean; | ||
@@ -7,0 +17,0 @@ pushWith(node: string, item: T): boolean; |
@@ -9,4 +9,5 @@ /** | ||
*/ | ||
function DFSStack(order) { | ||
this.stack = new Array(order); | ||
function DFSStack(graph) { | ||
this.graph = graph; | ||
this.stack = new Array(graph.order); | ||
this.seen = new Set(); | ||
@@ -16,2 +17,29 @@ this.size = 0; | ||
DFSStack.prototype.hasAlreadySeenEverything = function () { | ||
return this.seen.size === this.graph.order; | ||
}; | ||
DFSStack.prototype.countUnseenNodes = function () { | ||
return this.graph.order - this.seen.size; | ||
}; | ||
DFSStack.prototype.forEachNodeYetUnseen = function (callback) { | ||
var seen = this.seen; | ||
var graph = this.graph; | ||
graph.someNode(function (node, attr) { | ||
// Useful early exit for connected graphs | ||
if (seen.size === graph.order) return true; // break | ||
// Node already seen? | ||
if (seen.has(node)) return false; // continue | ||
var shouldBreak = callback(node, attr); | ||
if (shouldBreak) return true; | ||
return false; | ||
}); | ||
}; | ||
DFSStack.prototype.has = function (node) { | ||
@@ -18,0 +46,0 @@ return this.seen.has(node); |
{ | ||
"name": "graphology-indices", | ||
"version": "0.16.6", | ||
"version": "0.17.0", | ||
"description": "Miscellaneous indices for graphology.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
45659
1279