Crates.io | algos |
lib.rs | algos |
version | 0.4.0 |
source | src |
created_at | 2018-07-21 07:12:29.521321 |
updated_at | 2020-02-23 00:38:51.769077 |
description | A collection of algorithms in Rust |
homepage | https://crates.io/crates/algos |
repository | https://github.com/GrayJack/algos |
max_upload_size | |
id | 75317 |
size | 56,426 |
A Rust library with a collection of algorithms. Mostly intended as learning exercises for Rust.
Only sort, search and pattern matching algorithms for now. It is planned to add graph algorithms as well.
Add this to your Cargo.toml
:
[dependencies]
algos = "0.3"
and this to your crate root if on 2015 edition:
extern crate algos;
Add this to your crate root:
use algos::sort;
and create an array and use like this:
fn fn main() {
let mut v = [2, 3, 1, 9, 8, 4];
// Crescent sorting
sort::heap(&mut v, &|a,b| a<b);
// For decreasing sorting, change the signal in &|a,b| a>b.
}
It can also work in an array of Strings, sorting by the length of the string:
fn main() {
let mut v = ["bc", "a", "def", "klmno", "ghij", "pqrstu"];
// Crescent sorting
sort::merge(&mut v, &|a,b| a.len()<b.len())
}
Add this to your crate root:
use algos::search;
and create an array and use like this:
fn fn main() {
// Remember that your array must be crescent sorted.
let mut v = [1, 2, 3, 4, 5, 7, 9];
let find = search::binary(&v, &5);
}
Add this to your crate root:
use algos::pattern;
and use like this:
fn fn main() {
let p = "ATCGGATTTCAGAAGCT".as_bytes();
let find = karp_rabin(&p, &"TTT".as_bytes()); // Type Return<usize, usize>
}