Interface Graph<N>
- Type Parameters:
N- node type | 节点类型
- All Known Implementing Classes:
MutableGraph
public interface Graph<N>
Graph - Graph Interface
Graph - 图接口
An interface for graph data structures supporting directed and undirected graphs.
支持有向图和无向图的图数据结构接口。
Features | 主要功能:
- Node operations - 节点操作
- Edge operations - 边操作
- Directed/undirected support - 有向/无向支持
- Adjacency queries - 邻接查询
Usage Examples | 使用示例:
Graph<String> graph = MutableGraph.directed();
graph.addNode("A");
graph.addNode("B");
graph.addEdge("A", "B");
Set<String> neighbors = graph.successors("A"); // [B]
boolean hasEdge = graph.hasEdge("A", "B"); // true
Security | 安全性:
- Thread-safe: No (interface, implementation-dependent) - 否(接口,取决于实现)
- Null-safe: No - 否
- Since:
- JDK 25, opencode-base-collections V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceEndpoint pair representing an edge. -
Method Summary
Modifier and TypeMethodDescriptionadjacentNodes(N node) Return all adjacent nodes (both successors and predecessors).booleanCheck if this graph allows self-loops.intReturn the degree of a node (number of edges incident to it).default intReturn the number of edges.edges()Return the set of all edges.booleanCheck if the edge exists.booleanCheck if the node exists.incidentEdges(N node) Return the edges incident to a node.intReturn the in-degree of a node (number of incoming edges).booleanCheck if this graph is directed.default intReturn the number of nodes.nodes()Return the set of all nodes.intReturn the out-degree of a node (number of outgoing edges).predecessors(N node) Return the predecessors (incoming neighbors) of a node.successors(N node) Return the successors (outgoing neighbors) of a node.
-
Method Details
-
isDirected
boolean isDirected()Check if this graph is directed. 检查此图是否有向。- Returns:
- true if directed | 如果有向则返回 true
-
allowsSelfLoops
boolean allowsSelfLoops()Check if this graph allows self-loops. 检查此图是否允许自环。- Returns:
- true if allows self-loops | 如果允许自环则返回 true
-
nodes
-
edges
Set<Graph.EndpointPair<N>> edges()Return the set of all edges. 返回所有边的集合。- Returns:
- the set of edges | 边集合
-
hasNode
Check if the node exists. 检查节点是否存在。- Parameters:
node- the node | 节点- Returns:
- true if exists | 如果存在则返回 true
-
successors
-
predecessors
-
adjacentNodes
-
degree
Return the degree of a node (number of edges incident to it). 返回节点的度数(入射边的数量)。- Parameters:
node- the node | 节点- Returns:
- the degree | 度数
-
inDegree
Return the in-degree of a node (number of incoming edges). 返回节点的入度(入边数量)。- Parameters:
node- the node | 节点- Returns:
- the in-degree | 入度
-
outDegree
Return the out-degree of a node (number of outgoing edges). 返回节点的出度(出边数量)。- Parameters:
node- the node | 节点- Returns:
- the out-degree | 出度
-
hasEdge
-
incidentEdges
Return the edges incident to a node. 返回入射到节点的边。- Parameters:
node- the node | 节点- Returns:
- the set of incident edges | 入射边集合
-
nodeCount
default int nodeCount()Return the number of nodes. 返回节点数量。- Returns:
- the number of nodes | 节点数量
-
edgeCount
default int edgeCount()Return the number of edges. 返回边数量。- Returns:
- the number of edges | 边数量
-