[][src]Trait rocks::comparator::Comparator

pub trait Comparator {
    fn compare(&self, a: &[u8], b: &[u8]) -> Ordering;

    fn equal(&self, a: &[u8], b: &[u8]) -> bool { ... }
fn name(&self) -> &str { ... }
fn find_shortest_separator(
        &self,
        _start: &[u8],
        _limit: &[u8]
    ) -> Option<&[u8]> { ... }
fn find_short_successor(&self, _key: &[u8]) -> Option<&[u8]> { ... } }

A Comparator object provides a total order across slices that are used as keys in an sstable or a database. A Comparator implementation must be thread-safe since rocksdb may invoke its methods concurrently from multiple threads.

Required methods

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

Three-way comparison. Returns value:

  • < 0 iff "a" < "b",
  • == 0 iff "a" == "b",
  • > 0 iff "a" > "b"
Loading content...

Provided methods

fn equal(&self, a: &[u8], b: &[u8]) -> bool

Compares two slices for equality. The following invariant should always hold (and is the default implementation):

Equal(a, b) iff Compare(a, b) == 0

Overwrite only if equality comparisons can be done more efficiently than three-way comparisons.

fn name(&self) -> &str

The name of the comparator. Used to check for comparator mismatches (i.e., a DB created with one comparator is accessed using a different comparator.

The client of this package should switch to a new name whenever the comparator implementation changes in a way that will cause the relative ordering of any two keys to change.

Names starting with "rocksdb." are reserved and should not be used by any clients of this package.

fn find_shortest_separator(&self, _start: &[u8], _limit: &[u8]) -> Option<&[u8]>

If *start < limit, changes *start to a short string in [start,limit). Simple comparator implementations may return with *start unchanged, i.e., an implementation of this method that does nothing is correct.

fn find_short_successor(&self, _key: &[u8]) -> Option<&[u8]>

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

Simple comparator implementations may return with *key unchanged, i.e., an implementation of this method that does nothing is correct.

Loading content...

Implementors

Loading content...