diff --git a/src/db_options.rs b/src/db_options.rs index bf763f5..c9d51c0 100644 --- a/src/db_options.rs +++ b/src/db_options.rs @@ -561,7 +561,17 @@ impl BlockBasedOptions { } } - /// Sets the filter policy to reduce disk reads + /// Sets a [Bloom filter](https://github.com/facebook/rocksdb/wiki/RocksDB-Bloom-Filter) + /// policy to reduce disk reads. + /// + /// # Examples + /// + /// ``` + /// use rocksdb::BlockBasedOptions; + /// + /// let mut opts = BlockBasedOptions::default(); + /// opts.set_bloom_filter(10.0, true); + /// ``` pub fn set_bloom_filter(&mut self, bits_per_key: c_double, block_based: bool) { unsafe { let bloom = if block_based { @@ -574,6 +584,56 @@ impl BlockBasedOptions { } } + /// Sets a [Ribbon filter](http://rocksdb.org/blog/2021/12/29/ribbon-filter.html) + /// policy to reduce disk reads. + /// + /// Ribbon filters use less memory in exchange for slightly more CPU usage + /// compared to an equivalent bloom filter. + /// + /// # Examples + /// + /// ``` + /// use rocksdb::BlockBasedOptions; + /// + /// let mut opts = BlockBasedOptions::default(); + /// opts.set_ribbon_filter(10.0); + /// ``` + pub fn set_ribbon_filter(&mut self, bloom_equivalent_bits_per_key: c_double) { + unsafe { + let ribbon = ffi::rocksdb_filterpolicy_create_ribbon(bloom_equivalent_bits_per_key); + ffi::rocksdb_block_based_options_set_filter_policy(self.inner, ribbon); + } + } + + /// Sets a hybrid [Ribbon filter](http://rocksdb.org/blog/2021/12/29/ribbon-filter.html) + /// policy to reduce disk reads. + /// + /// Uses Bloom filters before the given level, and Ribbon filters for all + /// other levels. This combines the memory savings from Ribbon filters + /// with the lower CPU usage of Bloom filters. + /// + /// # Examples + /// + /// ``` + /// use rocksdb::BlockBasedOptions; + /// + /// let mut opts = BlockBasedOptions::default(); + /// opts.set_hybrid_ribbon_filter(10.0, 2); + /// ``` + pub fn set_hybrid_ribbon_filter( + &mut self, + bloom_equivalent_bits_per_key: c_double, + bloom_before_level: c_int, + ) { + unsafe { + let ribbon = ffi::rocksdb_filterpolicy_create_ribbon_hybrid( + bloom_equivalent_bits_per_key, + bloom_before_level, + ); + ffi::rocksdb_block_based_options_set_filter_policy(self.inner, ribbon); + } + } + pub fn set_cache_index_and_filter_blocks(&mut self, v: bool) { unsafe { ffi::rocksdb_block_based_options_set_cache_index_and_filter_blocks(self.inner, v as u8);