# American Flag sort for Rust
[](https://travis-ci.org/antonha/afsort)
The afsort crate implements a sorting algorithm based on
[American Flag sort](https://en.wikipedia.org/wiki/American_flag_sort). The implementation is
currently limited to sort byte slices, e.g. Strings. The main motivation is to sort strings of
text, so most of the benchmarks are based on English text strings. When sorting English words,
this implementation seems to be about 40% faster than `sort_unstable` from the Rust standard
library.
For small input, this method falls back to the standard library.
# Installation - TODO: Not on crates yet
Add the depndency to your `Cargo.toml`:
```ignore
[dependencies]
afsort = "0.1"
```
In your crate root:
```ignore
extern crate afsort;
```
# Usage
You can now use afsort to e.g. sort arrays of strings or string slices.
```rust
use afsort;
let mut strings = vec!("red", "green", "blue");
afsort::sort_unstable(&mut strings);
assert_eq!(strings, vec!["blue", "green", "red"]);
```
You can also sort by an extractor function, e.g.:
```rust
use afsort;
let mut tuples = vec![("b", 2), ("a", 1)];
good first step, since it supports sorting of Strings. There is however no reason why American
Flag sorting should be limited to this data type. Any kind of element that can deliver a radix
to a certain digit/depth can be sorted using this technique.
The American Flag algorithm is unstable, in the same way that sort_unstable in the standard
library. That is, equal elements might be re-ordered.
This crate can _only_ sort strings based on their `utf-8` byte values. For many problems, this
is fine. However, if you want to sort strings for display to a user, Locale might matter. This
crate does not try to address this issue.
# Testing
Testing is done using the [quickcheck](https://github.com/BurntSushi/quickcheck) crate. We run
about 50k different variations of input strings. We treat the standard library's sort_unstable
as the gold standard.
# License
This repository is licensed under the MIT license, with the exception of the english-american.txt
dictionary file, which comes from the Linux words package, and thus is under GPL. The dictionary
is only used for testing purposes.