heed

Trait LexicographicComparator

Source
pub trait LexicographicComparator: Comparator {
    // Required methods
    fn compare_elem(a: u8, b: u8) -> Ordering;
    fn successor(elem: u8) -> Option<u8>;
    fn predecessor(elem: u8) -> Option<u8>;
    fn max_elem() -> u8;
    fn min_elem() -> u8;
}
Expand description

Define a lexicographic comparator, which is a special case of Comparator.

Types that implements LexicographicComparator will automatically have Comparator implemented as well, where the Comparator::compare is implemented per the definition of lexicographic ordering with LexicographicComparator::compare_elem.

This trait is introduced to support prefix iterators, which implicit assumes that the underlying key comparator is lexicographic.

Required Methods§

Source

fn compare_elem(a: u8, b: u8) -> Ordering

Compare a single byte; this function is used to implement Comparator::compare by definition of lexicographic ordering.

§Safety

This function must never crash.

Source

fn successor(elem: u8) -> Option<u8>

Advances the given elem to its immediate lexicographic successor, if possible. Returns None if elem is already at its maximum value with respect to the lexicographic order defined by this comparator.

Source

fn predecessor(elem: u8) -> Option<u8>

Moves the given elem to its immediate lexicographic predecessor, if possible. Returns None if elem is already at its minimum value with respect to the lexicographic order defined by this comparator.

Source

fn max_elem() -> u8

Returns the maximum byte value per the comparator’s lexicographic order.

Source

fn min_elem() -> u8

Returns the minimum byte value per the comparator’s lexicographic order.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§