TOC Toolkit API - v0.1.0
    Preparing search index...

    A partition of the integers from 0 up to its size into disjoint sets. Every set has one member that stands for it, called its representative.

    find compresses the path to the representative, and union hangs the tree of lower rank under the other. So a sequence of m operations on n elements takes time O(m α(n)), where α is the inverse Ackermann function, which is below 5 for every n that fits in memory. A partition with a budget charges one Resource.Cells for each element.

    The parents and the ranks live in typed arrays of the capacity that the caller states. The arrays double when add runs past the capacity, so a caller that knows the final size states it and never copies.

    Index
    • Makes size elements, each in a set of its own, with room for capacity elements.

      Parameters

      • size: number = 0
      • Optionalbudget: Budget
      • capacity: number = size

      Returns UnionFind

    • get size(): number

      The number of elements.

      Returns number

    • get sets(): number

      The number of disjoint sets.

      Returns number

    • Adds an element in a set of its own, and returns the element.

      Returns number

    • Returns the representative of the set that holds element.

      Parameters

      • element: number

      Returns number

    • Joins the sets of two elements, and returns whether they were two sets.

      Parameters

      • first: number
      • second: number

      Returns boolean

    • Whether two elements are in the same set.

      Parameters

      • first: number
      • second: number

      Returns boolean