Mercurial > lbo > hg > leveldb-rs
changeset 127:400a8eee617c
Fix some subtle bugs in the two-level seeking logic in TableIterator
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sat, 31 Dec 2016 18:29:54 +0100 |
parents | 66c13972d977 |
children | 566a0f423512 |
files | src/block.rs src/cmp.rs src/table_reader.rs |
diffstat | 3 files changed, 5 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/block.rs Sat Dec 31 17:42:02 2016 +0100 +++ b/src/block.rs Sat Dec 31 18:29:54 2016 +0100 @@ -212,12 +212,12 @@ // At a restart, the shared part is supposed to be 0. assert_eq!(shared, 0); - let c = self.opt.cmp.cmp(to, &self.block[self.offset..self.offset + non_shared]); + let c = self.opt.cmp.cmp(&self.block[self.offset..self.offset + non_shared], to); if c == Ordering::Less { - right = middle - 1; + left = middle; } else { - left = middle; + right = middle - 1; } }
--- a/src/cmp.rs Sat Dec 31 17:42:02 2016 +0100 +++ b/src/cmp.rs Sat Dec 31 18:29:54 2016 +0100 @@ -44,11 +44,7 @@ diff_at += 1; } - // extend one slice by a 0 byte - // e.g. abc/abd => abc abc\0 abd - let mut r = Vec::from(a); - r.extend_from_slice(&[0x00]); - return r; + return a.to_vec(); } fn find_short_succ(&self, a: &[u8]) -> Vec<u8> {
--- a/src/table_reader.rs Sat Dec 31 17:42:02 2016 +0100 +++ b/src/table_reader.rs Sat Dec 31 18:29:54 2016 +0100 @@ -290,7 +290,7 @@ self.index_block.seek(to); if let Some((past_block, handle)) = self.index_block.current() { - if self.opt.cmp.cmp(to, &past_block) == Ordering::Less { + if self.opt.cmp.cmp(to, &past_block) <= Ordering::Equal { // ok, found right block: continue if let Ok(()) = self.load_block(&handle) { self.current_block.seek(to);