pub struct Graph {
pub name: String,
pub graph_type: GraphType,
pub nodes: HashMap<NodeId, GraphNode>,
pub edges: HashMap<EdgeId, GraphEdge>,
pub adjacency: HashMap<NodeId, Vec<EdgeId>>,
pub reverse_adjacency: HashMap<NodeId, Vec<EdgeId>>,
pub nodes_by_type: HashMap<NodeType, Vec<NodeId>>,
pub edges_by_type: HashMap<EdgeType, Vec<EdgeId>>,
pub metadata: GraphMetadata,
/* private fields */
}Expand description
A graph containing nodes and edges.
Fields§
§name: StringGraph name.
graph_type: GraphTypeGraph type.
nodes: HashMap<NodeId, GraphNode>Nodes indexed by ID.
edges: HashMap<EdgeId, GraphEdge>Edges indexed by ID.
adjacency: HashMap<NodeId, Vec<EdgeId>>Adjacency list (node -> outgoing edges).
reverse_adjacency: HashMap<NodeId, Vec<EdgeId>>Reverse adjacency (node -> incoming edges).
nodes_by_type: HashMap<NodeType, Vec<NodeId>>Node type index.
edges_by_type: HashMap<EdgeType, Vec<EdgeId>>Edge type index.
metadata: GraphMetadataMetadata.
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn add_node(&mut self, node: GraphNode) -> NodeId
pub fn add_node(&mut self, node: GraphNode) -> NodeId
Adds a node to the graph, returning its ID.
Sourcepub fn add_edge(&mut self, edge: GraphEdge) -> EdgeId
pub fn add_edge(&mut self, edge: GraphEdge) -> EdgeId
Adds an edge to the graph, returning its ID.
Sourcepub fn get_node_mut(&mut self, id: NodeId) -> Option<&mut GraphNode>
pub fn get_node_mut(&mut self, id: NodeId) -> Option<&mut GraphNode>
Gets a mutable node by ID.
Sourcepub fn get_edge_mut(&mut self, id: EdgeId) -> Option<&mut GraphEdge>
pub fn get_edge_mut(&mut self, id: EdgeId) -> Option<&mut GraphEdge>
Gets a mutable edge by ID.
Sourcepub fn nodes_of_type(&self, node_type: &NodeType) -> Vec<&GraphNode>
pub fn nodes_of_type(&self, node_type: &NodeType) -> Vec<&GraphNode>
Returns all nodes of a given type.
Sourcepub fn edges_of_type(&self, edge_type: &EdgeType) -> Vec<&GraphEdge>
pub fn edges_of_type(&self, edge_type: &EdgeType) -> Vec<&GraphEdge>
Returns all edges of a given type.
Sourcepub fn outgoing_edges(&self, node_id: NodeId) -> Vec<&GraphEdge>
pub fn outgoing_edges(&self, node_id: NodeId) -> Vec<&GraphEdge>
Returns outgoing edges from a node.
Sourcepub fn incoming_edges(&self, node_id: NodeId) -> Vec<&GraphEdge>
pub fn incoming_edges(&self, node_id: NodeId) -> Vec<&GraphEdge>
Returns incoming edges to a node.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Returns the number of nodes.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Returns the number of edges.
Sourcepub fn out_degree(&self, node_id: NodeId) -> usize
pub fn out_degree(&self, node_id: NodeId) -> usize
Returns the out-degree of a node.
Sourcepub fn anomalous_nodes(&self) -> Vec<&GraphNode>
pub fn anomalous_nodes(&self) -> Vec<&GraphNode>
Returns anomalous nodes.
Sourcepub fn anomalous_edges(&self) -> Vec<&GraphEdge>
pub fn anomalous_edges(&self) -> Vec<&GraphEdge>
Returns anomalous edges.
Sourcepub fn compute_statistics(&mut self)
pub fn compute_statistics(&mut self)
Computes graph statistics.
Sourcepub fn edge_index(&self) -> (Vec<NodeId>, Vec<NodeId>)
pub fn edge_index(&self) -> (Vec<NodeId>, Vec<NodeId>)
Returns the edge index as a pair of vectors (source_ids, target_ids).
Sourcepub fn node_features(&self) -> Vec<Vec<f64>>
pub fn node_features(&self) -> Vec<Vec<f64>>
Returns the node feature matrix (nodes x features).
Sourcepub fn edge_features(&self) -> Vec<Vec<f64>>
pub fn edge_features(&self) -> Vec<Vec<f64>>
Returns the edge feature matrix (edges x features).
Sourcepub fn node_labels(&self) -> Vec<Vec<String>>
pub fn node_labels(&self) -> Vec<Vec<String>>
Returns node labels.
Sourcepub fn edge_labels(&self) -> Vec<Vec<String>>
pub fn edge_labels(&self) -> Vec<Vec<String>>
Returns edge labels.
Sourcepub fn node_anomaly_mask(&self) -> Vec<bool>
pub fn node_anomaly_mask(&self) -> Vec<bool>
Returns node anomaly flags.
Sourcepub fn edge_anomaly_mask(&self) -> Vec<bool>
pub fn edge_anomaly_mask(&self) -> Vec<bool>
Returns edge anomaly flags.