#collation #data-structures #bisect

collate

Traits and a data structure to support collation and bisection

19 releases

0.4.2 Aug 13, 2024
0.4.1 Dec 20, 2023
0.4.0 Nov 6, 2023
0.3.0 Jul 3, 2023
0.1.1 Jan 18, 2021

#1223 in Rust patterns

Download history 32/week @ 2025-12-28 48/week @ 2026-01-04 43/week @ 2026-01-11 133/week @ 2026-01-18 105/week @ 2026-01-25 212/week @ 2026-02-01 105/week @ 2026-02-08 178/week @ 2026-02-15 223/week @ 2026-02-22 122/week @ 2026-03-01 165/week @ 2026-03-08 222/week @ 2026-03-15 134/week @ 2026-03-22 103/week @ 2026-03-29 74/week @ 2026-04-05 184/week @ 2026-04-12

495 downloads per month
Used in 22 crates (9 directly)

Apache-2.0

36KB
807 lines

Defines a Collate trait to standardize collation methods across data types. The provided Collator struct can be used to collate a collection of items of type T where T: Ord.

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 handle types like complex numbers which do not necessarily have a natural ordering.

Use the "stream" feature flag to enable diff and try_diff functions to compute the difference between two collated Streams, and the merge and try_merge functions to merge two collated Streams.


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);

Dependencies

~210KB