#bisect #collation

collate

Traits and a data structure to support collation and bisection

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

Download history 76/week @ 2022-10-02 32/week @ 2022-10-09 25/week @ 2022-10-16 42/week @ 2022-10-23 67/week @ 2022-10-30 82/week @ 2022-11-06 51/week @ 2022-11-13 33/week @ 2022-11-20 24/week @ 2022-11-27 41/week @ 2022-12-04 64/week @ 2022-12-11 46/week @ 2022-12-18 39/week @ 2022-12-25 17/week @ 2023-01-01 51/week @ 2023-01-08 18/week @ 2023-01-15

127 downloads per month
Used in 10 crates (6 directly)

Apache-2.0

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