UNPKG

@graphty/algorithms

Version:

Graph algorithms library for browser environments implemented in TypeScript

54 lines 1.61 kB
import type { NodeId } from "../types/index.js"; /** * Union-Find (Disjoint Set) data structure with path compression and union by rank * * Efficiently supports dynamic connectivity queries and is essential for * algorithms like connected components and minimum spanning trees. */ export declare class UnionFind { private parent; private rank; private componentCount; constructor(elements: NodeId[]); /** * Find the root of the set containing the element with path compression */ find(element: NodeId): NodeId; /** * Union two sets using union by rank */ union(elementA: NodeId, elementB: NodeId): void; /** * Check if two elements are in the same connected component */ connected(elementA: NodeId, elementB: NodeId): boolean; /** * Get the number of connected components */ getComponentCount(): number; /** * Get all elements that belong to the same component as the given element */ getComponent(element: NodeId): NodeId[]; /** * Get all connected components as separate arrays */ getAllComponents(): NodeId[][]; /** * Get the size of the component containing the given element */ getComponentSize(element: NodeId): number; /** * Add a new element to the data structure */ addElement(element: NodeId): void; /** * Check if an element exists in the data structure */ hasElement(element: NodeId): boolean; /** * Get the total number of elements */ size(): number; } //# sourceMappingURL=union-find.d.ts.map