Mercurial > lbo > hg > leveldb-rs
view src/test_util.rs @ 97:4754dd356f5e
Fix several bugs in the Table*/Block implementations
1. Calculate correct number of restarts, even if it is 0
2. Use correct slice length when encoding the value length
3. Remove a weird duplicate implementation of Footer that I wrote for no reason
4. Move non-method functions out of Table
5. Don't try to read a filter block as ordinary block
6. Add tests for TableIterator
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sun, 25 Sep 2016 12:32:45 +0200 |
parents | 89810ac42bd1 |
children | 6147b3a3eeea |
line wrap: on
line source
use types::LdbIterator; use types::Comparator; use types::StandardComparator; use std::cmp::Ordering; pub struct TestLdbIter<'a> { v: Vec<(&'a [u8], &'a [u8])>, ix: usize, init: bool, } impl<'a> TestLdbIter<'a> { pub fn new(c: Vec<(&'a [u8], &'a [u8])>) -> TestLdbIter<'a> { return TestLdbIter { v: c, ix: 0, init: false, }; } } impl<'a> Iterator for TestLdbIter<'a> { type Item = (&'a [u8], &'a [u8]); fn next(&mut self) -> Option<Self::Item> { if self.ix == self.v.len() { return None; } else if !self.init { self.init = true; Some(self.v[self.ix]) } else { self.ix += 1; Some(self.v[self.ix - 1]) } } } impl<'a> LdbIterator for TestLdbIter<'a> { fn reset(&mut self) { self.ix = 0; self.init = false; } fn current(&self) -> Option<Self::Item> { if self.init && self.ix < self.v.len() { Some(self.v[self.ix]) } else { None } } fn valid(&self) -> bool { self.init } fn seek(&mut self, k: &[u8]) { self.ix = 0; while self.ix < self.v.len() && StandardComparator.cmp(self.v[self.ix].0, k) == Ordering::Less { self.ix += 1; } } fn prev(&mut self) -> Option<Self::Item> { if !self.init || self.ix == 0 { None } else { self.ix -= 1; Some(self.v[self.ix]) } } }