pub struct CategorizedGraph<N, E> {
    pub nodes: SlotMap<NodeID, Node<N>>,
    pub edges: SlotMap<EdgeID, Edge<E>>,
    pub categories: HashMap<String, NodeID>,
}
Expand description

A graph with category nodes (where the nodes contain an ID of the category and a list of nodes in that category) and a hash map that maps category names to category nodes efficiently.

Fields§

§nodes: SlotMap<NodeID, Node<N>>§edges: SlotMap<EdgeID, Edge<E>>§categories: HashMap<String, NodeID>

Implementations§

source§

impl<N, E> CategorizedGraph<N, E>

source

pub fn new() -> Self

Trait Implementations§

source§

impl<N, E> Categorized<N, E, N> for CategorizedGraph<N, E>
where Self: GraphInterface<NodeData = N, EdgeData = E>,

source§

fn category_id_by_name(&self, category_name: &str) -> Option<&NodeID>

Returns the category ID by name. In the standard implementation this is a hashmap lookup.
source§

fn insert_category_id_by_name( &mut self, category_name: &str, category_id: NodeID )

In the default implementation this is used to insert the category ID into the hashmap.
source§

fn create_category( &mut self, category: &str, nodes: Vec<NodeID>, data: N ) -> Result<NodeID, String>
where E: Default + Clone, N: Clone + Default,

Creates a new category Node with the given name, nodes, and (optionally) data. Read more
source§

fn all_categories(&self) -> Vec<(&String, NodeID)>

Returns a list of all categories.
source§

fn category(&self, category: &str) -> Option<&Node<N>>

Returns the category node by name.
source§

fn category_by_id(&self, category: NodeID) -> Result<&Node<N>, GraphError>

Returns the category node by ID.
source§

fn nodes_by_category_id(&self, category: NodeID) -> Vec<NodeID>

Returns a list of nodes in the category by ID.
source§

fn nodes_by_category(&self, category: &str) -> Vec<NodeID>

Returns a list of nodes in the category by name.
source§

fn category_exists(&self, category_name: &str) -> bool

Checks if the category exists by name.
source§

fn category_exists_by_id(&self, category: NodeID) -> bool

Checks if the category exists by ID.
source§

fn nodes_by_categories(&self, categories: Vec<&str>) -> Vec<NodeID>

Returns a list of nodes in the categories by name.
source§

fn nodes_by_category_ids(&self, categories: Vec<NodeID>) -> Vec<NodeID>

Returns a list of nodes in the categories by ID.
source§

impl<N: Debug, E: Debug> Debug for CategorizedGraph<N, E>

source§

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

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

impl<N, E> GraphInterface for CategorizedGraph<N, E>

§

type NodeData = N

§

type EdgeData = E

source§

fn nodes(&self) -> impl Iterator<Item = NodeID>

source§

fn node_count(&self) -> usize

source§

fn remove_node(&mut self, id: NodeID) -> Result<(), GraphError>

source§

fn remove_edge(&mut self, id: EdgeID) -> Result<(), GraphError>

source§

fn add_node(&mut self, data: N) -> NodeID

source§

fn add_nodes(&mut self, data: &[N]) -> Vec<NodeID>
where N: Clone,

source§

fn add_edges(&mut self, data: &[(NodeID, NodeID)]) -> Vec<EdgeID>
where E: Default + Clone, N: Clone,

source§

fn add_edge(&mut self, from: NodeID, to: NodeID, data: E) -> EdgeID

source§

fn node(&self, id: NodeID) -> Result<&Node<N>, GraphError>

source§

fn node_mut(&mut self, id: NodeID) -> Result<&mut Node<N>, GraphError>

source§

fn edge(&self, id: EdgeID) -> Result<&Edge<E>, GraphError>

source§

fn edge_mut(&mut self, id: EdgeID) -> Result<&mut Edge<E>, GraphError>

source§

fn remove_nodes(&mut self, ids: &[NodeID]) -> Result<(), GraphError>

Auto Trait Implementations§

§

impl<N, E> Freeze for CategorizedGraph<N, E>

§

impl<N, E> RefUnwindSafe for CategorizedGraph<N, E>

§

impl<N, E> Send for CategorizedGraph<N, E>
where N: Send, E: Send,

§

impl<N, E> Sync for CategorizedGraph<N, E>
where N: Sync, E: Sync,

§

impl<N, E> Unpin for CategorizedGraph<N, E>
where N: Unpin, E: Unpin,

§

impl<N, E> UnwindSafe for CategorizedGraph<N, E>
where N: UnwindSafe, E: UnwindSafe,

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> 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<'a, G> IterDepthFirst<'a, G> for G
where G: GraphInterface,

source§

fn connected_components(&'a self) -> Vec<HashSet<NodeID>>

Returns a vector of sets of node IDs, where each set is a connected component.
Starts a DFS at every node (except if it’s already been visited) and marks all reachable nodes as being part of the same component.

source§

fn iter_depth_first(&'a self, start: NodeID) -> DepthFirstSearch<'a, G>

Returns a depth first search iterator starting from a given node
source§

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

§

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>,

§

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.