nrc/r4cppp

Not the most obvious way to do graphs

tomshackell opened this issue · 0 comments

You've left out what is probably the most common and obvious way to do graphs in practice in Rust, use identity keys:

#[derive(Copy, Clone, Eq, PartialEq, Hash)]
struct NodeID(u32);

struct Node {
    datum: &'static str,
    edges: Vec<NodeID>,
}

struct Graph {
    nodes: HashMap<NodeID, Node>, // or Vec if you never delete Nodes
}

Not a lot of overhead .. vastly less headaches.