Interface MutableValueGraph<N,V>
- Type Parameters:
N- node type | 节点类型V- edge value type | 边值类型
- All Superinterfaces:
ValueGraph<N,V>
MutableValueGraph - Mutable Value Graph Interface and Implementation
MutableValueGraph - 可变值图接口与实现
A mutable graph where edges have associated values (weights). Supports both directed and undirected graphs.
边带有关联值(权重)的可变图。支持有向图和无向图。
Features | 主要功能:
- Add/remove nodes - 添加/移除节点
- Add/remove weighted edges - 添加/移除带权边
- Directed/undirected support - 有向/无向支持
- Edge value queries - 边值查询
Usage Examples | 使用示例:
// Create directed value graph - 创建有向值图
MutableValueGraph<String, Double> directed = MutableValueGraph.directed();
directed.putEdgeValue("A", "B", 1.5);
directed.putEdgeValue("B", "C", 2.0);
Optional<Double> weight = directed.edgeValue("A", "B"); // Optional[1.5]
// Create undirected value graph - 创建无向值图
MutableValueGraph<String, Integer> undirected = MutableValueGraph.undirected();
undirected.putEdgeValue("X", "Y", 10);
// Both directions queryable - 双向可查
undirected.edgeValue("Y", "X"); // Optional[10]
Performance | 性能特性:
- addNode: O(1) - addNode: O(1)
- putEdgeValue: O(1) - putEdgeValue: O(1)
- edgeValue: O(1) - edgeValue: O(1)
- removeNode: O(degree) - removeNode: O(度数)
Security | 安全性:
- Thread-safe: No - 线程安全: 否
- Null-safe: No (nulls not allowed for nodes) - 空值安全: 否(节点不允许空值)
- Since:
- JDK 25, opencode-base-collections V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface ValueGraph
ValueGraph.EndpointPair<N> -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd a node to the graph.static <N,V> MutableValueGraph <N, V> directed()Create a directed mutable value graph.putEdgeValue(N nodeU, N nodeV, V value) Add an edge with a value between two nodes, adding nodes if necessary.removeEdge(N nodeU, N nodeV) Remove the edge between two nodes.booleanremoveNode(N node) Remove a node and all its edges from the graph.static <N,V> MutableValueGraph <N, V> Create an undirected mutable value graph.Methods inherited from interface ValueGraph
adjacentNodes, degree, edgeCount, edges, edgeValue, edgeValueOrDefault, hasEdgeConnecting, isDirected, nodeCount, nodes, predecessors, successors
-
Method Details
-
addNode
Add a node to the graph. 添加节点到图。- Parameters:
node- the node to add | 要添加的节点- Returns:
- true if added (node was not present) | 如果添加成功则返回 true
- Throws:
NullPointerException- if node is null | 如果节点为空则抛出异常
-
putEdgeValue
Add an edge with a value between two nodes, adding nodes if necessary. Returns the previous value associated with the edge, ornullif no edge existed. 添加两个节点之间带值的边,必要时添加节点。 返回之前与该边关联的值,如果不存在则返回null。- Parameters:
nodeU- the source node | 源节点nodeV- the target node | 目标节点value- the edge value | 边值- Returns:
- the previous edge value, or null | 之前的边值或 null
- Throws:
NullPointerException- if any node is null | 如果节点为空则抛出异常
-
removeEdge
-
removeNode
Remove a node and all its edges from the graph. 从图中移除节点及其所有边。- Parameters:
node- the node to remove | 要移除的节点- Returns:
- true if removed | 如果移除成功则返回 true
-
directed
Create a directed mutable value graph. 创建有向可变值图。- Type Parameters:
N- node type | 节点类型V- edge value type | 边值类型- Returns:
- new directed value graph | 新有向值图
-
undirected
Create an undirected mutable value graph. 创建无向可变值图。- Type Parameters:
N- node type | 节点类型V- edge value type | 边值类型- Returns:
- new undirected value graph | 新无向值图
-