Crates.io | treerder |
lib.rs | treerder |
version | |
source | src |
created_at | 2024-10-20 22:09:40.119577 |
updated_at | 2024-11-28 22:50:42.299427 |
description | Trie ordering for type implementing Orderable. |
homepage | https://github.com/bravequickcleverfibreyarn/treerder |
repository | https://github.com/bravequickcleverfibreyarn/treerder |
max_upload_size | |
id | 1416686 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
char
s sequence representationOrderable
trait&str
and String
oobchar
s iterated overchar
s in respective brancheslet mut test = [
String::from("zzz"),
String::from("ZZZ"),
String::from("aaa"),
String::from("AAA"),
];
let mut proof = test.clone();
proof.sort();
let mut orderer = Treerder::new();
orderer.order(&mut test);
assert_eq!(proof, test);
Orderable
implementation with custom alphabetuse treerder::{Orderable, Treerder, Alphabet, ab as ab_fn};
#[derive(Debug, PartialEq)]
struct LocalUsize(usize);
struct LocalUsizeCharIterator {
c: char,
x: bool,
}
impl Iterator for LocalUsizeCharIterator {
type Item = char;
fn next(&mut self) -> Option<char> {
if self.x {
self.x = false;
Some(self.c)
} else {
None
}
}
}
impl Orderable for LocalUsize {
type Shadow = usize;
fn chars(&self) -> impl Iterator<Item = char> {
let c = self.0.to_string().chars().next().unwrap();
LocalUsizeCharIterator { c, x: true }
}
fn shadow(&self) -> Self::Shadow {
self.0
}
fn steady(s: Self::Shadow) -> Self {
LocalUsize(s)
}
}
fn ix(c: char) -> usize {
c.to_digit(10).unwrap() as usize
}
fn ab() -> Alphabet<LocalUsize> {
ab_fn::<LocalUsize>(10)
}
let mut nums = [9, 8, 7, 5, 3, 1].map(|x| LocalUsize(x));
let mut orderer = Treerder::<LocalUsize>::new_with(ix, ab);
orderer.order(&mut nums);
let proof = [1, 3, 5, 7, 8, 9].map(|x| LocalUsize(x));
assert_eq!(proof, nums);