[−][src]Trait rocks::comparator::Comparator
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"
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.