Skip to content

Commit

Permalink
chore: add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
slavik-pastushenko committed Oct 24, 2024
1 parent 255ecfc commit b8c3d68
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
license = "MIT"
readme = "README.md"
authors = ["Slavik Pastushenko <slavpas@gmail.com>"]
exclude = [".github/**"]
exclude = [".github/**", "examples/**"]
documentation = "https://docs.rs/graph-algorithms-rs"
repository = "https://github.com/slavik-pastushenko/graph-algorithms-rs"

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ The Floyd-Warshall algorithm finds shortest paths between all pairs of vertices

This crate uses `#![forbid(unsafe_code)]` to ensure everything is implemented in 100% safe Rust.

## Usage

The `examples` directory contains example implementations of various graph algorithms:

```rust
use graph_algorithms::{Dijkstra, GraphAlgorithm};
```

## Contributing

Build the application:
Expand Down
7 changes: 7 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "dijkstra"
version = "0.1.0"
edition = "2021"

[dependencies]
graph-algorithms-rs = { path = "../" }
14 changes: 14 additions & 0 deletions examples/src/dijkstra.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use graph_algorithms::{Dijkstra, GraphAlgorithm};

pub fn run() {
let mut dijkstra = Dijkstra::new();
dijkstra.set_nodes(vec![
(0, vec![(1, 1), (2, 4)]),
(1, vec![(2, 2)]),
(2, vec![]),
]);

let result = dijkstra.run(0);

println!("{:?}", result);
}
6 changes: 6 additions & 0 deletions examples/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mod dijkstra;

fn main() {
// Run the Dijkstra example
dijkstra::run();
}

0 comments on commit b8c3d68

Please sign in to comment.