Commit 92eef015 authored by Jay's avatar Jay

allow setting iterate option (#16)

parent 5b805d74
...@@ -27,6 +27,6 @@ pub mod comparator; ...@@ -27,6 +27,6 @@ pub mod comparator;
pub use librocksdb_sys::{DBCompactionStyle, DBComparator, DBCompressionType, pub use librocksdb_sys::{DBCompactionStyle, DBComparator, DBCompressionType,
new_bloom_filter, self as rocksdb_ffi}; new_bloom_filter, self as rocksdb_ffi};
pub use rocksdb::{DB, DBIterator, DBVector, Kv, SeekKey, Writable, WriteBatch}; pub use rocksdb::{DB, DBIterator, DBVector, Kv, SeekKey, Writable, WriteBatch, ReadOptions};
pub use rocksdb_options::{BlockBasedOptions, Options, WriteOptions}; pub use rocksdb_options::{BlockBasedOptions, Options, WriteOptions};
pub use merge_operator::MergeOperands; pub use merge_operator::MergeOperands;
...@@ -204,9 +204,13 @@ impl<'a> Snapshot<'a> { ...@@ -204,9 +204,13 @@ impl<'a> Snapshot<'a> {
} }
pub fn iter(&self) -> DBIterator { pub fn iter(&self) -> DBIterator {
let mut readopts = ReadOptions::new(); let readopts = ReadOptions::new();
readopts.set_snapshot(self); self.iter_opt(readopts)
DBIterator::new(self.db, &readopts) }
pub fn iter_opt(&self, mut opt: ReadOptions) -> DBIterator {
opt.set_snapshot(self);
DBIterator::new(self.db, &opt)
} }
pub fn get(&self, key: &[u8]) -> Result<Option<DBVector>, String> { pub fn get(&self, key: &[u8]) -> Result<Option<DBVector>, String> {
...@@ -583,7 +587,11 @@ impl DB { ...@@ -583,7 +587,11 @@ impl DB {
pub fn iter(&self) -> DBIterator { pub fn iter(&self) -> DBIterator {
let opts = ReadOptions::new(); let opts = ReadOptions::new();
DBIterator::new(&self, &opts) self.iter_opt(&opts)
}
pub fn iter_opt(&self, opt: &ReadOptions) -> DBIterator {
DBIterator::new(&self, opt)
} }
pub fn iter_cf(&self, pub fn iter_cf(&self,
...@@ -971,14 +979,14 @@ impl Default for ReadOptions { ...@@ -971,14 +979,14 @@ impl Default for ReadOptions {
} }
impl ReadOptions { impl ReadOptions {
fn new() -> ReadOptions { pub fn new() -> ReadOptions {
ReadOptions::default() ReadOptions::default()
} }
// TODO add snapshot setting here // TODO add snapshot setting here
// TODO add snapshot wrapper structs with proper destructors; // TODO add snapshot wrapper structs with proper destructors;
// that struct needs an "iterator" impl too. // that struct needs an "iterator" impl too.
#[allow(dead_code)] #[allow(dead_code)]
fn fill_cache(&mut self, v: bool) { pub fn fill_cache(&mut self, v: bool) {
unsafe { unsafe {
rocksdb_ffi::rocksdb_readoptions_set_fill_cache(self.inner, v); rocksdb_ffi::rocksdb_readoptions_set_fill_cache(self.inner, v);
} }
......
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