pub struct CategoryGraph<N: Clone, E: Clone> {
    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: Clone, E: Clone> CategoryGraph<N, E>

source

pub fn new() -> Self

Trait Implementations§

source§

impl<N: Clone + Default, E: Clone + Default> Categorized<N, E, N> for CategoryGraph<N, E>
where Self: GraphWriter<N, 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>

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) -> Option<&Node<N>>

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 add_to_category_by_id( &mut self, category_id: NodeID, nodes: Vec<NodeID> ) -> Result<(), CategoryGraphError>

Adds a list of nodes to a category by ID. Returns Ok(()) if successful, otherwise returns Error(CategoryGraphError::CategoryNotFound).
source§

fn add_to_category(&mut self, category_name: &str, nodes: Vec<NodeID>) -> NodeID

If the category does not exist, it is created. Returns the NodeID of the category.
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: Clone + Clone, E: Clone + Clone> Clone for CategoryGraph<N, E>

source§

fn clone(&self) -> CategoryGraph<N, E>

Returns a copy 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<N: Debug + Clone, E: Debug + Clone> Debug for CategoryGraph<N, E>

source§

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

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

impl<N: Clone, E: Clone> SlotMapGraph<N, E> for CategoryGraph<N, E>

source§

fn nodes(&self) -> &SlotMap<NodeID, Node<N>>

source§

fn nodes_mut(&mut self) -> &mut SlotMap<NodeID, Node<N>>

source§

fn edges(&self) -> &SlotMap<EdgeID, Edge<E>>

source§

fn edges_mut(&mut self) -> &mut SlotMap<EdgeID, Edge<E>>

source§

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

source§

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

source§

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

source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<N, E> UnwindSafe for CategoryGraph<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, N, E> GraphWriter<N, E> for T
where T: SlotMapGraph<N, E> + ?Sized, N: Clone, E: Clone,

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) -> &Node<N>

source§

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

source§

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

source§

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

source§

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

source§

fn add_edges_with_data(&mut self, data: &[(NodeID, NodeID, E)]) -> Vec<EdgeID>

source§

fn add_nodes_and_edges( &mut self, data: Vec<(N, Vec<NodeID>)> ) -> (Vec<NodeID>, Vec<EdgeID>)
where E: Default,

source§

fn add_nodes_and_edges_with_data( &mut self, node_data: Vec<(N, Vec<(NodeID, E)>)> ) -> (Vec<NodeID>, Vec<EdgeID>)

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,

§

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

§

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.