Comparing version 0.1.56 to 0.1.57
@@ -17,3 +17,4 @@ declare class Graph { | ||
indegrees(): number[]; | ||
bipartition(): boolean; | ||
} | ||
export { Graph }; |
@@ -11,2 +11,3 @@ "use strict"; | ||
Graph.prototype.create = function (vectors, nodes) { | ||
this._nodes = nodes; | ||
this._adjList = new Array(nodes).fill(0).map(function () { return []; }); | ||
@@ -126,4 +127,28 @@ for (var i = 0; i < vectors.length; i++) { | ||
}; | ||
Graph.prototype.bipartition = function () { | ||
var _a; | ||
var group = new Array(this._nodes + 1).fill(0); | ||
for (var i = 1; i <= this._nodes; i++) { | ||
if (group[i] === 0) { | ||
group[i] = 1; | ||
var queue = [i]; | ||
while (queue.length) { | ||
var node = queue.shift(); | ||
for (var j = 0; j < ((_a = this._adjList[node]) === null || _a === void 0 ? void 0 : _a.length); j++) { | ||
var neighbor = this._adjList[node][j]; | ||
if (group[node] === group[neighbor]) { | ||
return false; | ||
} | ||
if (group[neighbor] === 0) { | ||
group[neighbor] = -1 * group[node]; | ||
queue.push(neighbor); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return true; | ||
}; | ||
return Graph; | ||
}()); | ||
exports.Graph = Graph; |
{ | ||
"name": "flex-algo", | ||
"version": "0.1.56", | ||
"version": "0.1.57", | ||
"description": "\"SDK for commonly used data structure and algorithms\"", | ||
@@ -5,0 +5,0 @@ "main": "lib/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
75286
2057