use sinistra::graph::{
BasicGraph, Graph, GraphEdgesExt, GraphEdgesMutExt, GraphEndpointsExt, GraphNeighborsExt,
GraphVertexSetMutExt, HashMapStorage, HashMapTopology, Storage,
};
fn main() {
type Vertex = String;
type Edge = ();
let storage = HashMapStorage::<Vertex, Edge>::new();
let topology = HashMapTopology::new();
let mut graph = BasicGraph::new(storage, topology);
let a = graph.add_vertex("A".into());
let b = graph.add_vertex("B".into());
let c = graph.add_vertex("C".into());
graph.add_edge((), a, b); graph.add_edge((), b, c); graph.add_edge((), a, c);
println!("Vertices:");
for vertex in graph.vertices() {
let value = graph.storage().vertex(vertex).unwrap();
println!("{} (v{})", value, vertex.index());
}
println!("\nEdges:");
for edge in graph.edges() {
let (u, v) = graph.edge_endpoints(edge).unwrap();
let source = graph.storage().vertex(u).unwrap();
let target = graph.storage().vertex(v).unwrap();
println!("{} (v{}) -> {} (v{})", source, u.index(), target, v.index());
}
println!("\nOutbound Neighbors of A:");
for neighbor in graph.out_neighbors(a) {
let value = graph.storage().vertex(neighbor).unwrap();
println!("{} (v{})", value, neighbor.index());
}
}