summaryrefslogtreecommitdiffstats
path: root/src/indexer/delete_queue.rs
diff options
context:
space:
mode:
authorPaul Masurel <paul.masurel@gmail.com>2017-03-12 19:00:57 +0900
committerPaul Masurel <paul.masurel@gmail.com>2017-03-12 19:00:57 +0900
commit202dda98ba6fe4ca68d333e537d5553486143547 (patch)
tree745df22b24d340476b5b848ee2a467fe21bf0586 /src/indexer/delete_queue.rs
parent7c971b5d3b79b601ba69a0725cb6002b79b06de0 (diff)
baby step 3
Diffstat (limited to 'src/indexer/delete_queue.rs')
-rw-r--r--src/indexer/delete_queue.rs33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/indexer/delete_queue.rs b/src/indexer/delete_queue.rs
index beb0266..0286454 100644
--- a/src/indexer/delete_queue.rs
+++ b/src/indexer/delete_queue.rs
@@ -16,9 +16,32 @@ pub struct DeleteCursor {
}
impl DeleteCursor {
- pub fn go_to_tail(&mut self,) {
+
+ pub fn skip_to(&mut self, target_opstamp: u64) {
+ while let Some(operation) = self.peek() {
+ if operation.opstamp >= target_opstamp {
+ break;
+ }
+ self.advance()
+ }
+ }
+
+ pub fn advance(&mut self) {
let read = self.operations.read().unwrap();
- self.cursor = read.len();
+ if self.cursor < read.len() {
+ self.cursor += 1;
+ }
+ }
+
+ pub fn peek(&self,) -> Option<DeleteOperation> {
+ let read = self.operations.read().unwrap();
+ if self.cursor >= read.len() {
+ None
+ }
+ else {
+ let operation = read[self.cursor].clone();
+ Some(operation)
+ }
}
}
@@ -40,6 +63,7 @@ impl Iterator for DeleteCursor {
}
}
+
#[derive(Clone, Default)]
pub struct DeleteQueue(InnerDeleteQueue);
@@ -53,10 +77,6 @@ impl DeleteQueue {
self.0.write().unwrap().push(delete_operation);
}
- pub fn clear(&mut self) {
- self.0.write().unwrap().clear();
- }
-
pub fn cursor(&self) -> DeleteCursor {
DeleteCursor {
cursor: 0,
@@ -65,6 +85,7 @@ impl DeleteQueue {
}
}
+
#[cfg(test)]
mod tests {