Mercurial > lbo > hg > sstable
changeset 66:8ff0ebc7f63e
Apply formatting
author | Thomas Krause <krauseto@hu-berlin.de> |
---|---|
date | Mon, 17 Feb 2020 10:32:50 +0100 |
parents | 195a49887564 |
children | cf194f28e5ec |
files | examples/rw_sstable/src/main.rs src/cache.rs src/cmp.rs src/error.rs src/filter.rs src/filter_block.rs src/lib.rs src/table_block.rs src/table_builder.rs src/table_reader.rs src/test_util.rs src/types.rs |
diffstat | 12 files changed, 77 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/rw_sstable/src/main.rs Sun Feb 16 11:52:47 2020 +0100 +++ b/examples/rw_sstable/src/main.rs Mon Feb 17 10:32:50 2020 +0100 @@ -47,7 +47,8 @@ } fn lookup(t: &sstable::Table, key: &str) -> Result<Option<String>> { - Ok(t.get(key.as_bytes())?.map(|v| unsafe { String::from_utf8_unchecked(v) })) + Ok(t.get(key.as_bytes())? + .map(|v| unsafe { String::from_utf8_unchecked(v) })) } fn main() {
--- a/src/cache.rs Sun Feb 16 11:52:47 2020 +0100 +++ b/src/cache.rs Mon Feb 17 10:32:50 2020 +0100 @@ -239,8 +239,8 @@ #[cfg(test)] mod tests { + use super::LRUList; use super::*; - use super::LRUList; fn make_key(a: u8, b: u8, c: u8) -> CacheKey { [a, b, c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
--- a/src/cmp.rs Sun Feb 16 11:52:47 2020 +0100 +++ b/src/cmp.rs Mon Feb 17 10:32:50 2020 +0100 @@ -85,32 +85,54 @@ #[test] fn test_cmp_defaultcmp_shortest_sep() { - assert_eq!(DefaultCmp.find_shortest_sep("abcd".as_bytes(), "abcf".as_bytes()), - "abce".as_bytes()); - assert_eq!(DefaultCmp.find_shortest_sep("abc".as_bytes(), "acd".as_bytes()), - "abc\0".as_bytes()); - assert_eq!(DefaultCmp.find_shortest_sep("abcdefghi".as_bytes(), "abcffghi".as_bytes()), - "abce".as_bytes()); - assert_eq!(DefaultCmp.find_shortest_sep("a".as_bytes(), "a".as_bytes()), - "a".as_bytes()); - assert_eq!(DefaultCmp.find_shortest_sep("a".as_bytes(), "b".as_bytes()), - "a\0".as_bytes()); - assert_eq!(DefaultCmp.find_shortest_sep("abc".as_bytes(), "zzz".as_bytes()), - "b".as_bytes()); - assert_eq!(DefaultCmp.find_shortest_sep("yyy".as_bytes(), "z".as_bytes()), - "yyy\0".as_bytes()); - assert_eq!(DefaultCmp.find_shortest_sep("".as_bytes(), "".as_bytes()), - "".as_bytes()); + assert_eq!( + DefaultCmp.find_shortest_sep("abcd".as_bytes(), "abcf".as_bytes()), + "abce".as_bytes() + ); + assert_eq!( + DefaultCmp.find_shortest_sep("abc".as_bytes(), "acd".as_bytes()), + "abc\0".as_bytes() + ); + assert_eq!( + DefaultCmp.find_shortest_sep("abcdefghi".as_bytes(), "abcffghi".as_bytes()), + "abce".as_bytes() + ); + assert_eq!( + DefaultCmp.find_shortest_sep("a".as_bytes(), "a".as_bytes()), + "a".as_bytes() + ); + assert_eq!( + DefaultCmp.find_shortest_sep("a".as_bytes(), "b".as_bytes()), + "a\0".as_bytes() + ); + assert_eq!( + DefaultCmp.find_shortest_sep("abc".as_bytes(), "zzz".as_bytes()), + "b".as_bytes() + ); + assert_eq!( + DefaultCmp.find_shortest_sep("yyy".as_bytes(), "z".as_bytes()), + "yyy\0".as_bytes() + ); + assert_eq!( + DefaultCmp.find_shortest_sep("".as_bytes(), "".as_bytes()), + "".as_bytes() + ); } #[test] fn test_cmp_defaultcmp_short_succ() { - assert_eq!(DefaultCmp.find_short_succ("abcd".as_bytes()), - "b".as_bytes()); - assert_eq!(DefaultCmp.find_short_succ("zzzz".as_bytes()), - "{".as_bytes()); + assert_eq!( + DefaultCmp.find_short_succ("abcd".as_bytes()), + "b".as_bytes() + ); + assert_eq!( + DefaultCmp.find_short_succ("zzzz".as_bytes()), + "{".as_bytes() + ); assert_eq!(DefaultCmp.find_short_succ(&[]), &[0xff]); - assert_eq!(DefaultCmp.find_short_succ(&[0xff, 0xff, 0xff]), - &[0xff, 0xff, 0xff, 0xff]); + assert_eq!( + DefaultCmp.find_short_succ(&[0xff, 0xff, 0xff]), + &[0xff, 0xff, 0xff, 0xff] + ); } }
--- a/src/error.rs Sun Feb 16 11:52:47 2020 +0100 +++ b/src/error.rs Mon Feb 17 10:32:50 2020 +0100 @@ -106,4 +106,3 @@ pub fn err<T>(code: StatusCode, msg: &str) -> Result<T> { Err(Status::new(code, msg)) } -
--- a/src/filter.rs Sun Feb 16 11:52:47 2020 +0100 +++ b/src/filter.rs Mon Feb 17 10:32:50 2020 +0100 @@ -246,7 +246,8 @@ "xxx111xxx222".as_bytes(), "ab00cd00ab".as_bytes(), "908070605040302010".as_bytes(), - ].iter() + ] + .iter() { offs.push(concat.len()); concat.extend_from_slice(d);
--- a/src/filter_block.rs Sun Feb 16 11:52:47 2020 +0100 +++ b/src/filter_block.rs Mon Feb 17 10:32:50 2020 +0100 @@ -164,10 +164,10 @@ #[cfg(test)] mod tests { - use filter::BloomPolicy; + use super::get_filter_index; + use super::FILTER_BASE_LOG2; use super::*; - use super::FILTER_BASE_LOG2; - use super::get_filter_index; + use filter::BloomPolicy; #[test] fn test_filter_index() {
--- a/src/lib.rs Sun Feb 16 11:52:47 2020 +0100 +++ b/src/lib.rs Mon Feb 17 10:32:50 2020 +0100 @@ -23,9 +23,9 @@ pub use cmp::{Cmp, DefaultCmp}; pub use error::{Result, Status, StatusCode}; pub use options::{CompressionType, Options}; -pub use types::{current_key_val, SSIterator}; pub use table_builder::TableBuilder; pub use table_reader::{Table, TableIterator}; +pub use types::{current_key_val, SSIterator}; #[cfg(test)] mod test_util;
--- a/src/table_block.rs Sun Feb 16 11:52:47 2020 +0100 +++ b/src/table_block.rs Mon Feb 17 10:32:50 2020 +0100 @@ -36,7 +36,11 @@ /// Reads a table block from a random-access source. /// A table block consists of [bytes..., compress (1B), checksum (4B)]; the handle only refers to /// the location and length of [bytes...]. -pub fn read_table_block(opt: Options, f: &dyn RandomAccess, location: &BlockHandle) -> Result<Block> { +pub fn read_table_block( + opt: Options, + f: &dyn RandomAccess, + location: &BlockHandle, +) -> Result<Block> { // The block is denoted by offset and length in BlockHandle. A block in an encoded // table is followed by 1B compression type and 4B checksum. // The checksum refers to the compressed contents.
--- a/src/table_builder.rs Sun Feb 16 11:52:47 2020 +0100 +++ b/src/table_builder.rs Mon Feb 17 10:32:50 2020 +0100 @@ -125,9 +125,21 @@ #[allow(unused)] fn size_estimate(&self) -> usize { let mut size = 0; - size += self.data_block.as_ref().map(|b| b.size_estimate()).unwrap_or(0); - size += self.index_block.as_ref().map(|b| b.size_estimate()).unwrap_or(0); - size += self.filter_block.as_ref().map(|b| b.size_estimate()).unwrap_or(0); + size += self + .data_block + .as_ref() + .map(|b| b.size_estimate()) + .unwrap_or(0); + size += self + .index_block + .as_ref() + .map(|b| b.size_estimate()) + .unwrap_or(0); + size += self + .filter_block + .as_ref() + .map(|b| b.size_estimate()) + .unwrap_or(0); size += self.offset; size += FULL_FOOTER_LENGTH; size @@ -217,7 +229,8 @@ // If there's a pending data block, write it if self.data_block.as_ref().unwrap().entries() > 0 { // Find a key reliably past the last key - let key_past_last = self.opt + let key_past_last = self + .opt .cmp .find_short_succ(self.data_block.as_ref().unwrap().last_key()); self.write_data_block(&key_past_last)?;
--- a/src/table_reader.rs Sun Feb 16 11:52:47 2020 +0100 +++ b/src/table_reader.rs Mon Feb 17 10:32:50 2020 +0100 @@ -668,5 +668,4 @@ panic!("Should have hit 5th record in table!"); } } - }