Class OpenGraph

java.lang.Object
cloud.opencode.base.graph.OpenGraph

public final class OpenGraph extends Object
Open Graph 图组件入口类

Main entry point for graph operations.

图操作的主要入口点。

Features | 特性:

  • Graph creation (directed/undirected/immutable) | 图创建(有向/无向/不可变)
  • Graph traversal (BFS/DFS) | 图遍历(BFS/DFS)
  • Shortest path (Dijkstra, A-star, Bellman-Ford, Floyd-Warshall) | 最短路径(Dijkstra、A-star、Bellman-Ford、Floyd-Warshall)
  • Topological sort & DAG operations | 拓扑排序与DAG操作
  • Connectivity & Strongly connected components | 连通性与强连通分量
  • Articulation points & bridges | 关节点与桥
  • Bipartite detection | 二部图检测
  • Graph metrics & statistics | 图度量与统计
  • Graph diff, transform, snapshot | 图比较、转换、快照

Usage Examples | 使用示例:

// Create a directed graph
Graph<String> graph = OpenGraph.directed();
graph.addEdge("A", "B", 1.0);
graph.addEdge("B", "C", 2.0);

// BFS traversal
List<String> bfsResult = OpenGraph.bfs(graph, "A");

// Shortest path
List<String> path = OpenGraph.shortestPath(graph, "A", "C");

// Topological sort
List<String> order = OpenGraph.topologicalSort(graph);

Security | 安全性:

  • Thread-safe: Yes (stateless utility class) - 线程安全: 是(无状态工具类)
  • Null-safe: Yes (delegates to null-safe implementations) - 空值安全: 是(委托给空值安全的实现)
Since:
JDK 25, opencode-base-graph V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Floyd-Warshall all-pairs shortest paths Floyd-Warshall全源最短路径
    static <V> Set<V>
    Find all articulation points (cut vertices) 查找所有关节点(割点)
    static <V> List<V>
    aStar(Graph<V> graph, V source, V target, BiFunction<V,V,Double> heuristic)
    Find shortest path using A* algorithm 使用A*算法查找最短路径
    static <V> Map<V,Double>
    bellmanFord(Graph<V> graph, V source)
    Bellman-Ford single-source shortest paths (supports negative weights) Bellman-Ford单源最短路径(支持负权边)
    static <V> List<V>
    bfs(Graph<V> graph, V start)
    Breadth-first search 广度优先搜索
    static <V> List<V>
    bidirectionalBfs(Graph<V> graph, V source, V target)
    Find path using bidirectional BFS (efficient for large graphs) 使用双向BFS查找路径(对大图高效)
    Compute bipartite partition or odd cycle witness 计算二部图分区或奇环证据
    static <V> Set<Edge<V>>
    bridges(Graph<V> graph)
    Find all bridges (cut edges) 查找所有桥(割边)
    static <V> boolean
    Check if topological sort is possible (graph is DAG) 检查是否可以进行拓扑排序(图是DAG)
    computeFlow(Graph<V> graph, V source, V sink)
    Compute flow result with detailed information 计算包含详细信息的流结果
    static <V> Graph<Set<V>>
    condensation(Graph<V> graph)
    Get condensation graph (DAG of SCCs) 获取冷凝图(强连通分量的DAG)
    static <V> int
    Get the number of connected components 获取连通分量数量
    static <V> List<Set<V>>
    Find all connected components 查找所有连通分量
    static <V> double
    density(Graph<V> graph)
    Get graph density 获取图密度
    static <V> List<V>
    dfs(Graph<V> graph, V start)
    Depth-first search 深度优先搜索
    static <V> List<V>
    dfsIterative(Graph<V> graph, V start)
    Safe iterative depth-first search (avoids stack overflow) 安全的迭代式深度优先搜索(避免栈溢出)
    static <V> int
    diameter(Graph<V> graph)
    Get graph diameter 获取图直径
    static <V> GraphDiff.DiffResult<V>
    diff(Graph<V> before, Graph<V> after)
    Compare two graphs and get differences 比较两个图并获取差异
    static <V> Map<V,Double>
    dijkstra(Graph<V> graph, V source)
    Dijkstra's shortest path algorithm Dijkstra最短路径算法
    static <V> Graph<V>
    Create a directed graph 创建有向图
    static <V> GraphBuilder<V>
    Create a graph builder for directed graph 创建有向图构建器
    static <V> WeightedGraph<V>
    Create a directed weighted graph 创建有向加权图
    static <V> Graph<V>
    filterEdges(Graph<V> graph, Predicate<Edge<V>> predicate)
    Filter edges from a graph by predicate 按谓词过滤图的边
    static <V> Graph<V>
    filterVertices(Graph<V> graph, Predicate<V> predicate)
    Filter vertices from a graph by predicate 按谓词过滤图的顶点
    static <V> List<V>
    findCycle(Graph<V> graph)
    Find one cycle if exists 如果存在则找到一个环
    static <V> Map<Edge<V>,Double>
    getFlows(Graph<V> graph, V source, V sink)
    Get flow on each edge 获取每条边上的流量
    static <V> boolean
    hasCycle(Graph<V> graph)
    Check if graph contains a cycle 检查图是否包含环
    static <V> boolean
    hasNegativeCycle(Graph<V> graph, V source)
    Check for negative weight cycle reachable from source 检查从源顶点可达的负权环
    static <V> boolean
    Check if a graph has a spanning tree (is connected) 检查图是否有生成树(是否连通)
    static <V> boolean
    isBiconnected(Graph<V> graph)
    Check if graph is biconnected 检查图是否双连通
    static <V> boolean
    isBipartite(Graph<V> graph)
    Check if graph is bipartite 检查图是否为二部图
    static <V> boolean
    isConnected(Graph<V> graph, V v1, V v2)
    Check if two vertices are connected 检查两个顶点是否连通
    static <V> boolean
    Check if graph is fully connected 检查图是否完全连通
    static <V> boolean
    Check if graph is strongly connected 检查图是否强连通
    static <V> Set<Edge<V>>
    kruskal(Graph<V> graph)
    Find minimum spanning tree using Kruskal's algorithm 使用Kruskal算法查找最小生成树
    static <V> List<V>
    longestPath(Graph<V> graph)
    Find longest path in DAG (critical path) 查找DAG中的最长路径(关键路径)
    static <V,R> Graph<R>
    mapVertices(Graph<V> graph, Function<V,R> mapper)
    Transform graph vertices using mapping function 使用映射函数转换图顶点
    static <V> double
    maxFlow(Graph<V> graph, V source, V sink)
    Calculate maximum flow using Ford-Fulkerson algorithm (Edmonds-Karp) 使用Ford-Fulkerson算法(Edmonds-Karp)计算最大流
    static <V> Set<Edge<V>>
    minCut(Graph<V> graph, V source, V sink)
    Find minimum cut edges 查找最小割边
    static <V> double
    mstWeight(Graph<V> graph)
    Calculate the total weight of the minimum spanning tree 计算最小生成树的总权重
    static <V> Set<Edge<V>>
    prim(Graph<V> graph)
    Find minimum spanning tree using Prim's algorithm 使用Prim算法查找最小生成树
    static <V> Set<Edge<V>>
    prim(Graph<V> graph, V start)
    Find minimum spanning tree using Prim's algorithm starting from a vertex 使用Prim算法从指定顶点开始查找最小生成树
    static <V> Graph<V>
    reverse(Graph<V> graph)
    Reverse a directed graph 反转有向图
    static <V> List<V>
    shortestPath(Graph<V> graph, V source, V target)
    Find shortest path between two vertices 查找两个顶点之间的最短路径
    static <V> Graph<V>
    snapshot(Graph<V> graph)
    Create an immutable snapshot of a graph 创建图的不可变快照
    static <V> List<Set<V>>
    Find all strongly connected components (Tarjan's algorithm) 查找所有强连通分量(Tarjan算法)
    summary(Graph<V> graph)
    Get graph summary with all key metrics 获取包含所有关键指标的图摘要
    static <V> List<V>
    Topological sort using Kahn's algorithm 使用Kahn算法进行拓扑排序
    static <V> Graph<V>
    Compute transitive closure of DAG 计算DAG的传递闭包
    static <V> Graph<V>
    Compute transitive reduction of DAG 计算DAG的传递归约
    static <V> Graph<V>
    Create an undirected graph 创建无向图
    static <V> GraphBuilder<V>
    Create a graph builder for undirected graph 创建无向图构建器
    static <V> WeightedGraph<V>
    Create an undirected weighted graph 创建无向加权图

    Methods inherited from class Object

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

    • directed

      public static <V> Graph<V> directed()
      Create a directed graph 创建有向图
      Type Parameters:
      V - the vertex type | 顶点类型
      Returns:
      a new directed graph | 新的有向图
    • undirected

      public static <V> Graph<V> undirected()
      Create an undirected graph 创建无向图
      Type Parameters:
      V - the vertex type | 顶点类型
      Returns:
      a new undirected graph | 新的无向图
    • directedWeighted

      public static <V> WeightedGraph<V> directedWeighted()
      Create a directed weighted graph 创建有向加权图
      Type Parameters:
      V - the vertex type | 顶点类型
      Returns:
      a new directed weighted graph | 新的有向加权图
    • undirectedWeighted

      public static <V> WeightedGraph<V> undirectedWeighted()
      Create an undirected weighted graph 创建无向加权图
      Type Parameters:
      V - the vertex type | 顶点类型
      Returns:
      a new undirected weighted graph | 新的无向加权图
    • directedBuilder

      public static <V> GraphBuilder<V> directedBuilder()
      Create a graph builder for directed graph 创建有向图构建器
      Type Parameters:
      V - the vertex type | 顶点类型
      Returns:
      a new graph builder | 新的图构建器
    • undirectedBuilder

      public static <V> GraphBuilder<V> undirectedBuilder()
      Create a graph builder for undirected graph 创建无向图构建器
      Type Parameters:
      V - the vertex type | 顶点类型
      Returns:
      a new graph builder | 新的图构建器
    • bfs

      public static <V> List<V> bfs(Graph<V> graph, V start)
      Breadth-first search 广度优先搜索
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph to traverse | 要遍历的图
      start - the starting vertex | 起始顶点
      Returns:
      list of vertices in BFS order | BFS顺序的顶点列表
    • dfs

      public static <V> List<V> dfs(Graph<V> graph, V start)
      Depth-first search 深度优先搜索
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph to traverse | 要遍历的图
      start - the starting vertex | 起始顶点
      Returns:
      list of vertices in DFS order | DFS顺序的顶点列表
    • dfsIterative

      public static <V> List<V> dfsIterative(Graph<V> graph, V start)
      Safe iterative depth-first search (avoids stack overflow) 安全的迭代式深度优先搜索(避免栈溢出)
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph to traverse | 要遍历的图
      start - the starting vertex | 起始顶点
      Returns:
      list of vertices in DFS order | DFS顺序的顶点列表
    • dijkstra

      public static <V> Map<V,Double> dijkstra(Graph<V> graph, V source)
      Dijkstra's shortest path algorithm Dijkstra最短路径算法
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      source - the source vertex | 源顶点
      Returns:
      map of vertex to shortest distance from source | 顶点到源的最短距离映射
    • shortestPath

      public static <V> List<V> shortestPath(Graph<V> graph, V source, V target)
      Find shortest path between two vertices 查找两个顶点之间的最短路径
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      source - the source vertex | 源顶点
      target - the target vertex | 目标顶点
      Returns:
      list of vertices in the shortest path | 最短路径的顶点列表
    • aStar

      public static <V> List<V> aStar(Graph<V> graph, V source, V target, BiFunction<V,V,Double> heuristic)
      Find shortest path using A* algorithm 使用A*算法查找最短路径
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      source - the source vertex | 源顶点
      target - the target vertex | 目标顶点
      heuristic - the heuristic function | 启发式函数
      Returns:
      list of vertices in the shortest path | 最短路径的顶点列表
    • bidirectionalBfs

      public static <V> List<V> bidirectionalBfs(Graph<V> graph, V source, V target)
      Find path using bidirectional BFS (efficient for large graphs) 使用双向BFS查找路径(对大图高效)
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      source - the source vertex | 源顶点
      target - the target vertex | 目标顶点
      Returns:
      list of vertices in the path | 路径的顶点列表
    • topologicalSort

      public static <V> List<V> topologicalSort(Graph<V> graph)
      Topological sort using Kahn's algorithm 使用Kahn算法进行拓扑排序
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the directed graph | 有向图
      Returns:
      list of vertices in topological order | 拓扑顺序的顶点列表
    • canTopologicalSort

      public static <V> boolean canTopologicalSort(Graph<V> graph)
      Check if topological sort is possible (graph is DAG) 检查是否可以进行拓扑排序(图是DAG)
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      true if topological sort is possible | 如果可以进行拓扑排序返回true
    • hasCycle

      public static <V> boolean hasCycle(Graph<V> graph)
      Check if graph contains a cycle 检查图是否包含环
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      true if graph contains a cycle | 如果图包含环返回true
    • findCycle

      public static <V> List<V> findCycle(Graph<V> graph)
      Find one cycle if exists 如果存在则找到一个环
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      list of vertices forming a cycle | 形成环的顶点列表
    • connectedComponents

      public static <V> List<Set<V>> connectedComponents(Graph<V> graph)
      Find all connected components 查找所有连通分量
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      list of connected components | 连通分量列表
    • isConnected

      public static <V> boolean isConnected(Graph<V> graph, V v1, V v2)
      Check if two vertices are connected 检查两个顶点是否连通
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      v1 - first vertex | 第一个顶点
      v2 - second vertex | 第二个顶点
      Returns:
      true if connected | 如果连通返回true
    • isFullyConnected

      public static <V> boolean isFullyConnected(Graph<V> graph)
      Check if graph is fully connected 检查图是否完全连通
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      true if fully connected | 如果完全连通返回true
    • connectedComponentCount

      public static <V> int connectedComponentCount(Graph<V> graph)
      Get the number of connected components 获取连通分量数量
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      number of connected components | 连通分量数量
    • prim

      public static <V> Set<Edge<V>> prim(Graph<V> graph)
      Find minimum spanning tree using Prim's algorithm 使用Prim算法查找最小生成树
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the undirected graph | 无向图
      Returns:
      set of edges in the MST | 最小生成树的边集合
    • prim

      public static <V> Set<Edge<V>> prim(Graph<V> graph, V start)
      Find minimum spanning tree using Prim's algorithm starting from a vertex 使用Prim算法从指定顶点开始查找最小生成树
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the undirected graph | 无向图
      start - the starting vertex | 起始顶点
      Returns:
      set of edges in the MST | 最小生成树的边集合
    • kruskal

      public static <V> Set<Edge<V>> kruskal(Graph<V> graph)
      Find minimum spanning tree using Kruskal's algorithm 使用Kruskal算法查找最小生成树
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the undirected graph | 无向图
      Returns:
      set of edges in the MST | 最小生成树的边集合
    • mstWeight

      public static <V> double mstWeight(Graph<V> graph)
      Calculate the total weight of the minimum spanning tree 计算最小生成树的总权重
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the undirected graph | 无向图
      Returns:
      total weight of MST | 最小生成树的总权重
    • hasSpanningTree

      public static <V> boolean hasSpanningTree(Graph<V> graph)
      Check if a graph has a spanning tree (is connected) 检查图是否有生成树(是否连通)
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      true if graph is connected | 如果图连通返回true
    • maxFlow

      public static <V> double maxFlow(Graph<V> graph, V source, V sink)
      Calculate maximum flow using Ford-Fulkerson algorithm (Edmonds-Karp) 使用Ford-Fulkerson算法(Edmonds-Karp)计算最大流
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the directed graph with edge weights as capacities | 边权重作为容量的有向图
      source - the source vertex | 源顶点
      sink - the sink vertex | 汇顶点
      Returns:
      the maximum flow value | 最大流值
    • getFlows

      public static <V> Map<Edge<V>,Double> getFlows(Graph<V> graph, V source, V sink)
      Get flow on each edge 获取每条边上的流量
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the directed graph | 有向图
      source - the source vertex | 源顶点
      sink - the sink vertex | 汇顶点
      Returns:
      map of edge to flow value | 边到流量值的映射
    • minCut

      public static <V> Set<Edge<V>> minCut(Graph<V> graph, V source, V sink)
      Find minimum cut edges 查找最小割边
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the directed graph | 有向图
      source - the source vertex | 源顶点
      sink - the sink vertex | 汇顶点
      Returns:
      set of edges in the minimum cut | 最小割中的边集合
    • computeFlow

      public static <V> NetworkFlowUtil.FlowResult<V> computeFlow(Graph<V> graph, V source, V sink)
      Compute flow result with detailed information 计算包含详细信息的流结果
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the directed graph | 有向图
      source - the source vertex | 源顶点
      sink - the sink vertex | 汇顶点
      Returns:
      the flow result with max flow, edge flows, and min-cut | 包含最大流、边流量和最小割的流结果
    • bellmanFord

      public static <V> Map<V,Double> bellmanFord(Graph<V> graph, V source)
      Bellman-Ford single-source shortest paths (supports negative weights) Bellman-Ford单源最短路径(支持负权边)
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      source - the source vertex | 源顶点
      Returns:
      map of vertex to shortest distance | 顶点到最短距离的映射
    • hasNegativeCycle

      public static <V> boolean hasNegativeCycle(Graph<V> graph, V source)
      Check for negative weight cycle reachable from source 检查从源顶点可达的负权环
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      source - the source vertex | 源顶点
      Returns:
      true if negative cycle exists | 如果存在负权环返回true
    • allPairsShortestPaths

      public static <V> FloydWarshallUtil.AllPairsResult<V> allPairsShortestPaths(Graph<V> graph)
      Floyd-Warshall all-pairs shortest paths Floyd-Warshall全源最短路径
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      all-pairs shortest path result | 全源最短路径结果
    • stronglyConnectedComponents

      public static <V> List<Set<V>> stronglyConnectedComponents(Graph<V> graph)
      Find all strongly connected components (Tarjan's algorithm) 查找所有强连通分量(Tarjan算法)
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the directed graph | 有向图
      Returns:
      list of SCCs | 强连通分量列表
    • isStronglyConnected

      public static <V> boolean isStronglyConnected(Graph<V> graph)
      Check if graph is strongly connected 检查图是否强连通
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      true if strongly connected | 如果强连通返回true
    • condensation

      public static <V> Graph<Set<V>> condensation(Graph<V> graph)
      Get condensation graph (DAG of SCCs) 获取冷凝图(强连通分量的DAG)
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the directed graph | 有向图
      Returns:
      condensation graph | 冷凝图
    • articulationPoints

      public static <V> Set<V> articulationPoints(Graph<V> graph)
      Find all articulation points (cut vertices) 查找所有关节点(割点)
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      set of articulation points | 关节点集合
    • bridges

      public static <V> Set<Edge<V>> bridges(Graph<V> graph)
      Find all bridges (cut edges) 查找所有桥(割边)
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      set of bridge edges | 桥边集合
    • isBiconnected

      public static <V> boolean isBiconnected(Graph<V> graph)
      Check if graph is biconnected 检查图是否双连通
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      true if biconnected | 如果双连通返回true
    • isBipartite

      public static <V> boolean isBipartite(Graph<V> graph)
      Check if graph is bipartite 检查图是否为二部图
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      true if bipartite | 如果是二部图返回true
    • bipartitePartition

      public static <V> BipartiteUtil.BipartiteResult<V> bipartitePartition(Graph<V> graph)
      Compute bipartite partition or odd cycle witness 计算二部图分区或奇环证据
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      bipartite result | 二部图结果
    • longestPath

      public static <V> List<V> longestPath(Graph<V> graph)
      Find longest path in DAG (critical path) 查找DAG中的最长路径(关键路径)
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the DAG | 有向无环图
      Returns:
      list of vertices in the longest path | 最长路径的顶点列表
    • transitiveReduction

      public static <V> Graph<V> transitiveReduction(Graph<V> graph)
      Compute transitive reduction of DAG 计算DAG的传递归约
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the DAG | 有向无环图
      Returns:
      reduced graph | 归约后的图
    • transitiveClosure

      public static <V> Graph<V> transitiveClosure(Graph<V> graph)
      Compute transitive closure of DAG 计算DAG的传递闭包
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the DAG | 有向无环图
      Returns:
      closure graph | 闭包图
    • density

      public static <V> double density(Graph<V> graph)
      Get graph density 获取图密度
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      density value between 0 and 1 | 密度值,0到1之间
    • diameter

      public static <V> int diameter(Graph<V> graph)
      Get graph diameter 获取图直径
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      diameter | 直径
    • summary

      public static <V> GraphMetrics.GraphSummary summary(Graph<V> graph)
      Get graph summary with all key metrics 获取包含所有关键指标的图摘要
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      graph summary | 图摘要
    • diff

      public static <V> GraphDiff.DiffResult<V> diff(Graph<V> before, Graph<V> after)
      Compare two graphs and get differences 比较两个图并获取差异
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      before - the original graph | 原始图
      after - the modified graph | 修改后的图
      Returns:
      diff result | 差异结果
    • mapVertices

      public static <V,R> Graph<R> mapVertices(Graph<V> graph, Function<V,R> mapper)
      Transform graph vertices using mapping function 使用映射函数转换图顶点
      Type Parameters:
      V - the source vertex type | 源顶点类型
      R - the target vertex type | 目标顶点类型
      Parameters:
      graph - the graph | 图
      mapper - the mapping function | 映射函数
      Returns:
      transformed graph | 转换后的图
    • reverse

      public static <V> Graph<V> reverse(Graph<V> graph)
      Reverse a directed graph 反转有向图
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      reversed graph | 反转后的图
    • filterVertices

      public static <V> Graph<V> filterVertices(Graph<V> graph, Predicate<V> predicate)
      Filter vertices from a graph by predicate 按谓词过滤图的顶点
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the source graph | 源图
      predicate - the vertex filter predicate | 顶点过滤谓词
      Returns:
      a new graph containing only vertices matching the predicate | 仅包含匹配谓词的顶点的新图
    • filterEdges

      public static <V> Graph<V> filterEdges(Graph<V> graph, Predicate<Edge<V>> predicate)
      Filter edges from a graph by predicate 按谓词过滤图的边
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the source graph | 源图
      predicate - the edge filter predicate | 边过滤谓词
      Returns:
      a new graph containing only edges matching the predicate | 仅包含匹配谓词的边的新图
    • snapshot

      public static <V> Graph<V> snapshot(Graph<V> graph)
      Create an immutable snapshot of a graph 创建图的不可变快照
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      graph - the graph | 图
      Returns:
      immutable graph snapshot | 不可变图快照