Skip to content

Commit

Permalink
feat(algorithms): implement dijkstra's
Browse files Browse the repository at this point in the history
  • Loading branch information
slavik-pastushenko committed Oct 24, 2024
1 parent 5086451 commit 8a1f9a8
Show file tree
Hide file tree
Showing 7 changed files with 400 additions and 16 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: test

on:
push:
branches: [ "main" ]
paths:
- '**.rs'
- 'src/**.rs'
pull_request:
branches: [ "main" ]
paths:
- '**.rs'
- 'src/**.rs'

env:
CI: true
CARGO_TERM_COLOR: always

jobs:
test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Install tarpaulin
run: cargo install cargo-tarpaulin
- name: Run build
run: cargo build
- name: Run clippy
run: cargo clippy --all-targets --all-features --no-deps -- -D warnings
- name: Run lint
run: cargo fmt -- --check
- name: Run tests
run: cargo tarpaulin --out xml
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
file: ./cobertura.xml
18 changes: 4 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# RustRover
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.env
/.idea
/.vscode
.DS_Store
13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "graph-algorithms-rs"
description = "A collection of graph algorithms."
version = "1.0.0"
edition = "2021"
license = "MIT"
readme = "README.md"
authors = ["Slavik Pastushenko <slavpas@gmail.com>"]
repository = "https://github.com/slavik-pastushenko/graph-algorithms-rs"

[lib]
name = "graph_algorithms"
path = "src/lib.rs"
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Slavik
Copyright (c) 2024 Slavik Pastushenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
67 changes: 66 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,66 @@
# graph-algorithms-rs
# Graph Algorithms in Rust

A collection of graph algorithms implemented in Rust. This repository aims to provide efficient and easy-to-understand implementations of various graph algorithms for educational purposes and practical use.

Contributions are welcome to expand the set of algorithms and improve existing implementations.

## Reference implementation

[![test](https://github.com/slavik-pastushenko/graph-algorithms-rs/actions/workflows/test.yml/badge.svg)](https://github.com/slavik-pastushenko/graph-algorithms-rs/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/slavik-pastushenko/graph-algorithms-rs/graph/badge.svg?token=9EL0F6725A)](https://codecov.io/gh/slavik-pastushenko/graph-algorithms-rs)

### Algorithms

### Dijkstra's Algorithm
Dijkstra's algorithm finds the shortest path from a starting node to all other nodes in a weighted graph. It uses a priority queue to efficiently select the next node with the smallest distance.

### A* Algorithm (TODO)
A* is a pathfinding and graph traversal algorithm that is often used in many fields of computer science due to its completeness, optimality, and optimal efficiency.

### Breadth-First Search (BFS) (TODO)
BFS explores the graph level by level, starting from a given node. It is used for finding the shortest path in an unweighted graph.

### Depth-First Search (DFS) (TODO)
DFS explores as far as possible along each branch before backtracking. It is used for pathfinding and topological sorting.

### Bellman-Ford Algorithm (TODO)
The Bellman-Ford algorithm computes shortest paths from a single source vertex to all of the other vertices in a weighted digraph. It can handle graphs with negative weight edges.

### Floyd-Warshall Algorithm (TODO)
The Floyd-Warshall algorithm finds shortest paths between all pairs of vertices in a weighted graph. It can handle graphs with negative weights but no negative weight cycles.

## Safety

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

## Contributing

Build the application:

```bash
cargo build
```

Test the application:

```bash
cargo test
```

Run [clippy](https://github.com/rust-lang/rust-clippy):

```bash
cargo clippy --all-targets --all-features --no-deps -- -D warnings
```

Run [lint](https://github.com/rust-lang/rustfmt):

```bash
cargo fmt
```

Generate documentation in HTML format:

```bash
cargo doc --open
```
Loading

0 comments on commit 8a1f9a8

Please sign in to comment.