Class SafeGraphTraversalUtil
java.lang.Object
cloud.opencode.base.graph.algorithm.SafeGraphTraversalUtil
Safe Graph Traversal Util
安全图遍历工具类
Iterative implementations of graph traversal to avoid stack overflow.
图遍历的迭代实现,避免栈溢出。
Features | 特性:
- Iterative DFS (no recursion) | 迭代式DFS(无递归)
- Depth-limited traversal | 深度限制遍历
- Suitable for large graphs | 适用于大图
Usage Examples | 使用示例:
// Iterative DFS for large graphs
List<String> result = SafeGraphTraversalUtil.dfsIterative(graph, "A");
// Depth-limited DFS
List<String> limited = SafeGraphTraversalUtil.dfsWithLimit(graph, "A", 100);
Security | 安全性:
- Thread-safe: Yes (stateless utility class) - 线程安全: 是(无状态工具类)
- Null-safe: Yes (returns empty results for null inputs) - 空值安全: 是(null输入返回空结果)
Performance | 性能特性:
- Time complexity: O(V + E) - 时间复杂度: O(V + E)
- Space complexity: O(V) - 空间复杂度: O(V)
- Since:
- JDK 25, opencode-base-graph V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <V> List<V> bfsWithLimit(Graph<V> graph, V start, int maxDistance) BFS with maximum distance limit 带最大距离限制的BFSstatic <V> List<V> dfsIterative(Graph<V> graph, V start) Iterative Depth-First Search (avoids stack overflow) 迭代式深度优先搜索(避免栈溢出)static <V> voiddfsIterative(Graph<V> graph, V start, Consumer<V> visitor) Iterative DFS with visitor 带访问器的迭代式DFSstatic <V> List<V> dfsIterativeWithLimit(Graph<V> graph, V start, int maxDepth) Iterative depth-limited DFS 迭代式深度限制DFSstatic <V> List<V> dfsWithLimit(Graph<V> graph, V start, int maxDepth) Depth-limited DFS 深度限制的DFS
-
Method Details
-
dfsIterative
-
dfsIterative
-
dfsWithLimit
Depth-limited DFS 深度限制的DFS- Type Parameters:
V- the vertex type | 顶点类型- Parameters:
graph- the graph | 图start- the starting vertex | 起始顶点maxDepth- maximum depth to traverse | 最大遍历深度- Returns:
- list of vertices within depth limit | 深度限制内的顶点列表
-
dfsIterativeWithLimit
Iterative depth-limited DFS 迭代式深度限制DFS- Type Parameters:
V- the vertex type | 顶点类型- Parameters:
graph- the graph | 图start- the starting vertex | 起始顶点maxDepth- maximum depth to traverse | 最大遍历深度- Returns:
- list of vertices within depth limit | 深度限制内的顶点列表
-
bfsWithLimit
BFS with maximum distance limit 带最大距离限制的BFS- Type Parameters:
V- the vertex type | 顶点类型- Parameters:
graph- the graph | 图start- the starting vertex | 起始顶点maxDistance- maximum distance from start | 距起始点的最大距离- Returns:
- list of vertices within distance limit | 距离限制内的顶点列表
-