@graphty/algorithms
Version:
Graph algorithms library for browser environments implemented in TypeScript
62 lines • 2.48 kB
TypeScript
import { Graph } from "../core/graph.js";
import type { NodeId } from "../types/index.js";
/**
* Reconstructs a path from source to target using a predecessor map
* @param target - The target node
* @param predecessor - Map of node to its predecessor in the path
* @returns Array of nodes from source to target, or empty array if no path exists
*/
export declare function reconstructPath<T>(target: T, predecessor: Map<T, T | null>): T[];
/**
* Find common neighbors between two nodes
* @param graph - The graph
* @param source - First node
* @param target - Second node
* @param directed - Whether to consider edge direction
* @returns Set of common neighbor node IDs
*/
export declare function getCommonNeighbors(graph: Graph, source: NodeId, target: NodeId, directed?: boolean): Set<NodeId>;
/**
* Find common neighbors for link prediction in directed graphs
* This finds nodes that form a path from source to target (source->X->target)
* @param graph - The graph
* @param source - First node
* @param target - Second node
* @returns Set of intermediate node IDs
*/
export declare function getIntermediateNodes(graph: Graph, source: NodeId, target: NodeId): Set<NodeId>;
/**
* Generate a consistent edge key for undirected graphs
* @param source - Source node
* @param target - Target node
* @param isDirected - Whether the graph is directed
* @returns A consistent edge identifier
*/
export declare function getEdgeKey(source: NodeId, target: NodeId, isDirected: boolean): string;
/**
* Calculate total edge weight in a graph
* @param graph - The graph
* @returns Total weight of all edges
*/
export declare function getTotalEdgeWeight(graph: Graph): number;
/**
* Get node degree with optional mode for directed graphs
* @param graph - The graph
* @param nodeId - The node ID
* @param mode - Degree mode for directed graphs
* @returns Node degree
*/
export declare function getNodeDegree(graph: Graph, nodeId: NodeId, mode?: "in" | "out" | "total"): number;
/**
* Convert directed graph to undirected
* @param graph - The directed graph
* @returns A new undirected graph
*/
export declare function makeUndirected(graph: Graph): Graph;
/**
* Renumber communities consecutively starting from 0
* @param communities - Map of node to community ID
* @returns Map with renumbered community IDs
*/
export declare function renumberCommunities<T>(communities: Map<T, number>): Map<T, number>;
//# sourceMappingURL=graph-utilities.d.ts.map