UNPKG

es-next-tools

Version:

A comprehensive utility library for JavaScript and TypeScript that provides a wide range of functions for common programming tasks, including mathematical operations, date manipulations, array and object handling, string utilities, and more.

32 lines (31 loc) 1.04 kB
/** * Represents a Union-Find (Disjoint Set) data structure. */ export declare class UnionFind { private parent; private rank; /** * Creates a Union-Find structure with a specified size. * @param {number} size - The number of elements in the structure. */ constructor(size: number); /** * Finds the root of the set containing the element. * @param {number} element - The element to find. * @returns {number} The root of the set. */ find(element: number): number; /** * Unites two sets. * @param {number} element1 - The first element. * @param {number} element2 - The second element. */ union(element1: number, element2: number): void; /** * Checks if two elements are in the same set. * @param {number} element1 - The first element. * @param {number} element2 - The second element. * @returns {boolean} True if they are in the same set, false otherwise. */ connected(element1: number, element2: number): boolean; }