Skip to main content

GraphData

Struct GraphData 

Source
pub struct GraphData {
    pub graph: DiGraph<Node, Edge>,
    pub node_indices: HashMap<String, NodeIndex>,
    pub nodes: HashMap<String, Node>,
    pub edges: Vec<Edge>,
}
Expand description

Core graph data structure.

Wraps a petgraph DiGraph with lookup tables for efficient access. Supports runtime mutation (add/remove nodes and edges) without full rebuild.

Fields§

§graph: DiGraph<Node, Edge>

The underlying directed graph.

§node_indices: HashMap<String, NodeIndex>

Lookup table: node ID → petgraph NodeIndex.

§nodes: HashMap<String, Node>

Lookup table: node ID → Node data.

§edges: Vec<Edge>

All edges as a flat list (for serialization).

Implementations§

Source§

impl GraphData

Source

pub fn prerequisites(&self, node_id: &str) -> Result<Vec<Node>>

Get direct prerequisites of a node (incoming Prerequisite edges).

Source

pub fn dependents(&self, node_id: &str) -> Result<Vec<Node>>

Get nodes that depend on this node (outgoing Prerequisite edges pointing here).

Source

pub fn related_by( &self, node_id: &str, relationship: &Relationship, ) -> Result<Vec<Node>>

Get nodes related by a specific relationship type (outgoing direction).

Source§

impl GraphData

Source

pub fn new() -> Self

Creates an empty graph.

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 get_node(&self, id: &str) -> Option<&Node>

Gets a node by ID.

Source

pub fn get_index(&self, id: &str) -> Option<NodeIndex>

Gets the petgraph NodeIndex for a node ID.

Source

pub fn contains_node(&self, id: &str) -> bool

Checks if a node exists.

Source

pub fn node_ids(&self) -> impl Iterator<Item = &str>

Returns an iterator over all node IDs.

Source

pub fn iter_nodes(&self) -> impl Iterator<Item = &Node>

Returns an iterator over all nodes.

Source

pub fn iter_edges(&self) -> impl Iterator<Item = &Edge>

Returns an iterator over all edges.

Source

pub fn add_node(&mut self, node: Node) -> NodeIndex

Add a node to the graph at runtime.

Returns the NodeIndex for the newly added node. If a node with the same ID already exists, returns its existing index.

Source

pub fn add_edge(&mut self, edge: Edge) -> Result<()>

Add an edge between two nodes identified by ID.

Both nodes must already exist in the graph. Returns Ok(()) on success, or an error if a node is missing.

Source

pub fn remove_node(&mut self, id: &str) -> Option<Node>

Remove a node and all its connected edges.

Returns the removed node, or None if the node didn’t exist.

Trait Implementations§

Source§

impl Clone for GraphData

Source§

fn clone(&self) -> GraphData

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 GraphData

Source§

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

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

impl Default for GraphData

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.