From a7116cec793bee24c346323fbc8d025fba5c2657 Mon Sep 17 00:00:00 2001 From: BrianHung Date: Thu, 2 Nov 2023 19:56:27 -0700 Subject: [PATCH] change nodeid back to number only --- src/DependencyGraph/Graph.ts | 6 +++--- src/DependencyGraph/TopSort.ts | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/DependencyGraph/Graph.ts b/src/DependencyGraph/Graph.ts index cf54ad7e5..9946c36b9 100644 --- a/src/DependencyGraph/Graph.ts +++ b/src/DependencyGraph/Graph.ts @@ -8,7 +8,7 @@ import {SimpleCellRange} from '../AbsoluteCellRange' import {TopSort, TopSortResult} from './TopSort' import {ProcessableValue} from './ProcessableValue' -export type NodeId = string | number +export type NodeId = number export type NodeAndId = { node: Node, id: NodeId } export type DependencyQuery = (vertex: Node) => [(SimpleCellAddress | SimpleCellRange), Node][] @@ -288,7 +288,7 @@ export class Graph { operatingFunction: (node: Node) => boolean, onCycle: (node: Node) => void ): TopSortResult { - const topSortAlgorithm = new TopSort(this.nodes, this.edges) + const topSortAlgorithm = new TopSort(this.nodes, this.edges) const modifiedNodesIds = modifiedNodes.map(node => this.getNodeId(node)).filter(id => id !== undefined) as NodeId[] return topSortAlgorithm.getTopSortedWithSccSubgraphFrom(modifiedNodesIds, operatingFunction, onCycle) } @@ -396,7 +396,7 @@ export class Graph { * Doesn't work if overlap between nodeId and node. */ private getNodeIdIfNode(node: Node | NodeId): NodeId | undefined { - return (typeof node === 'number' || typeof node === 'string') ? node : this.nodesIds.get(node) + return typeof node === 'number' ? node : this.nodesIds.get(node) } /** diff --git a/src/DependencyGraph/TopSort.ts b/src/DependencyGraph/TopSort.ts index c7dd80ee9..1044b678d 100644 --- a/src/DependencyGraph/TopSort.ts +++ b/src/DependencyGraph/TopSort.ts @@ -15,12 +15,10 @@ enum NodeVisitStatus { POPPED, } -type id = string | number - /** * An algorithm class. Provides an iterative implementation of Tarjan's algorithm for finding strongly connected components */ -export class TopSort { +export class TopSort { private entranceTime: Map = new Map() private low: Map = new Map() private parent: Map = new Map() @@ -60,7 +58,7 @@ export class TopSort { private getAdjacentNodeIds(id: id) { const edges = this.edges.get(id) if (edges === undefined) { - throw new Error(`Edge set missing for node ${id}: ${Array.from(this.nodes.keys())}`) + throw new Error(`Edge set missing for node ${id}`) } return new Set(Array.from(edges.values()).filter(id => this.nodes.has(id))) }