Trait heed_traits::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.

Object Safety§

This trait is not object safe.

Implementors§