pub struct Comparator { /* private fields */ }Expand description
A key ordering, owned by Rust and shareable with anything that needs one.
RocksDB never takes ownership of a comparator: Options, WriteBatchWithIndex
and the rest all keep a borrowed pointer to it. Wrap it in an Arc and hand
out clones so it outlives every user, which is what
Options::set_comparator does internally.
Implementations§
Source§impl Comparator
impl Comparator
Sourcepub fn new(
name: impl CStrLike,
compare_fn: Box<dyn Fn(&[u8], &[u8]) -> Ordering + Send + Sync>,
) -> Self
pub fn new( name: impl CStrLike, compare_fn: Box<dyn Fn(&[u8], &[u8]) -> Ordering + Send + Sync>, ) -> Self
Builds a comparator from a total order over keys.
name is persisted in the SST files. Changing the ordering without
changing the name gives RocksDB no way to notice, and it will read the
old files with the new ordering, so pick a new name whenever the order
changes.
§Panics
Panics if name contains an interior nul byte.
Sourcepub fn with_ts(
name: impl CStrLike,
timestamp_size: usize,
compare_fn: Box<dyn Fn(&[u8], &[u8]) -> Ordering + Send + Sync>,
compare_ts_fn: Box<dyn Fn(&[u8], &[u8]) -> Ordering + Send + Sync>,
compare_without_ts_fn: Box<dyn Fn(&[u8], bool, &[u8], bool) -> Ordering + Send + Sync>,
) -> Self
pub fn with_ts( name: impl CStrLike, timestamp_size: usize, compare_fn: Box<dyn Fn(&[u8], &[u8]) -> Ordering + Send + Sync>, compare_ts_fn: Box<dyn Fn(&[u8], &[u8]) -> Ordering + Send + Sync>, compare_without_ts_fn: Box<dyn Fn(&[u8], bool, &[u8], bool) -> Ordering + Send + Sync>, ) -> Self
Builds a comparator for a column family that uses user-defined timestamps.
timestamp_size is the fixed width of the timestamp suffix on every key.
compare_fn orders whole keys including the timestamp, compare_ts_fn
orders two bare timestamps, and compare_without_ts_fn orders keys
ignoring their timestamps. See the RocksDB user-defined timestamp docs.
§Panics
Panics if name contains an interior nul byte.