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.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Graph
impl<'de> Deserialize<'de> for Graph
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Graph
impl RefUnwindSafe for Graph
impl Send for Graph
impl Sync for Graph
impl Unpin for Graph
impl UnsafeUnpin for Graph
impl UnwindSafe for Graph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.