Skip to main content

Graph

Struct Graph 

Source
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: String

Graph name.

§graph_type: GraphType

Graph 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: GraphMetadata

Metadata.

Implementations§

Source§

impl Graph

Source

pub fn new(name: &str, graph_type: GraphType) -> Self

Creates a new graph.

Source

pub fn add_node(&mut self, node: GraphNode) -> NodeId

Adds a node to the graph, returning its ID.

Source

pub fn add_edge(&mut self, edge: GraphEdge) -> EdgeId

Adds an edge to the graph, returning its ID.

Source

pub fn get_node(&self, id: NodeId) -> Option<&GraphNode>

Gets a node by ID.

Source

pub fn get_node_mut(&mut self, id: NodeId) -> Option<&mut GraphNode>

Gets a mutable node by ID.

Source

pub fn get_edge(&self, id: EdgeId) -> Option<&GraphEdge>

Gets an edge by ID.

Source

pub fn get_edge_mut(&mut self, id: EdgeId) -> Option<&mut GraphEdge>

Gets a mutable edge by ID.

Source

pub fn nodes_of_type(&self, node_type: &NodeType) -> Vec<&GraphNode>

Returns all nodes of a given type.

Source

pub fn edges_of_type(&self, edge_type: &EdgeType) -> Vec<&GraphEdge>

Returns all edges of a given type.

Source

pub fn outgoing_edges(&self, node_id: NodeId) -> Vec<&GraphEdge>

Returns outgoing edges from a node.

Source

pub fn incoming_edges(&self, node_id: NodeId) -> Vec<&GraphEdge>

Returns incoming edges to a node.

Source

pub fn neighbors(&self, node_id: NodeId) -> Vec<NodeId>

Returns neighbors of a node.

Source

pub fn node_count(&self) -> usize

Returns the number of nodes.

Source

pub fn edge_count(&self) -> usize

Returns the number of edges.

Source

pub fn out_degree(&self, node_id: NodeId) -> usize

Returns the out-degree of a node.

Source

pub fn in_degree(&self, node_id: NodeId) -> usize

Returns the in-degree of a node.

Source

pub fn degree(&self, node_id: NodeId) -> usize

Returns the total degree of a node.

Source

pub fn anomalous_nodes(&self) -> Vec<&GraphNode>

Returns anomalous nodes.

Source

pub fn anomalous_edges(&self) -> Vec<&GraphEdge>

Returns anomalous edges.

Source

pub fn compute_statistics(&mut self)

Computes graph statistics.

Source

pub fn edge_index(&self) -> (Vec<NodeId>, Vec<NodeId>)

Returns the edge index as a pair of vectors (source_ids, target_ids).

Source

pub fn node_features(&self) -> Vec<Vec<f64>>

Returns the node feature matrix (nodes x features).

Source

pub fn edge_features(&self) -> Vec<Vec<f64>>

Returns the edge feature matrix (edges x features).

Source

pub fn node_labels(&self) -> Vec<Vec<String>>

Returns node labels.

Source

pub fn edge_labels(&self) -> Vec<Vec<String>>

Returns edge labels.

Source

pub fn node_anomaly_mask(&self) -> Vec<bool>

Returns node anomaly flags.

Source

pub fn edge_anomaly_mask(&self) -> Vec<bool>

Returns edge anomaly flags.

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Graph

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Graph

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Graph

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnwindSafe for Graph

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,