9 unstable releases

new 0.5.1 Jan 17, 2025
0.5.0 Jan 17, 2025
0.4.0 Feb 23, 2020
0.3.2 Oct 11, 2018
0.1.1 Jul 21, 2018

#174 in Algorithms

Download history 5/week @ 2024-09-20 1/week @ 2024-09-27

411 downloads per month

Custom license

58KB
1K SLoC

Algos

Crates.io Documentation Build Status dependency status GitHub license

** Jan 16, 2025 - ADVISORY - This crate has changed hands and will be maintained by @Brad-Edwards - Expect breaking changes. **

** The repo has been moved to a new repo. **

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.

Usage

Add this to your Cargo.toml:

[dependencies]
algos = "0.5.1"

and this to your crate root if on 2015 edition:

extern crate algos;

Sorts Algorithms

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())
}

Search Algorithms

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);
}

Pattern Matching algorithms

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>
}

Implemented

Sorts

  • Selection Sort
  • Bubble Sort
  • Cocktail Sort
  • Insertion Sort
  • Merge Sort
  • Quick Sort
  • Heap Sort

Searches

  • Linear Search
  • Binary Search
  • Exponential Search
  • Fibonacci Search

String Matching

  • Bruteforce
  • Karp-Rabin
  • Boyer-Moore
  • Horspool
  • Quick
  • Two-Way

Dependencies

~240–385KB