UNPKG

@graphty/algorithms

Version:

Graph algorithms library for browser environments implemented in TypeScript

109 lines 2.88 kB
import type { Edge, GraphConfig, Node, NodeId } from "../types/index.js"; /** * Core Graph data structure for the Graphty Algorithms library * * Provides efficient graph representation with support for both directed and undirected graphs. * Uses adjacency lists for optimal performance with sparse graphs. */ export declare class Graph { private nodeMap; private adjacencyList; private incomingEdges; private config; private edgeCount; constructor(config?: Partial<GraphConfig>); /** * Add a node to the graph */ addNode(id: NodeId, data?: Record<string, unknown>): void; /** * Remove a node from the graph */ removeNode(id: NodeId): boolean; /** * Add an edge to the graph */ addEdge(source: NodeId, target: NodeId, weight?: number, data?: Record<string, unknown>): void; /** * Remove an edge from the graph */ removeEdge(source: NodeId, target: NodeId): boolean; /** * Check if a node exists in the graph */ hasNode(id: NodeId): boolean; /** * Check if an edge exists in the graph */ hasEdge(source: NodeId, target: NodeId): boolean; /** * Get a node by ID */ getNode(id: NodeId): Node | undefined; /** * Get an edge by source and target */ getEdge(source: NodeId, target: NodeId): Edge | undefined; /** * Get the number of nodes in the graph */ get nodeCount(): number; /** * Get the number of edges in the graph */ get totalEdgeCount(): number; /** * Check if the graph is directed */ get isDirected(): boolean; /** * Get all nodes in the graph */ nodes(): IterableIterator<Node>; /** * Get all edges in the graph */ edges(): IterableIterator<Edge>; /** * Get neighbors of a node (outgoing edges) */ neighbors(nodeId: NodeId): IterableIterator<NodeId>; /** * Get incoming neighbors of a node (directed graphs only) */ inNeighbors(nodeId: NodeId): IterableIterator<NodeId>; /** * Get outgoing neighbors of a node */ outNeighbors(nodeId: NodeId): IterableIterator<NodeId>; /** * Get the degree of a node */ degree(nodeId: NodeId): number; /** * Get the in-degree of a node */ inDegree(nodeId: NodeId): number; /** * Get the out-degree of a node */ outDegree(nodeId: NodeId): number; /** * Create a copy of the graph */ clone(): Graph; /** * Get graph configuration */ getConfig(): GraphConfig; /** * Clear all nodes and edges from the graph */ clear(): void; /** * Get the number of unique edges in the graph * For undirected graphs, each edge is counted once */ get uniqueEdgeCount(): number; } //# sourceMappingURL=graph.d.ts.map