Crate searchsort

source ·
Expand description

This crate provides a trait SearchSort that defines methods for searching and sorting.

The SearchSort trait provides a method find_me that finds the first occurrence of an element in a slice between a start and end index. It returns Some(index) if found, otherwise None.

The crate also provides an implementation of the SearchSort trait for the Vec<T> type, which allows you to use the find_me method on vectors.

Additionally, the crate provides a method quicksort that sorts a mutable slice in-place using the quicksort algorithm.

The crate also includes tests and benchmarks for the find_me and quicksort methods.

Examples

use searchsort::SearchSort;

let arr = vec![4, 82, 4, 32, 3, 20, 3, 2, 2, 9, 8, 7, 5, 0];
let find = 5;

assert_eq!(arr.find_me(find, 0, arr.len()-1), Some(12));

let mut arr = vec![3, 1, 4, 1, 5, 9, 2, 6, 5];
arr.quicksort();
assert_eq!(arr, [1, 1, 2, 3, 4, 5, 5, 6, 9]);

Traits