Crates.io | kurve |
lib.rs | kurve |
version | 0.1.0 |
source | src |
created_at | 2023-10-19 20:44:24.537773 |
updated_at | 2023-10-19 20:44:24.537773 |
description | Adjacency list graph data structure |
homepage | https://github.com/Tyrannican/kurve |
repository | https://github.com/Tyrannican/kurve |
max_upload_size | |
id | 1008362 |
size | 25,140 |
Simple adjacency list Graph data structure with Dijkstra pathing.
No bells, no whistles; just a graph with the ability to add / remove vertices with weighted / unweighted edges with a simple pathing algorithm.
Performance? Not designed with that in mind but good enough for simple - intermediate cases.
use kurve::Kurve;
// Create a graph with String IDs and i32 values
let mut graph: Kurve<String, i32> = Kurve::new();
// Add some vertices
graph.add_vertex("id_1".to_string(), 100);
graph.add_vertex("id_2".to_string(), 200);
graph.add_vertex("id_3".to_string(), 300);
graph.add_vertex("id_4".to_string(), 400);
// Add some edges
graph.add_edge("id_1".to_string(), "id_2".to_string());
graph.add_edge("id_1".to_string(), "id_3".to_string());
graph.add_edge("id_2".to_string(), "id_4".to_string());
graph.add_edge("id_4".to_string(), "id_3".to_string());
// Get neighbors of a node
let neighbors = graph.get_neighbors("id_1".to_string()); // ["id_2", "id_3"]
// Find paths
let path = graph.dijkstra("id_1".to_string(), "id_4".to_string()); // ["id_1", "id_2", "id_4"]