mirror of
https://github.com/romanz/electrs.git
synced 2025-02-23 14:50:45 +01:00
Add scanning DBStore prefix iterator
This commit is contained in:
parent
698156eb6e
commit
e300796fc2
1 changed files with 33 additions and 0 deletions
33
src/store.rs
33
src/store.rs
|
@ -94,6 +94,39 @@ impl DBStore {
|
|||
info!("finished full compaction");
|
||||
store
|
||||
}
|
||||
|
||||
pub fn iter_scan(&self, prefix: &[u8]) -> ScanIterator {
|
||||
ScanIterator {
|
||||
prefix: prefix.to_vec(),
|
||||
iter: self.db.prefix_iterator(prefix),
|
||||
done: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ScanIterator {
|
||||
prefix: Vec<u8>,
|
||||
iter: rocksdb::DBIterator,
|
||||
done: bool,
|
||||
}
|
||||
|
||||
impl Iterator for ScanIterator {
|
||||
type Item = Row;
|
||||
|
||||
fn next(&mut self) -> Option<Row> {
|
||||
if self.done {
|
||||
return None;
|
||||
}
|
||||
let (key, value) = self.iter.next()?;
|
||||
if !key.starts_with(&self.prefix) {
|
||||
self.done = true;
|
||||
return None;
|
||||
}
|
||||
Some(Row {
|
||||
key: key.to_vec(),
|
||||
value: value.to_vec(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ReadStore for DBStore {
|
||||
|
|
Loading…
Add table
Reference in a new issue