15 releases
Uses new Rust 2021
new 0.2.4 | Jan 21, 2023 |
---|---|
0.2.3 | Apr 24, 2022 |
0.1.10 | Apr 30, 2021 |
0.1.1 | Jan 18, 2021 |
#384 in Rust patterns
127 downloads per month
Used in 10 crates
(6 directly)
24KB
594 lines
collate
Rust collation utilities
Example usage:
use collate::*;
let collator = Collator::default();
let collection = [
[1, 2, 3],
[2, 3, 4],
[3, 4, 5],
];
assert_eq!(collator.bisect_left(&collection, &[1]), 0);
assert_eq!(collator.bisect_right(&collection, &[1]), 1);
lib.rs
:
Defines a [Collate
] trait to standardize collation methods across data types. The provided
[Collator
] struct can be used to collate a collection of slices of type T
where T: Ord
.
Also provides bisect
(with a [Range
]), bisect_left
, and bisect_right
methods.
[Collate
] is useful for implementing a B-Tree, or to handle cases where a collator type is
more efficient than calling Ord::cmp
repeatedly, for example when collating localized strings
using rust_icu_ucol
. It's also useful to collate types like f32
and f64
which do not support Ord
. A [FloatCollator
] is provided for this purpose.
Enable the "complex" feature to provide support for collating Complex
numbers provided by
the num_complex
crate.
Example:
# use collate::*;
let collator = Collator::default();
let collection = [
[1, 2, 3],
[2, 3, 4],
[3, 4, 5],
];
assert_eq!(collator.bisect_left(&collection, &[1]), 0);
assert_eq!(collator.bisect_right(&collection, &[1]), 1);
Dependencies
~53KB