Module categories

Module categories 

Source
Expand description

§A graph with category nodes.

The CategorizedGraph struct uses a hash map to map category names (String) to a category node (NodeID) (where the node’s edges are the nodes belonging to the category). There’s also some useful extra functions to query categories and their nodes, and a Categorized trait that can be implemented for a custom struct if needed.

In other words a simple extension to the graph that allows for efficient and easy grouping of nodes by strings.

§Example

use fast_graph::*;

#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
enum NodeData {
    String(String),
    CategoryName(String),
    #[default]
    None,
}

let mut graph: CategorizedGraph<NodeData, ()> = CategorizedGraph::new();

let node1 = graph.add_node(NodeData::String("Node 1".into()));
let node2 = graph.add_node(NodeData::String("Node 2".into()));
let node3 = graph.add_node(NodeData::String("Node 3".into()));

let category1 = graph.create_category("Category 1", vec![node1, node2], NodeData::CategoryName("Category 1".into())).unwrap();
let category2 = graph.add_to_category("Category 2", vec![node3]);

assert_eq!(graph.all_categories().len(), 2);

Structs§

CategorizedGraph
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.

Enums§

CategorizedGraphError

Traits§

Categorized
Methods for a graph with categories.