Options
All
  • Public
  • Public/Protected
  • All
Menu

Class UnionFind

class

UnionFind

Hierarchy

  • UnionFind

Index

Constructors

constructor

  • new UnionFind(nodes?: any[] | Set<any>, path?: [][] | Set<any>, config?: Config): UnionFind
  • Initialize

    constructor

    Parameters

    • Optional nodes: any[] | Set<any>

      Nodes Array

    • Optional path: [][] | Set<any>

      Path Array

    • Default value config: Config = {}

      Config Object

    Returns UnionFind

Properties

Protected _config

_config: object

Type declaration

Protected _nodes

_nodes: Map<any, UnionNode>

Protected _subtree

_subtree: Map<any, UnionNode>

Accessors

config

  • get config(): object

nodes

subtree

Methods

Protected _addNodes

  • _addNodes(nodes: any[] | Set<any>): void

Protected _addPaths

  • _addPaths(path: any[][] | Set<any[]>): void

Protected _defaultConfig

  • _defaultConfig(config: Config): void

Protected _unionAutoCompress

Protected _unionByHeight

Protected _unionNormal

addSubtree

  • addSubtree(nodes?: any[] | Set<any>, paths?: any[][] | Set<any[]>): void
  • description

    Add subtrees

    example
    Base Usage
    let unionFind = new UnionFind(["a","b","c"]);
    unionFind.addSubtree(
        ["d","e"],
        [ ["a","b","c"],["d","e"]]
    );
    // => "a","b","c" is a subtree, "d","e" is a subtree
    

    Parameters

    • Optional nodes: any[] | Set<any>

      Nodes Array

    • Optional paths: any[][] | Set<any[]>

      Path Array

    Returns void

changeSettings

  • changeSettings(config: Config): void

compress

  • compress(): void

findRoot

getUnionNode

  • getUnionNode(node: any): UnionNode | undefined

isConnected

  • isConnected(nodeA: UnionNode, nodeB: UnionNode): boolean
  • isConnected(nodeA: any, nodeB: any): boolean

toString

  • toString(): string
  • description

    returns a string representing all subtrees

    Returns string

union

  • description

    Union two Nodes

    example
    Basic Usage
    let unionFind = new UnionFind(["a","b","c"],[["a","b"]]);
    unionFind.union("b","c");// => "b" is the parent of "c"
    
    example
    Compression Union
    let unionFind = new UnionFind(["a","b","c","d"],[["a","b","c"]],{unionMode:unionMode.compress});
    unionFind.union("c","d");// => "a" is the parent of "d"
    

    Parameters

    Returns void

  • Parameters

    • nodeA: any
    • nodeB: any

    Returns void

Generated using TypeDoc