pub mod cursor_empty;
pub mod cursor_group;
pub mod cursor_list;
pub mod cursor_pair;
pub mod cursor_with_polarity;
mod reverse;
pub mod saturating_cursor;
use std::{fmt::Debug, marker::PhantomData};
pub use cursor_empty::CursorEmpty;
pub use cursor_group::CursorGroup;
pub use cursor_list::CursorList;
pub use cursor_pair::CursorPair;
pub use cursor_with_polarity::CursorWithPolarity;
pub use saturating_cursor::SaturatingCursor;
pub use reverse::ReverseKeyCursor;
use size_of::SizeOf;
use crate::dynamic::{DataTrait, Factory};
use super::BatchReader;
use super::{Filter, GroupFilter};
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
enum Direction {
Forward,
Backward,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Position {
pub total: u64,
pub offset: u64,
}
pub trait Cursor<K: ?Sized, V: ?Sized, T, R: ?Sized> {
fn weight_factory(&self) -> &'static dyn Factory<R>;
fn key_valid(&self) -> bool;
fn val_valid(&self) -> bool;
fn key(&self) -> &K;
fn val(&self) -> &V;
fn get_key(&self) -> Option<&K> {
if self.key_valid() {
Some(self.key())
} else {
None
}
}
fn get_val(&self) -> Option<&V> {
if self.val_valid() {
Some(self.val())
} else {
None
}
}
fn map_times(&mut self, logic: &mut dyn FnMut(&T, &R));
fn map_times_through(&mut self, upper: &T, logic: &mut dyn FnMut(&T, &R));
fn weight(&mut self) -> &R
where
T: PartialEq<()>;
fn weight_checked(&mut self) -> &R;
fn map_values(&mut self, logic: &mut dyn FnMut(&V, &R))
where
T: PartialEq<()>;
fn step_key(&mut self);
fn step_key_reverse(&mut self);
fn seek_key(&mut self, key: &K);
fn seek_key_exact(&mut self, key: &K, hash: Option<u64>) -> bool;
fn seek_key_with(&mut self, predicate: &dyn Fn(&K) -> bool);
fn seek_key_with_reverse(&mut self, predicate: &dyn Fn(&K) -> bool);
fn seek_key_reverse(&mut self, key: &K);
fn step_val(&mut self);
fn step_val_reverse(&mut self);
fn seek_val(&mut self, val: &V);
fn seek_val_reverse(&mut self, val: &V);
fn seek_val_with(&mut self, predicate: &dyn Fn(&V) -> bool);
fn seek_val_with_reverse(&mut self, predicate: &dyn Fn(&V) -> bool);
fn rewind_keys(&mut self);
fn fast_forward_keys(&mut self);
fn rewind_vals(&mut self);
fn fast_forward_vals(&mut self);
fn keyval_valid(&self) -> bool {
self.key_valid() && self.val_valid()
}
fn keyval(&self) -> (&K, &V) {
(self.key(), self.val())
}
fn step_keyval(&mut self) {
self.step_val();
while self.key_valid() && !self.val_valid() {
self.step_key();
}
}
fn step_keyval_reverse(&mut self) {
self.step_val_reverse();
while self.key_valid() && !self.val_valid() {
self.step_key_reverse();
if self.key_valid() {
self.fast_forward_vals();
}
}
}
fn seek_keyval(&mut self, key: &K, val: &V)
where
K: PartialEq,
{
if self.get_key() != Some(key) {
self.seek_key(key);
}
if self.get_key() == Some(key) {
self.seek_val(val);
}
while self.key_valid() && !self.val_valid() {
self.step_key();
}
}
fn seek_keyval_reverse(&mut self, key: &K, val: &V)
where
K: PartialEq,
{
if self.get_key() != Some(key) {
self.seek_key_reverse(key);
if self.key_valid() {
self.fast_forward_vals();
}
}
if self.get_key() == Some(key) {
self.seek_val_reverse(val);
}
while self.key_valid() && !self.val_valid() {
self.step_key_reverse();
if self.key_valid() {
self.fast_forward_vals();
}
}
}
fn position(&self) -> Option<Position>;
}
pub trait CursorFactory<K: ?Sized, V: ?Sized, T, R: ?Sized> {
fn get_cursor<'a>(&'a self) -> Box<dyn Cursor<K, V, T, R> + 'a>;
}
impl<K: ?Sized, V: ?Sized, T, R: ?Sized, B> CursorFactory<K, V, T, R> for &B
where
B: BatchReader<Key = K, Val = V, Time = T, R = R>,
{
fn get_cursor<'a>(&'a self) -> Box<dyn Cursor<K, V, T, R> + 'a> {
Box::new(self.cursor())
}
}
pub struct CursorFactoryWrapper<B>(pub B);
impl<K: ?Sized, V: ?Sized, T, R: ?Sized, B> CursorFactory<K, V, T, R> for CursorFactoryWrapper<B>
where
B: BatchReader<Key = K, Val = V, Time = T, R = R>,
{
fn get_cursor<'a>(&'a self) -> Box<dyn Cursor<K, V, T, R> + 'a> {
Box::new(self.0.cursor())
}
}
pub trait ClonableCursor<'s, K, V, T, R>: Cursor<K, V, T, R> + Debug
where
K: ?Sized,
V: ?Sized,
R: ?Sized,
{
fn clone_boxed(&self) -> Box<dyn ClonableCursor<'s, K, V, T, R> + Send + 's>;
}
impl<'s, K, V, T, R, C> ClonableCursor<'s, K, V, T, R> for C
where
K: ?Sized,
V: ?Sized,
R: ?Sized,
C: Cursor<K, V, T, R> + Debug + Clone + Send + 's,
{
fn clone_boxed(&self) -> Box<dyn ClonableCursor<'s, K, V, T, R> + Send + 's> {
Box::new(self.clone())
}
}
impl<K, V, T, R, C> Cursor<K, V, T, R> for Box<C>
where
K: ?Sized,
V: ?Sized,
R: ?Sized,
C: Cursor<K, V, T, R> + ?Sized,
{
fn weight_factory(&self) -> &'static dyn Factory<R> {
(**self).weight_factory()
}
fn key_valid(&self) -> bool {
(**self).key_valid()
}
fn val_valid(&self) -> bool {
(**self).val_valid()
}
fn key(&self) -> &K {
(**self).key()
}
fn val(&self) -> &V {
(**self).val()
}
fn map_times(&mut self, logic: &mut dyn FnMut(&T, &R)) {
(**self).map_times(logic)
}
fn map_times_through(&mut self, upper: &T, logic: &mut dyn FnMut(&T, &R)) {
(**self).map_times_through(upper, logic)
}
fn weight(&mut self) -> &R
where
T: PartialEq<()>,
{
(**self).weight()
}
fn weight_checked(&mut self) -> &R {
(**self).weight_checked()
}
fn map_values(&mut self, logic: &mut dyn FnMut(&V, &R))
where
T: PartialEq<()>,
{
(**self).map_values(logic)
}
fn step_key(&mut self) {
(**self).step_key()
}
fn step_key_reverse(&mut self) {
(**self).step_key_reverse()
}
fn seek_key(&mut self, key: &K) {
(**self).seek_key(key)
}
fn seek_key_exact(&mut self, key: &K, hash: Option<u64>) -> bool {
(**self).seek_key_exact(key, hash)
}
fn seek_key_with(&mut self, predicate: &dyn Fn(&K) -> bool) {
(**self).seek_key_with(predicate)
}
fn seek_key_with_reverse(&mut self, predicate: &dyn Fn(&K) -> bool) {
(**self).seek_key_with_reverse(predicate)
}
fn seek_key_reverse(&mut self, key: &K) {
(**self).seek_key_reverse(key)
}
fn step_val(&mut self) {
(**self).step_val()
}
fn step_val_reverse(&mut self) {
(**self).step_val_reverse()
}
fn seek_val(&mut self, val: &V) {
(**self).seek_val(val)
}
fn seek_val_reverse(&mut self, val: &V) {
(**self).seek_val_reverse(val)
}
fn seek_val_with(&mut self, predicate: &dyn Fn(&V) -> bool) {
(**self).seek_val_with(predicate)
}
fn seek_val_with_reverse(&mut self, predicate: &dyn Fn(&V) -> bool) {
(**self).seek_val_with_reverse(predicate)
}
fn rewind_keys(&mut self) {
(**self).rewind_keys()
}
fn fast_forward_keys(&mut self) {
(**self).fast_forward_keys()
}
fn rewind_vals(&mut self) {
(**self).rewind_vals()
}
fn fast_forward_vals(&mut self) {
(**self).fast_forward_vals()
}
fn get_key(&self) -> Option<&K> {
(**self).get_key()
}
fn get_val(&self) -> Option<&V> {
(**self).get_val()
}
fn keyval_valid(&self) -> bool {
(**self).keyval_valid()
}
fn keyval(&self) -> (&K, &V) {
(**self).keyval()
}
fn step_keyval(&mut self) {
(**self).step_keyval()
}
fn step_keyval_reverse(&mut self) {
(**self).step_keyval_reverse()
}
fn seek_keyval(&mut self, key: &K, val: &V)
where
K: PartialEq,
{
(**self).seek_keyval(key, val)
}
fn seek_keyval_reverse(&mut self, key: &K, val: &V)
where
K: PartialEq,
{
(**self).seek_keyval_reverse(key, val)
}
fn position(&self) -> Option<Position> {
(**self).position()
}
}
#[derive(Debug, SizeOf)]
pub struct DelegatingCursor<'s, K, V, T, R>(
pub Box<dyn ClonableCursor<'s, K, V, T, R> + Send + 's>,
)
where
K: ?Sized,
V: ?Sized,
R: ?Sized;
impl<K, V, T, R> Clone for DelegatingCursor<'_, K, V, T, R>
where
K: ?Sized,
V: ?Sized,
R: ?Sized,
{
fn clone(&self) -> Self {
Self(self.0.clone_boxed())
}
}
impl<K, V, T, R> Cursor<K, V, T, R> for DelegatingCursor<'_, K, V, T, R>
where
K: ?Sized,
V: ?Sized,
R: ?Sized,
{
fn weight_factory(&self) -> &'static dyn Factory<R> {
self.0.weight_factory()
}
fn key(&self) -> &K {
self.0.key()
}
fn val(&self) -> &V {
self.0.val()
}
fn map_times(&mut self, logic: &mut dyn FnMut(&T, &R)) {
self.0.map_times(logic)
}
fn map_times_through(&mut self, upper: &T, logic: &mut dyn FnMut(&T, &R)) {
self.0.map_times_through(upper, logic)
}
fn map_values(&mut self, logic: &mut dyn FnMut(&V, &R))
where
T: PartialEq<()>,
{
self.0.map_values(logic)
}
fn weight(&mut self) -> &R
where
T: PartialEq<()>,
{
self.0.weight()
}
fn weight_checked(&mut self) -> &R {
self.0.weight_checked()
}
fn key_valid(&self) -> bool {
self.0.key_valid()
}
fn val_valid(&self) -> bool {
self.0.val_valid()
}
fn step_key(&mut self) {
self.0.step_key()
}
fn step_key_reverse(&mut self) {
self.0.step_key_reverse()
}
fn seek_key(&mut self, key: &K) {
self.0.seek_key(key)
}
fn seek_key_exact(&mut self, key: &K, hash: Option<u64>) -> bool {
self.0.seek_key_exact(key, hash)
}
fn seek_key_with(&mut self, predicate: &dyn Fn(&K) -> bool) {
self.0.seek_key_with(predicate)
}
fn seek_key_with_reverse(&mut self, predicate: &dyn Fn(&K) -> bool) {
self.0.seek_key_with_reverse(predicate)
}
fn seek_key_reverse(&mut self, key: &K) {
self.0.seek_key_reverse(key)
}
fn step_val(&mut self) {
self.0.step_val()
}
fn seek_val(&mut self, val: &V) {
self.0.seek_val(val)
}
fn seek_val_with(&mut self, predicate: &dyn Fn(&V) -> bool) {
self.0.seek_val_with(predicate)
}
fn rewind_keys(&mut self) {
self.0.rewind_keys()
}
fn fast_forward_keys(&mut self) {
self.0.fast_forward_keys()
}
fn rewind_vals(&mut self) {
self.0.rewind_vals()
}
fn step_val_reverse(&mut self) {
self.0.step_val_reverse()
}
fn seek_val_reverse(&mut self, val: &V) {
self.0.seek_val_reverse(val)
}
fn seek_val_with_reverse(&mut self, predicate: &dyn Fn(&V) -> bool) {
self.0.seek_val_with_reverse(predicate)
}
fn fast_forward_vals(&mut self) {
self.0.fast_forward_vals()
}
fn position(&self) -> Option<Position> {
self.0.position()
}
}
pub trait MergeCursor<K, V, T, R>
where
K: ?Sized,
V: ?Sized,
R: ?Sized,
{
fn key_valid(&self) -> bool;
fn val_valid(&self) -> bool;
fn get_key(&self) -> Option<&K> {
self.key_valid().then(|| self.key())
}
fn get_val(&self) -> Option<&V> {
self.val_valid().then(|| self.val())
}
fn key(&self) -> &K;
fn val(&self) -> &V;
fn map_times(&mut self, logic: &mut dyn FnMut(&T, &R));
fn weight(&mut self) -> &R
where
T: PartialEq<()>;
fn step_key(&mut self);
fn step_val(&mut self);
fn has_mut(&self) -> bool {
false
}
fn key_mut(&mut self) -> &mut K {
unimplemented!("used key_mut() on batch that does not support it")
}
fn val_mut(&mut self) -> &mut V {
unimplemented!("used val_mut() on batch that does not support it")
}
fn weight_mut(&mut self) -> &mut R
where
T: PartialEq<()>,
{
unimplemented!("used weight_mut() on batch that does not support it")
}
}
impl<K, V, T, R, C> MergeCursor<K, V, T, R> for Box<C>
where
C: MergeCursor<K, V, T, R> + ?Sized,
K: ?Sized,
V: ?Sized,
R: ?Sized,
{
fn key_valid(&self) -> bool {
(**self).key_valid()
}
fn val_valid(&self) -> bool {
(**self).val_valid()
}
fn key(&self) -> &K {
(**self).key()
}
fn val(&self) -> &V {
(**self).val()
}
fn map_times(&mut self, logic: &mut dyn FnMut(&T, &R)) {
(**self).map_times(logic)
}
fn weight(&mut self) -> &R
where
T: PartialEq<()>,
{
(**self).weight()
}
fn step_key(&mut self) {
(**self).step_key()
}
fn step_val(&mut self) {
(**self).step_val()
}
fn has_mut(&self) -> bool {
(**self).has_mut()
}
fn key_mut(&mut self) -> &mut K {
(**self).key_mut()
}
fn val_mut(&mut self) -> &mut V {
(**self).val_mut()
}
fn weight_mut(&mut self) -> &mut R
where
T: PartialEq<()>,
{
(**self).weight_mut()
}
}
pub struct FilteredMergeCursor<K, V, T, R, C>
where
K: ?Sized,
V: ?Sized + 'static,
R: ?Sized,
C: Cursor<K, V, T, R>,
{
cursor: C,
key_filter: Option<Filter<K>>,
value_filter: Option<Filter<V>>,
phantom: PhantomData<(T, Box<R>)>,
}
impl<K, V, T, R, C> FilteredMergeCursor<K, V, T, R, C>
where
K: ?Sized + 'static,
V: DataTrait + ?Sized,
R: ?Sized + 'static,
C: Cursor<K, V, T, R>,
T: 'static,
{
pub fn new(
mut cursor: C,
key_filter: Option<Filter<K>>,
value_filter: Option<Filter<V>>,
) -> Self {
Self::skip_filtered_keys(&mut cursor, &key_filter, &value_filter);
Self {
cursor,
key_filter,
value_filter,
phantom: PhantomData,
}
}
fn skip_filtered_keys(
cursor: &mut C,
key_filter: &Option<Filter<K>>,
value_filter: &Option<Filter<V>>,
) {
while let Some(key) = cursor.get_key() {
if Filter::include(key_filter, key) && Self::skip_filtered_values(cursor, value_filter)
{
return;
} else {
cursor.step_key();
}
}
}
fn skip_filtered_values(cursor: &mut C, value_filter: &Option<Filter<V>>) -> bool {
while let Some(val) = cursor.get_val() {
if Filter::include(value_filter, val) {
return true;
}
cursor.step_val();
}
false
}
}
impl<K, V, T, R, C> MergeCursor<K, V, T, R> for FilteredMergeCursor<K, V, T, R, C>
where
K: ?Sized + 'static,
V: DataTrait + ?Sized,
R: ?Sized + 'static,
T: 'static,
C: Cursor<K, V, T, R>,
{
fn key_valid(&self) -> bool {
self.cursor.key_valid()
}
fn val_valid(&self) -> bool {
self.cursor.val_valid()
}
fn key(&self) -> &K {
self.cursor.key()
}
fn val(&self) -> &V {
self.cursor.val()
}
fn step_key(&mut self) {
self.cursor.step_key();
Self::skip_filtered_keys(&mut self.cursor, &self.key_filter, &self.value_filter);
}
fn step_val(&mut self) {
self.cursor.step_val();
Self::skip_filtered_values(&mut self.cursor, &self.value_filter);
}
fn map_times(&mut self, logic: &mut dyn FnMut(&T, &R)) {
self.cursor.map_times(logic);
}
fn weight(&mut self) -> &R
where
T: PartialEq<()>,
{
self.cursor.weight()
}
}
pub struct FilteredMergeCursorWithSnapshot<'a, K, V, T, R, C>
where
K: ?Sized,
V: ?Sized + 'static,
R: ?Sized,
C: Cursor<K, V, T, R>,
{
cursor: C,
trace_cursor: Box<dyn Cursor<K, V, T, R> + Send + 'a>,
key_filter: Option<Filter<K>>,
value_filter: GroupFilterCursor<V>,
phantom: PhantomData<(T, Box<R>)>,
}
impl<'a, K, V, T, R, C> FilteredMergeCursorWithSnapshot<'a, K, V, T, R, C>
where
K: ?Sized + 'static,
V: DataTrait + ?Sized,
R: ?Sized + 'static,
C: Cursor<K, V, T, R>,
T: 'static,
{
pub fn new<S>(
cursor: C,
key_filter: Option<Filter<K>>,
value_filter: GroupFilter<V>,
snapshot: &'a S,
) -> Self
where
S: BatchReader<Key = K, Val = V, Time = T, R = R>,
{
let trace_cursor = Box::new(snapshot.cursor());
let value_filter = value_filter.new_cursor();
let mut result = Self {
cursor,
trace_cursor,
key_filter,
value_filter,
phantom: PhantomData,
};
result.skip_filtered_keys();
result
}
fn skip_filtered_keys(&mut self) {
while let Some(key) = self.cursor.get_key() {
if Filter::include(&self.key_filter, key)
&& self
.value_filter
.on_step_key(&mut self.cursor, &mut self.trace_cursor)
{
return;
} else {
self.cursor.step_key();
}
}
}
fn skip_filtered_values(&mut self) {
self.value_filter
.on_step_val(&mut self.cursor, &mut self.trace_cursor);
}
}
impl<'a, K, V, T, R, C> MergeCursor<K, V, T, R>
for FilteredMergeCursorWithSnapshot<'a, K, V, T, R, C>
where
K: ?Sized + 'static,
V: DataTrait + ?Sized,
R: ?Sized + 'static,
T: 'static,
C: Cursor<K, V, T, R>,
{
fn key_valid(&self) -> bool {
self.cursor.key_valid()
}
fn val_valid(&self) -> bool {
self.cursor.val_valid()
}
fn key(&self) -> &K {
self.cursor.key()
}
fn val(&self) -> &V {
self.cursor.val()
}
fn step_key(&mut self) {
self.cursor.step_key();
self.skip_filtered_keys();
}
fn step_val(&mut self) {
self.cursor.step_val();
self.skip_filtered_values();
}
fn map_times(&mut self, logic: &mut dyn FnMut(&T, &R)) {
self.cursor.map_times(logic);
}
fn weight(&mut self) -> &R
where
T: PartialEq<()>,
{
self.cursor.weight()
}
}
impl<V: DataTrait + ?Sized> GroupFilter<V> {
fn new_cursor(&self) -> GroupFilterCursor<V> {
match self {
Self::Simple(filter) => GroupFilterCursor::Simple {
filter: filter.clone(),
},
Self::LastN(n, filter) => GroupFilterCursor::LastN {
n: *n,
filter: filter.clone(),
},
Self::TopN(n, filter, val_factory) => GroupFilterCursor::TopN {
n: *n,
filter: filter.clone(),
min_val: val_factory.default_box(),
min_val_valid: false,
},
Self::BottomN(n, filter, val_factory) => GroupFilterCursor::BottomN {
n: *n,
filter: filter.clone(),
max_val: val_factory.default_box(),
max_val_valid: false,
},
}
}
}
enum GroupFilterCursor<V: ?Sized> {
Simple {
filter: Filter<V>,
},
LastN {
n: usize,
filter: Filter<V>,
},
TopN {
n: usize,
filter: Filter<V>,
min_val: Box<V>,
min_val_valid: bool,
},
BottomN {
n: usize,
filter: Filter<V>,
max_val: Box<V>,
max_val_valid: bool,
},
}
impl<V: DataTrait + ?Sized> GroupFilterCursor<V> {
fn on_step_key<K: ?Sized, T, R: ?Sized>(
&mut self,
cursor: &mut dyn Cursor<K, V, T, R>,
trace_cursor: &mut dyn Cursor<K, V, T, R>,
) -> bool {
if !trace_cursor.seek_key_exact(cursor.key(), None) {
return false;
}
match self {
Self::Simple { filter } => {
while let Some(val) = cursor.get_val() {
if (filter.filter_func())(val) {
return true;
}
cursor.step_val();
}
false
}
Self::LastN { n, filter } => {
trace_cursor.fast_forward_vals();
trace_cursor.seek_val_with_reverse(&|val| !(filter.filter_func())(val));
let mut count = 1;
while count < *n && trace_cursor.val_valid() {
trace_cursor.step_val_reverse();
count += 1;
}
if trace_cursor.val_valid() {
while cursor.val_valid() && cursor.val() < trace_cursor.val() {
cursor.step_val();
}
}
cursor.val_valid()
}
Self::TopN {
n,
filter,
min_val,
min_val_valid,
} => {
trace_cursor.fast_forward_vals();
let mut above_waterline = 0;
let mut below_waterline = 0;
*min_val_valid = false;
while trace_cursor.val_valid() {
if (filter.filter_func())(trace_cursor.val()) {
above_waterline += 1;
} else {
below_waterline += 1;
if below_waterline == *n {
trace_cursor.val().clone_to(min_val);
*min_val_valid = true;
break;
}
}
trace_cursor.step_val_reverse();
}
if below_waterline + above_waterline > 0 {
if *min_val_valid {
cursor
.seek_val_with(&|val| (filter.filter_func())(val) || val >= &**min_val)
}
cursor.val_valid()
} else {
false
}
}
Self::BottomN {
n,
filter,
max_val,
max_val_valid,
} => {
let mut above_waterline = 0;
let mut below_waterline = 0;
*max_val_valid = false;
while trace_cursor.val_valid() {
if (filter.filter_func())(trace_cursor.val()) {
above_waterline += 1;
} else {
below_waterline += 1;
if below_waterline == *n {
*max_val_valid = true;
trace_cursor.val().clone_to(max_val);
break;
}
}
trace_cursor.step_val();
}
below_waterline + above_waterline > 0
}
}
}
fn on_step_val<K: ?Sized, T, R: ?Sized>(
&mut self,
cursor: &mut dyn Cursor<K, V, T, R>,
_trace_cursor: &mut dyn Cursor<K, V, T, R>,
) {
match self {
Self::Simple { filter } => {
while let Some(val) = cursor.get_val() {
if (filter.filter_func())(val) {
return;
}
cursor.step_val();
}
}
Self::LastN { .. } => {}
Self::TopN {
filter,
min_val,
min_val_valid,
..
} => {
while let Some(val) = cursor.get_val() {
if (filter.filter_func())(val) || !*min_val_valid {
return;
}
if *val >= **min_val {
*min_val_valid = false;
return;
}
cursor.step_val();
}
}
Self::BottomN {
filter,
max_val,
max_val_valid,
..
} => {
while let Some(val) = cursor.get_val() {
if (filter.filter_func())(val) || !*max_val_valid {
return;
}
if *val <= **max_val {
return;
}
cursor.step_val();
}
}
}
}
}
pub struct UnfilteredMergeCursor<K, V, T, R, C>
where
K: ?Sized,
V: ?Sized,
R: ?Sized,
C: Cursor<K, V, T, R>,
{
cursor: C,
phantom: PhantomData<(Box<K>, Box<V>, T, Box<R>)>,
}
impl<K, V, T, R, C> UnfilteredMergeCursor<K, V, T, R, C>
where
K: ?Sized,
V: ?Sized,
R: ?Sized,
C: Cursor<K, V, T, R>,
{
pub fn new(cursor: C) -> Self {
Self {
cursor,
phantom: PhantomData,
}
}
}
impl<K, V, T, R, C> MergeCursor<K, V, T, R> for UnfilteredMergeCursor<K, V, T, R, C>
where
K: ?Sized,
V: ?Sized,
R: ?Sized,
C: Cursor<K, V, T, R>,
{
fn key_valid(&self) -> bool {
self.cursor.key_valid()
}
fn val_valid(&self) -> bool {
self.cursor.val_valid()
}
fn val(&self) -> &V {
self.cursor.val()
}
fn key(&self) -> &K {
self.cursor.key()
}
fn step_key(&mut self) {
self.cursor.step_key()
}
fn step_val(&mut self) {
self.cursor.step_val()
}
fn map_times(&mut self, logic: &mut dyn FnMut(&T, &R)) {
self.cursor.map_times(logic);
}
fn weight(&mut self) -> &R
where
T: PartialEq<()>,
{
self.cursor.weight()
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Pending;
pub trait PushCursor<K, V, T, R>
where
K: ?Sized,
V: ?Sized,
R: ?Sized,
{
fn key(&self) -> Result<Option<&K>, Pending>;
fn val(&self) -> Result<Option<&V>, Pending>;
fn map_times(&mut self, logic: &mut dyn FnMut(&T, &R));
fn weight(&mut self) -> &R
where
T: PartialEq<()>;
fn step_key(&mut self);
fn step_val(&mut self);
fn run(&mut self);
}
impl<K, V, T, R, C> PushCursor<K, V, T, R> for Box<C>
where
C: PushCursor<K, V, T, R> + ?Sized,
K: ?Sized,
V: ?Sized,
R: ?Sized,
{
fn key(&self) -> Result<Option<&K>, Pending> {
(**self).key()
}
fn val(&self) -> Result<Option<&V>, Pending> {
(**self).val()
}
fn map_times(&mut self, logic: &mut dyn FnMut(&T, &R)) {
(**self).map_times(logic);
}
fn weight(&mut self) -> &R
where
T: PartialEq<()>,
{
(**self).weight()
}
fn step_key(&mut self) {
(**self).step_key();
}
fn step_val(&mut self) {
(**self).step_val();
}
fn run(&mut self) {
(**self).run();
}
}
pub struct DefaultPushCursor<K, V, T, R, C>
where
K: ?Sized,
V: ?Sized,
R: ?Sized,
C: Cursor<K, V, T, R>,
{
cursor: C,
phantom: PhantomData<(Box<K>, Box<V>, T, Box<R>)>,
}
impl<K, V, T, R, C> DefaultPushCursor<K, V, T, R, C>
where
K: ?Sized,
V: ?Sized,
R: ?Sized,
C: Cursor<K, V, T, R>,
{
pub fn new(cursor: C) -> Self {
Self {
cursor,
phantom: PhantomData,
}
}
}
impl<K, V, T, R, C> PushCursor<K, V, T, R> for DefaultPushCursor<K, V, T, R, C>
where
K: ?Sized,
V: ?Sized,
R: ?Sized,
C: Cursor<K, V, T, R>,
{
fn key(&self) -> Result<Option<&K>, Pending> {
Ok(self.cursor.get_key())
}
fn val(&self) -> Result<Option<&V>, Pending> {
Ok(self.cursor.get_val())
}
fn map_times(&mut self, logic: &mut dyn FnMut(&T, &R)) {
self.cursor.map_times(logic);
}
fn weight(&mut self) -> &R
where
T: PartialEq<()>,
{
self.cursor.weight()
}
fn step_key(&mut self) {
self.cursor.step_key();
}
fn step_val(&mut self) {
self.cursor.step_val();
}
fn run(&mut self) {}
}