diff --git a/src/db_options.rs b/src/db_options.rs index d42fd2a..ba9bbad 100644 --- a/src/db_options.rs +++ b/src/db_options.rs @@ -19,7 +19,7 @@ use std::path::Path; use libc::{self, c_int, c_uchar, c_uint, c_void, size_t, uint64_t}; use ffi; -use {BlockBasedOptions, DBCompactionStyle, DBCompressionType, DBRecoveryMode, MemtableFactory, +use {BlockBasedOptions, BlockBasedIndexType, DBCompactionStyle, DBCompressionType, DBRecoveryMode, MemtableFactory, Options, WriteOptions}; use compaction_filter::{self, CompactionFilterCallback, CompactionFilterFn, filter_callback}; use comparator::{self, ComparatorCallback, CompareFn}; @@ -96,6 +96,24 @@ impl BlockBasedOptions { ffi::rocksdb_block_based_options_set_cache_index_and_filter_blocks(self.inner, v as u8); } } + + /// Defines the index type to be used for SS-table lookups. + /// + /// # Example + /// + /// ``` + /// use rocksdb::{BlockBasedOptions, BlockBasedIndexType, Options}; + /// + /// let mut opts = Options::default(); + /// let mut block_opts = BlockBasedOptions::default(); + /// block_opts.set_index_type(BlockBasedIndexType::HashSearch); + /// ``` + pub fn set_index_type(&mut self, index_type: BlockBasedIndexType) { + let index = index_type as i32; + unsafe { + ffi::rocksdb_block_based_options_set_index_type(self.inner, index); + } + } } impl Default for BlockBasedOptions { diff --git a/src/lib.rs b/src/lib.rs index d7133d0..b8193bf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -136,6 +136,20 @@ pub struct BlockBasedOptions { inner: *mut ffi::rocksdb_block_based_table_options_t, } +/// Used by BlockBasedOptions::set_index_type. +pub enum BlockBasedIndexType { + /// A space efficient index block that is optimized for + /// binary-search-based index. + BinarySearch, + + /// The hash index, if enabled, will perform a hash lookup if + /// a prefix extractor has been provided through Options::set_prefix_extractor. + HashSearch, + + /// A two-level index implementation. Both levels are binary search indexes. + TwoLevelIndexSearch, +} + /// Defines the underlying memtable implementation. /// See https://github.com/facebook/rocksdb/wiki/MemTable for more information. pub enum MemtableFactory {