From bcc4ca48ab11da19627673b7d1fbb7fb1dff33b6 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Sun, 21 Feb 2016 15:19:08 +0300 Subject: [PATCH 1/2] to new namespace --- util/src/kvdb.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/src/kvdb.rs b/util/src/kvdb.rs index fa74553fb..921e8b3c4 100644 --- a/util/src/kvdb.rs +++ b/util/src/kvdb.rs @@ -69,7 +69,7 @@ pub struct Database { impl Database { /// Open database with default settings. pub fn open_default(path: &str) -> Result { - Database::open(&DatabaseConfig { prefix_size: None }, path) + Database::open(&DatabaseConfig { prefix_size: None }, path) } /// Open database file. Creates if it does not exist. @@ -120,7 +120,7 @@ impl Database { pub fn write(&self, tr: DBTransaction) -> Result<(), String> { self.db.write(tr.batch) } - + /// Get value by key. pub fn get(&self, key: &[u8]) -> Result, String> { self.db.get(key) @@ -152,7 +152,7 @@ impl Database { mod tests { use hash::*; use super::*; - use tests::helpers::RandomTempPath; + use devtools::*; use std::str::FromStr; use std::ops::Deref; @@ -185,7 +185,7 @@ mod tests { db.write(transaction).unwrap(); assert!(db.get(&key1).unwrap().is_none()); assert_eq!(db.get(&key3).unwrap().unwrap().deref(), b"elephant"); - + if config.prefix_size.is_some() { assert_eq!(db.get_by_prefix(&key3).unwrap().deref(), b"elephant"); assert_eq!(db.get_by_prefix(&key2).unwrap().deref(), b"dog"); From 67cd29f4e14c7877c1af0341025322e3e047a0ca Mon Sep 17 00:00:00 2001 From: arkpar Date: Sun, 21 Feb 2016 16:58:56 +0100 Subject: [PATCH 2/2] Whitespaces --- util/src/kvdb.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/util/src/kvdb.rs b/util/src/kvdb.rs index 921e8b3c4..23784c200 100644 --- a/util/src/kvdb.rs +++ b/util/src/kvdb.rs @@ -31,12 +31,12 @@ impl DBTransaction { } /// Insert a key-value pair in the transaction. Any existing value value will be overwritten upon write. - pub fn put(&self, key: &[u8], value: &[u8]) -> Result<(), String> { + pub fn put(&self, key: &[u8], value: &[u8]) -> Result<(), String> { self.batch.put(key, value) } /// Delete value by key. - pub fn delete(&self, key: &[u8]) -> Result<(), String> { + pub fn delete(&self, key: &[u8]) -> Result<(), String> { self.batch.delete(key) } } @@ -49,14 +49,14 @@ pub struct DatabaseConfig { /// Database iterator pub struct DatabaseIterator<'a> { - iter: DBIterator<'a>, + iter: DBIterator<'a>, } impl<'a> Iterator for DatabaseIterator<'a> { - type Item = (Box<[u8]>, Box<[u8]>); + type Item = (Box<[u8]>, Box<[u8]>); #[allow(type_complexity)] - fn next(&mut self) -> Option<(Box<[u8]>, Box<[u8]>)> { + fn next(&mut self) -> Option<(Box<[u8]>, Box<[u8]>)> { self.iter.next() } } @@ -94,7 +94,8 @@ impl Database { opts.set_max_background_compactions(4); opts.set_max_background_flushes(4); opts.set_filter_deletes(false); - opts.set_disable_auto_compactions(false);*/ + opts.set_disable_auto_compactions(false); + */ if let Some(size) = config.prefix_size { let mut block_opts = BlockBasedOptions::new(); @@ -107,27 +108,27 @@ impl Database { } /// Insert a key-value pair in the transaction. Any existing value value will be overwritten. - pub fn put(&self, key: &[u8], value: &[u8]) -> Result<(), String> { + pub fn put(&self, key: &[u8], value: &[u8]) -> Result<(), String> { self.db.put(key, value) } /// Delete value by key. - pub fn delete(&self, key: &[u8]) -> Result<(), String> { + pub fn delete(&self, key: &[u8]) -> Result<(), String> { self.db.delete(key) } /// Commit transaction to database. - pub fn write(&self, tr: DBTransaction) -> Result<(), String> { + pub fn write(&self, tr: DBTransaction) -> Result<(), String> { self.db.write(tr.batch) } /// Get value by key. - pub fn get(&self, key: &[u8]) -> Result, String> { + pub fn get(&self, key: &[u8]) -> Result, String> { self.db.get(key) } /// Get value by partial key. Prefix size should match configured prefix size. - pub fn get_by_prefix(&self, prefix: &[u8]) -> Option> { + pub fn get_by_prefix(&self, prefix: &[u8]) -> Option> { let mut iter = self.db.iterator(IteratorMode::From(prefix, Direction::forward)); match iter.next() { // TODO: use prefix_same_as_start read option (not availabele in C API currently) @@ -147,7 +148,6 @@ impl Database { } } - #[cfg(test)] mod tests { use hash::*;