differential_dataflow/trace/cursor/
mod.rs1pub mod cursor_list;
9
10pub use self::cursor_list::CursorList;
11
12use std::borrow::Borrow;
13use std::cmp::Ordering;
14
15pub trait MyTrait<'a> : Ord {
20 type Owned;
22 fn into_owned(self) -> Self::Owned;
24 fn clone_onto(&self, other: &mut Self::Owned);
26 fn compare(&self, other: &Self::Owned) -> Ordering;
28 fn less_equals(&self, other: &Self::Owned) -> bool {
30 self.compare(other) != Ordering::Greater
31 }
32 fn equals(&self, other: &Self::Owned) -> bool {
34 self.compare(other) == Ordering::Equal
35 }
36 fn less_than(&self, other: &Self::Owned) -> bool {
38 self.compare(other) == Ordering::Less
39 }
40 fn borrow_as(other: &'a Self::Owned) -> Self;
42}
43
44impl<'a, T: Ord+ToOwned+?Sized> MyTrait<'a> for &'a T {
45 type Owned = T::Owned;
46 fn into_owned(self) -> Self::Owned { self.to_owned() }
47 fn clone_onto(&self, other: &mut Self::Owned) { <T as ToOwned>::clone_into(self, other) }
48 fn compare(&self, other: &Self::Owned) -> Ordering { self.cmp(&other.borrow()) }
49 fn borrow_as(other: &'a Self::Owned) -> Self {
50 other.borrow()
51 }
52}
53
54pub trait Cursor {
56
57 type Key<'a>: Copy + Clone + MyTrait<'a, Owned = Self::KeyOwned>;
59 type KeyOwned: Ord + Clone;
61 type Val<'a>: Copy + Clone + MyTrait<'a, Owned = Self::ValOwned> + for<'b> PartialOrd<Self::Val<'b>>;
63 type ValOwned: Ord + Clone;
65 type Time;
67 type Diff: ?Sized;
69
70 type Storage;
72
73 fn key_valid(&self, storage: &Self::Storage) -> bool;
77 fn val_valid(&self, storage: &Self::Storage) -> bool;
81
82 fn key<'a>(&self, storage: &'a Self::Storage) -> Self::Key<'a>;
84 fn val<'a>(&self, storage: &'a Self::Storage) -> Self::Val<'a>;
86
87 fn get_key<'a>(&self, storage: &'a Self::Storage) -> Option<Self::Key<'a>> {
89 if self.key_valid(storage) { Some(self.key(storage)) } else { None }
90 }
91 fn get_val<'a>(&self, storage: &'a Self::Storage) -> Option<Self::Val<'a>> {
93 if self.val_valid(storage) { Some(self.val(storage)) } else { None }
94 }
95
96 fn map_times<L: FnMut(&Self::Time, &Self::Diff)>(&mut self, storage: &Self::Storage, logic: L);
99
100 fn step_key(&mut self, storage: &Self::Storage);
102 fn seek_key(&mut self, storage: &Self::Storage, key: Self::Key<'_>);
104 fn seek_key_owned(&mut self, storage: &Self::Storage, key: &Self::KeyOwned) {
106 self.seek_key(storage, MyTrait::borrow_as(key));
107 }
108
109 fn step_val(&mut self, storage: &Self::Storage);
111 fn seek_val(&mut self, storage: &Self::Storage, val: Self::Val<'_>);
113
114 fn rewind_keys(&mut self, storage: &Self::Storage);
116 fn rewind_vals(&mut self, storage: &Self::Storage);
118
119 fn to_vec(&mut self, storage: &Self::Storage) -> Vec<((Self::KeyOwned, Self::ValOwned), Vec<(Self::Time, Self::Diff)>)>
121 where
122 Self::Time: Clone,
123 Self::Diff: Clone,
124 {
125 let mut out = Vec::new();
126 self.rewind_keys(storage);
127 self.rewind_vals(storage);
128 while self.key_valid(storage) {
129 while self.val_valid(storage) {
130 let mut kv_out = Vec::new();
131 self.map_times(storage, |ts, r| {
132 kv_out.push((ts.clone(), r.clone()));
133 });
134 out.push(((self.key(storage).into_owned(), self.val(storage).into_owned()), kv_out));
135 self.step_val(storage);
136 }
137 self.step_key(storage);
138 }
139 out
140 }
141}