5 releases
new 0.1.4 | Apr 22, 2025 |
---|---|
0.1.3 | Apr 22, 2025 |
0.1.2 | Apr 22, 2025 |
0.1.1 | Apr 22, 2025 |
0.1.0 | Apr 22, 2025 |
#672 in Data structures
36 downloads per month
28KB
623 lines
๐ Rust DSA Library
A collection of core Data Structures and Algorithms implemented in Rust. Currently includes a fully functional and tested Binary Search Tree (BST) with support for insert, delete, search, and traversal operations.
๐ Features
- โ
Binary Search Tree (BST)
- Insert
- Delete
- Search
- In-order, Pre-order, Post-order traversals
- โ
Singly Linked List
- Insert
- Delete
- Get by index and data
- ๐ Logarithmic time complexity for insert/search/delete in balanced trees
- ๐งช Thoroughly tested with unit tests
- ๐ฆ Unsafe Rust for raw pointer manipulation (performance reasons)
๐ฆ Installation
Clone this repository and include it in your workspace or build it as a Rust library:
git clone https://github.com/lucasmelodev1/dsa_abc cd dsa_abc cargo build
๐ Usage Example
use dsa_abc::BinarySearchTree;
fn main() {
let mut bst = BinarySearchTree::new(10);
bst.add(5);
bst.add(15);
if let Some(val) = bst.get(&5) {
println!("Found: {}", val);
}
// Traversal example
let mut values = vec![];
bst.in_order(&mut |v| values.push(*v));
println!("In-order values: {:?}", values);
}
โ Tests
Run tests using:
cargo test
Tests include:
- Basic insert/search/delete
- Deleting root and internal nodes
- Verifying correct order in traversals (in-order, pre-order, post-order)
๐ Structure
src/
โโโ lib.rs # Core implementation
โโโ ...
๐ง Planned Features
This crate aims to be an educational toolkit for practicing and learning DSA in Rust. Upcoming additions include:
- โ Binary Search Tree
- โ Singly Linked List
- โณ Doubly Linked List
- โณ AVL Tree
- โณ Red-Black Tree
- โณ Hash Table
- โณ Sorting Algorithms (Merge, Quick, Bubble)
- โณ Heap
โ ๏ธ Safety Disclaimer
This library uses unsafe code to manually manage pointers for educational purposes. Check the tests section to see if they are enough for your use case and, if not enough, please contact me and I will update them.
๐ License
MIT License