Class MinimumSpanningTreeUtil.UnionFind<V>

java.lang.Object
cloud.opencode.base.graph.algorithm.MinimumSpanningTreeUtil.UnionFind<V>
Type Parameters:
V - the vertex type | 顶点类型
Enclosing class:
MinimumSpanningTreeUtil

public static class MinimumSpanningTreeUtil.UnionFind<V> extends Object
Union-Find (Disjoint Set Union) data structure 并查集数据结构

Supports path compression and union by rank for optimal performance.

支持路径压缩和按秩合并以获得最佳性能。

Since:
JDK 25, opencode-base-graph V1.0.0
Author:
Leon Soo www.LeonSoo.com
  • Constructor Summary

    Constructors
    Constructor
    Description
    UnionFind(Set<V> vertices)
    Create a union-find structure for the given vertices 为给定顶点创建并查集结构
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    connected(V v1, V v2)
    Check if two vertices are connected 检查两个顶点是否连通
    find(V v)
    Find the root of a vertex (with path compression) 查找顶点的根(带路径压缩)
    void
    union(V v1, V v2)
    Union two vertices (by rank) 合并两个顶点(按秩合并)

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • UnionFind

      public UnionFind(Set<V> vertices)
      Create a union-find structure for the given vertices 为给定顶点创建并查集结构
      Parameters:
      vertices - the vertices | 顶点集合
  • Method Details

    • find

      public V find(V v)
      Find the root of a vertex (with path compression) 查找顶点的根(带路径压缩)
      Parameters:
      v - the vertex | 顶点
      Returns:
      the root vertex | 根顶点
    • union

      public void union(V v1, V v2)
      Union two vertices (by rank) 合并两个顶点(按秩合并)
      Parameters:
      v1 - first vertex | 第一个顶点
      v2 - second vertex | 第二个顶点
    • connected

      public boolean connected(V v1, V v2)
      Check if two vertices are connected 检查两个顶点是否连通
      Parameters:
      v1 - first vertex | 第一个顶点
      v2 - second vertex | 第二个顶点
      Returns:
      true if connected | 如果连通返回true