Commit 2aebd37e authored by zhangjinpeng1987's avatar zhangjinpeng1987

add filter policy interface

parent 0ab75512
...@@ -22,6 +22,10 @@ use merge_operator::{self, MergeOperatorCallback, full_merge_callback, ...@@ -22,6 +22,10 @@ use merge_operator::{self, MergeOperatorCallback, full_merge_callback,
use comparator::{self, ComparatorCallback, compare_callback}; use comparator::{self, ComparatorCallback, compare_callback};
use merge_operator::MergeFn; use merge_operator::MergeFn;
pub struct FilterPolicy {
inner: rocksdb_ffi::DBFilterPolicy,
}
pub struct BlockBasedOptions { pub struct BlockBasedOptions {
inner: rocksdb_ffi::DBBlockBasedTableOptions, inner: rocksdb_ffi::DBBlockBasedTableOptions,
} }
...@@ -42,6 +46,14 @@ impl Drop for Options { ...@@ -42,6 +46,14 @@ impl Drop for Options {
} }
} }
impl Drop for FilterPolicy {
fn drop(& mut self) {
unsafe {
rocksdb_ffi::rocksdb_filterpolicy_destroy(self.inner);
}
}
}
impl Drop for BlockBasedOptions { impl Drop for BlockBasedOptions {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
...@@ -70,6 +82,18 @@ impl Default for BlockBasedOptions { ...@@ -70,6 +82,18 @@ impl Default for BlockBasedOptions {
} }
} }
impl FilterPolicy {
pub fn new_bloom_filter(bits_per_key: c_int, block_based: bool) -> FilterPolicy {
let filter = if block_based {
unsafe { rocksdb_ffi::rocksdb_filterpolicy_create_bloom(bits_per_key) }
} else {
unsafe { rocksdb_ffi::rocksdb_filterpolicy_create_bloom_full(bits_per_key) }
};
FilterPolicy { inner: filter }
}
}
impl BlockBasedOptions { impl BlockBasedOptions {
pub fn new() -> BlockBasedOptions { pub fn new() -> BlockBasedOptions {
BlockBasedOptions::default() BlockBasedOptions::default()
...@@ -90,6 +114,13 @@ impl BlockBasedOptions { ...@@ -90,6 +114,13 @@ impl BlockBasedOptions {
rocksdb_ffi::rocksdb_block_based_options_set_block_cache(self.inner, cache); rocksdb_ffi::rocksdb_block_based_options_set_block_cache(self.inner, cache);
} }
} }
pub fn set_filter_policy(&mut self, filter: &FilterPolicy) {
unsafe {
rocksdb_ffi::rocksdb_block_based_options_set_filter_policy(self.inner,
filter.inner);
}
}
} }
// TODO figure out how to create these in a Rusty way // TODO figure out how to create these in a Rusty way
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment