ckb_rocksdb/ops/
compact.rs

1use super::columnfamily::GetColumnFamilys;
2use crate::{ffi_util::opt_bytes_to_ptr, handle::Handle, ColumnFamily};
3use libc::size_t;
4
5pub trait CompactRange {
6    fn compact_range<S: AsRef<[u8]>, E: AsRef<[u8]>>(&self, start: Option<S>, end: Option<E>);
7}
8
9pub trait CompactRangeCF {
10    fn compact_range_cf(&self, cf: &ColumnFamily, start: Option<&[u8]>, end: Option<&[u8]>);
11}
12
13impl<T> CompactRange for T
14where
15    T: Handle<ffi::rocksdb_t> + super::Write,
16{
17    fn compact_range<S: AsRef<[u8]>, E: AsRef<[u8]>>(&self, start: Option<S>, end: Option<E>) {
18        unsafe {
19            let start = start.as_ref().map(AsRef::as_ref);
20            let end = end.as_ref().map(AsRef::as_ref);
21
22            ffi::rocksdb_compact_range(
23                self.handle(),
24                opt_bytes_to_ptr(start),
25                start.map_or(0, |s| s.len()) as size_t,
26                opt_bytes_to_ptr(end),
27                end.map_or(0, |e| e.len()) as size_t,
28            );
29        }
30    }
31}
32
33impl<T> CompactRangeCF for T
34where
35    T: Handle<ffi::rocksdb_t> + super::Write + GetColumnFamilys,
36{
37    fn compact_range_cf(&self, cf: &ColumnFamily, start: Option<&[u8]>, end: Option<&[u8]>) {
38        unsafe {
39            ffi::rocksdb_compact_range_cf(
40                self.handle(),
41                cf.inner,
42                opt_bytes_to_ptr(start),
43                start.map_or(0, |s| s.len()) as size_t,
44                opt_bytes_to_ptr(end),
45                end.map_or(0, |e| e.len()) as size_t,
46            );
47        }
48    }
49}