Skip to main content

Comparator

Trait Comparator 

Source
pub trait Comparator: Send + Sync {
    // Required methods
    fn compare(&self, a: &[u8], b: &[u8]) -> Ordering;
    fn name(&self) -> &str;
    fn find_shortest_separator(&self, start: &mut Vec<u8>, limit: &[u8]);
    fn find_short_successor(&self, key: &mut Vec<u8>);
}
Expand description

A comparator defines a total order over user keys.

The same comparator must be used for all operations on a database — opening a database with a different comparator than the one used to create it is an error.

Port of LevelDB’s include/leveldb/comparator.h.

Required Methods§

Source

fn compare(&self, a: &[u8], b: &[u8]) -> Ordering

Three-way comparison. Returns Ordering::Less, Equal, or Greater.

Source

fn name(&self) -> &str

The name of this comparator, stored in the MANIFEST so that opening a database with an incompatible comparator is detected.

Source

fn find_shortest_separator(&self, start: &mut Vec<u8>, limit: &[u8])

If *start < limit, change *start to a short string in [start, limit).

Used to shorten index-block separators. Simple implementations may leave start unchanged.

Source

fn find_short_successor(&self, key: &mut Vec<u8>)

Change *key to a short string >= *key.

Used for the last entry in an index block. Simple implementations may leave key unchanged.

Implementors§