@eramux/graph-structure
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -1,3 +0,4 @@ | ||
declare type NodeId = string; | ||
declare type EdgeWeight = number; | ||
export declare type NodeId = string | number; | ||
export declare type EdgeWeight = number; | ||
export declare type EncodedEdge = string; | ||
export interface Serialized { | ||
@@ -29,11 +30,12 @@ nodes: { | ||
hasEdge(sourceNode: NodeId, targetNode: NodeId): boolean; | ||
inbound(node: NodeId): string[]; | ||
outbound(node: NodeId): string[]; | ||
depthFirstSearch(sourceNodes?: NodeId[], includeSourceNodes?: boolean, errorOnCycle?: boolean): string[]; | ||
inbound(node: NodeId): NodeId[]; | ||
outbound(node: NodeId): NodeId[]; | ||
depthFirstSearch(sourceNodes?: NodeId[], includeSourceNodes?: boolean, errorOnCycle?: boolean): NodeId[]; | ||
hasCycle(): boolean; | ||
lowestCommonAncestors(node1: NodeId, node2: NodeId): string[]; | ||
topologicalSort(sourceNodes?: NodeId[], includeSourceNodes?: boolean): string[]; | ||
shortestPath(sourceNode: NodeId, targetNode: NodeId): string[] & { | ||
lowestCommonAncestors(node1: NodeId, node2: NodeId): NodeId[]; | ||
topologicalSort(sourceNodes?: NodeId[], includeSourceNodes?: boolean): NodeId[]; | ||
shortestPath(sourceNode: NodeId, targetNode: NodeId): NodeId[] & { | ||
weight?: number | undefined; | ||
}; | ||
findComponents(): NodeId[][]; | ||
serialize(): Serialized; | ||
@@ -43,2 +45,1 @@ reset(): void; | ||
} | ||
export {}; |
@@ -274,2 +274,16 @@ "use strict"; | ||
} | ||
findComponents() { | ||
const visitedMap = new Set(); | ||
const componentGroups = []; | ||
for (const node of this.nodes) { | ||
if (!visitedMap.has(node)) { | ||
const subNodes = this.depthFirstSearch([node]); | ||
for (const subNode of subNodes) { | ||
visitedMap.add(subNode); | ||
} | ||
componentGroups.push(subNodes.reverse()); | ||
} | ||
} | ||
return componentGroups; | ||
} | ||
serialize() { | ||
@@ -276,0 +290,0 @@ const serialized = { |
{ | ||
"name": "@eramux/graph-structure", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Typescript graph structure library for common graph operations", | ||
@@ -5,0 +5,0 @@ "main": "dist/Graph.js", |
Sorry, the diff of this file is not supported yet
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
37719
365