hoist iterator modes; group fns
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
df7a1dee15
commit
7db8478dc0
1 changed files with 21 additions and 25 deletions
|
@ -130,28 +130,37 @@ impl Map {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_from<'a>(&'a self, from: &[u8], backwards: bool) -> Box<dyn Iterator<Item = KeyVal> + 'a> {
|
pub fn iter_from<'a>(&'a self, from: &[u8], backwards: bool) -> Box<dyn Iterator<Item = KeyVal> + 'a> {
|
||||||
|
let direction = if backwards {
|
||||||
|
Direction::Reverse
|
||||||
|
} else {
|
||||||
|
Direction::Forward
|
||||||
|
};
|
||||||
|
let mode = IteratorMode::From(from, direction);
|
||||||
let read_options = read_options_default();
|
let read_options = read_options_default();
|
||||||
let it = self
|
let it = self
|
||||||
.db
|
.db
|
||||||
.db
|
.db
|
||||||
.iterator_cf_opt(
|
.iterator_cf_opt(&self.cf(), read_options, mode)
|
||||||
&self.cf(),
|
|
||||||
read_options,
|
|
||||||
IteratorMode::From(
|
|
||||||
from,
|
|
||||||
if backwards {
|
|
||||||
Direction::Reverse
|
|
||||||
} else {
|
|
||||||
Direction::Forward
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.map(Result::unwrap)
|
.map(Result::unwrap)
|
||||||
.map(|(k, v)| (Vec::from(k), Vec::from(v)));
|
.map(|(k, v)| (Vec::from(k), Vec::from(v)));
|
||||||
|
|
||||||
Box::new(it)
|
Box::new(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn scan_prefix<'a>(&'a self, prefix: Vec<u8>) -> Box<dyn Iterator<Item = KeyVal> + 'a> {
|
||||||
|
let mode = IteratorMode::From(&prefix, Direction::Forward);
|
||||||
|
let read_options = read_options_default();
|
||||||
|
let it = self
|
||||||
|
.db
|
||||||
|
.db
|
||||||
|
.iterator_cf_opt(&self.cf(), read_options, mode)
|
||||||
|
.map(Result::unwrap)
|
||||||
|
.map(|(k, v)| (Vec::from(k), Vec::from(v)))
|
||||||
|
.take_while(move |(k, _)| k.starts_with(&prefix));
|
||||||
|
|
||||||
|
Box::new(it)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn increment(&self, key: &[u8]) -> Result<Vec<u8>> {
|
pub fn increment(&self, key: &[u8]) -> Result<Vec<u8>> {
|
||||||
let read_options = &self.read_options;
|
let read_options = &self.read_options;
|
||||||
let old = self
|
let old = self
|
||||||
|
@ -202,19 +211,6 @@ impl Map {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scan_prefix<'a>(&'a self, prefix: Vec<u8>) -> Box<dyn Iterator<Item = KeyVal> + 'a> {
|
|
||||||
let read_options = read_options_default();
|
|
||||||
let it = self
|
|
||||||
.db
|
|
||||||
.db
|
|
||||||
.iterator_cf_opt(&self.cf(), read_options, IteratorMode::From(&prefix, Direction::Forward))
|
|
||||||
.map(Result::unwrap)
|
|
||||||
.map(|(k, v)| (Vec::from(k), Vec::from(v)))
|
|
||||||
.take_while(move |(k, _)| k.starts_with(&prefix));
|
|
||||||
|
|
||||||
Box::new(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn watch_prefix<'a>(&'a self, prefix: &[u8]) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>> {
|
pub fn watch_prefix<'a>(&'a self, prefix: &[u8]) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>> {
|
||||||
self.watchers.watch(prefix)
|
self.watchers.watch(prefix)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue