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§
sourcefn compare_elem(a: u8, b: u8) -> Ordering
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.
sourcefn successor(elem: u8) -> Option<u8>
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.
sourcefn predecessor(elem: u8) -> Option<u8>
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.