Rename context parameters to cx
in sum_tree
This commit is contained in:
parent
f6e2754494
commit
173f99748d
2 changed files with 70 additions and 75 deletions
|
@ -25,7 +25,7 @@ pub trait KeyedItem: Item {
|
||||||
pub trait Summary: Default + Clone + fmt::Debug {
|
pub trait Summary: Default + Clone + fmt::Debug {
|
||||||
type Context;
|
type Context;
|
||||||
|
|
||||||
fn add_summary(&mut self, summary: &Self, ctx: &Self::Context);
|
fn add_summary(&mut self, summary: &Self, cx: &Self::Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Dimension<'a, S: Summary>: Clone + fmt::Debug + Default {
|
pub trait Dimension<'a, S: Summary>: Clone + fmt::Debug + Default {
|
||||||
|
@ -37,7 +37,7 @@ impl<'a, T: Summary> Dimension<'a, T> for () {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait SeekDimension<'a, T: Summary>: Dimension<'a, T> {
|
pub trait SeekDimension<'a, T: Summary>: Dimension<'a, T> {
|
||||||
fn cmp(&self, other: &Self, ctx: &T::Context) -> Ordering;
|
fn cmp(&self, other: &Self, cx: &T::Context) -> Ordering;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, S: Summary, T: Dimension<'a, S> + Ord> SeekDimension<'a, S> for T {
|
impl<'a, S: Summary, T: Dimension<'a, S> + Ord> SeekDimension<'a, S> for T {
|
||||||
|
@ -64,9 +64,9 @@ impl<T: Item> SumTree<T> {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_item(item: T, ctx: &<T::Summary as Summary>::Context) -> Self {
|
pub fn from_item(item: T, cx: &<T::Summary as Summary>::Context) -> Self {
|
||||||
let mut tree = Self::new();
|
let mut tree = Self::new();
|
||||||
tree.push(item, ctx);
|
tree.push(item, cx);
|
||||||
tree
|
tree
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,14 +101,14 @@ impl<T: Item> SumTree<T> {
|
||||||
self.rightmost_leaf().0.items().last()
|
self.rightmost_leaf().0.items().last()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_last(&mut self, f: impl FnOnce(&mut T), ctx: &<T::Summary as Summary>::Context) {
|
pub fn update_last(&mut self, f: impl FnOnce(&mut T), cx: &<T::Summary as Summary>::Context) {
|
||||||
self.update_last_recursive(f, ctx);
|
self.update_last_recursive(f, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_last_recursive(
|
fn update_last_recursive(
|
||||||
&mut self,
|
&mut self,
|
||||||
f: impl FnOnce(&mut T),
|
f: impl FnOnce(&mut T),
|
||||||
ctx: &<T::Summary as Summary>::Context,
|
cx: &<T::Summary as Summary>::Context,
|
||||||
) -> Option<T::Summary> {
|
) -> Option<T::Summary> {
|
||||||
match Arc::make_mut(&mut self.0) {
|
match Arc::make_mut(&mut self.0) {
|
||||||
Node::Internal {
|
Node::Internal {
|
||||||
|
@ -119,8 +119,8 @@ impl<T: Item> SumTree<T> {
|
||||||
} => {
|
} => {
|
||||||
let last_summary = child_summaries.last_mut().unwrap();
|
let last_summary = child_summaries.last_mut().unwrap();
|
||||||
let last_child = child_trees.last_mut().unwrap();
|
let last_child = child_trees.last_mut().unwrap();
|
||||||
*last_summary = last_child.update_last_recursive(f, ctx).unwrap();
|
*last_summary = last_child.update_last_recursive(f, cx).unwrap();
|
||||||
*summary = sum(child_summaries.iter(), ctx);
|
*summary = sum(child_summaries.iter(), cx);
|
||||||
Some(summary.clone())
|
Some(summary.clone())
|
||||||
}
|
}
|
||||||
Node::Leaf {
|
Node::Leaf {
|
||||||
|
@ -132,7 +132,7 @@ impl<T: Item> SumTree<T> {
|
||||||
{
|
{
|
||||||
(f)(item);
|
(f)(item);
|
||||||
*item_summary = item.summary();
|
*item_summary = item.summary();
|
||||||
*summary = sum(item_summaries.iter(), ctx);
|
*summary = sum(item_summaries.iter(), cx);
|
||||||
Some(summary.clone())
|
Some(summary.clone())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -165,7 +165,7 @@ impl<T: Item> SumTree<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extend<I>(&mut self, iter: I, ctx: &<T::Summary as Summary>::Context)
|
pub fn extend<I>(&mut self, iter: I, cx: &<T::Summary as Summary>::Context)
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = T>,
|
I: IntoIterator<Item = T>,
|
||||||
{
|
{
|
||||||
|
@ -173,7 +173,7 @@ impl<T: Item> SumTree<T> {
|
||||||
|
|
||||||
for item in iter {
|
for item in iter {
|
||||||
if leaf.is_some() && leaf.as_ref().unwrap().items().len() == 2 * TREE_BASE {
|
if leaf.is_some() && leaf.as_ref().unwrap().items().len() == 2 * TREE_BASE {
|
||||||
self.push_tree(SumTree(Arc::new(leaf.take().unwrap())), ctx);
|
self.push_tree(SumTree(Arc::new(leaf.take().unwrap())), cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if leaf.is_none() {
|
if leaf.is_none() {
|
||||||
|
@ -191,7 +191,7 @@ impl<T: Item> SumTree<T> {
|
||||||
}) = leaf.as_mut()
|
}) = leaf.as_mut()
|
||||||
{
|
{
|
||||||
let item_summary = item.summary();
|
let item_summary = item.summary();
|
||||||
summary.add_summary(&item_summary, ctx);
|
summary.add_summary(&item_summary, cx);
|
||||||
items.push(item);
|
items.push(item);
|
||||||
item_summaries.push(item_summary);
|
item_summaries.push(item_summary);
|
||||||
} else {
|
} else {
|
||||||
|
@ -200,11 +200,11 @@ impl<T: Item> SumTree<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if leaf.is_some() {
|
if leaf.is_some() {
|
||||||
self.push_tree(SumTree(Arc::new(leaf.take().unwrap())), ctx);
|
self.push_tree(SumTree(Arc::new(leaf.take().unwrap())), cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push(&mut self, item: T, ctx: &<T::Summary as Summary>::Context) {
|
pub fn push(&mut self, item: T, cx: &<T::Summary as Summary>::Context) {
|
||||||
let summary = item.summary();
|
let summary = item.summary();
|
||||||
self.push_tree(
|
self.push_tree(
|
||||||
SumTree(Arc::new(Node::Leaf {
|
SumTree(Arc::new(Node::Leaf {
|
||||||
|
@ -212,18 +212,18 @@ impl<T: Item> SumTree<T> {
|
||||||
items: ArrayVec::from_iter(Some(item)),
|
items: ArrayVec::from_iter(Some(item)),
|
||||||
item_summaries: ArrayVec::from_iter(Some(summary)),
|
item_summaries: ArrayVec::from_iter(Some(summary)),
|
||||||
})),
|
})),
|
||||||
ctx,
|
cx,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_tree(&mut self, other: Self, ctx: &<T::Summary as Summary>::Context) {
|
pub fn push_tree(&mut self, other: Self, cx: &<T::Summary as Summary>::Context) {
|
||||||
if !other.0.is_leaf() || other.0.items().len() > 0 {
|
if !other.0.is_leaf() || other.0.items().len() > 0 {
|
||||||
if self.0.height() < other.0.height() {
|
if self.0.height() < other.0.height() {
|
||||||
for tree in other.0.child_trees() {
|
for tree in other.0.child_trees() {
|
||||||
self.push_tree(tree.clone(), ctx);
|
self.push_tree(tree.clone(), cx);
|
||||||
}
|
}
|
||||||
} else if let Some(split_tree) = self.push_tree_recursive(other, ctx) {
|
} else if let Some(split_tree) = self.push_tree_recursive(other, cx) {
|
||||||
*self = Self::from_child_trees(self.clone(), split_tree, ctx);
|
*self = Self::from_child_trees(self.clone(), split_tree, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,7 @@ impl<T: Item> SumTree<T> {
|
||||||
fn push_tree_recursive(
|
fn push_tree_recursive(
|
||||||
&mut self,
|
&mut self,
|
||||||
other: SumTree<T>,
|
other: SumTree<T>,
|
||||||
ctx: &<T::Summary as Summary>::Context,
|
cx: &<T::Summary as Summary>::Context,
|
||||||
) -> Option<SumTree<T>> {
|
) -> Option<SumTree<T>> {
|
||||||
match Arc::make_mut(&mut self.0) {
|
match Arc::make_mut(&mut self.0) {
|
||||||
Node::Internal {
|
Node::Internal {
|
||||||
|
@ -242,7 +242,7 @@ impl<T: Item> SumTree<T> {
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
let other_node = other.0.clone();
|
let other_node = other.0.clone();
|
||||||
summary.add_summary(other_node.summary(), ctx);
|
summary.add_summary(other_node.summary(), cx);
|
||||||
|
|
||||||
let height_delta = *height - other_node.height();
|
let height_delta = *height - other_node.height();
|
||||||
let mut summaries_to_append = ArrayVec::<[T::Summary; 2 * TREE_BASE]>::new();
|
let mut summaries_to_append = ArrayVec::<[T::Summary; 2 * TREE_BASE]>::new();
|
||||||
|
@ -257,7 +257,7 @@ impl<T: Item> SumTree<T> {
|
||||||
let tree_to_append = child_trees
|
let tree_to_append = child_trees
|
||||||
.last_mut()
|
.last_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.push_tree_recursive(other, ctx);
|
.push_tree_recursive(other, cx);
|
||||||
*child_summaries.last_mut().unwrap() =
|
*child_summaries.last_mut().unwrap() =
|
||||||
child_trees.last().unwrap().0.summary().clone();
|
child_trees.last().unwrap().0.summary().clone();
|
||||||
|
|
||||||
|
@ -287,13 +287,13 @@ impl<T: Item> SumTree<T> {
|
||||||
left_trees = all_trees.by_ref().take(midpoint).collect();
|
left_trees = all_trees.by_ref().take(midpoint).collect();
|
||||||
right_trees = all_trees.collect();
|
right_trees = all_trees.collect();
|
||||||
}
|
}
|
||||||
*summary = sum(left_summaries.iter(), ctx);
|
*summary = sum(left_summaries.iter(), cx);
|
||||||
*child_summaries = left_summaries;
|
*child_summaries = left_summaries;
|
||||||
*child_trees = left_trees;
|
*child_trees = left_trees;
|
||||||
|
|
||||||
Some(SumTree(Arc::new(Node::Internal {
|
Some(SumTree(Arc::new(Node::Internal {
|
||||||
height: *height,
|
height: *height,
|
||||||
summary: sum(right_summaries.iter(), ctx),
|
summary: sum(right_summaries.iter(), cx),
|
||||||
child_summaries: right_summaries,
|
child_summaries: right_summaries,
|
||||||
child_trees: right_trees,
|
child_trees: right_trees,
|
||||||
})))
|
})))
|
||||||
|
@ -332,14 +332,14 @@ impl<T: Item> SumTree<T> {
|
||||||
}
|
}
|
||||||
*items = left_items;
|
*items = left_items;
|
||||||
*item_summaries = left_summaries;
|
*item_summaries = left_summaries;
|
||||||
*summary = sum(item_summaries.iter(), ctx);
|
*summary = sum(item_summaries.iter(), cx);
|
||||||
Some(SumTree(Arc::new(Node::Leaf {
|
Some(SumTree(Arc::new(Node::Leaf {
|
||||||
items: right_items,
|
items: right_items,
|
||||||
summary: sum(right_summaries.iter(), ctx),
|
summary: sum(right_summaries.iter(), cx),
|
||||||
item_summaries: right_summaries,
|
item_summaries: right_summaries,
|
||||||
})))
|
})))
|
||||||
} else {
|
} else {
|
||||||
summary.add_summary(other_node.summary(), ctx);
|
summary.add_summary(other_node.summary(), cx);
|
||||||
items.extend(other_node.items().iter().cloned());
|
items.extend(other_node.items().iter().cloned());
|
||||||
item_summaries.extend(other_node.child_summaries().iter().cloned());
|
item_summaries.extend(other_node.child_summaries().iter().cloned());
|
||||||
None
|
None
|
||||||
|
@ -351,7 +351,7 @@ impl<T: Item> SumTree<T> {
|
||||||
fn from_child_trees(
|
fn from_child_trees(
|
||||||
left: SumTree<T>,
|
left: SumTree<T>,
|
||||||
right: SumTree<T>,
|
right: SumTree<T>,
|
||||||
ctx: &<T::Summary as Summary>::Context,
|
cx: &<T::Summary as Summary>::Context,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let height = left.0.height() + 1;
|
let height = left.0.height() + 1;
|
||||||
let mut child_summaries = ArrayVec::new();
|
let mut child_summaries = ArrayVec::new();
|
||||||
|
@ -362,7 +362,7 @@ impl<T: Item> SumTree<T> {
|
||||||
child_trees.push(right);
|
child_trees.push(right);
|
||||||
SumTree(Arc::new(Node::Internal {
|
SumTree(Arc::new(Node::Internal {
|
||||||
height,
|
height,
|
||||||
summary: sum(child_summaries.iter(), ctx),
|
summary: sum(child_summaries.iter(), cx),
|
||||||
child_summaries,
|
child_summaries,
|
||||||
child_trees,
|
child_trees,
|
||||||
}))
|
}))
|
||||||
|
@ -389,12 +389,12 @@ impl<T: Item> SumTree<T> {
|
||||||
|
|
||||||
impl<T: KeyedItem> SumTree<T> {
|
impl<T: KeyedItem> SumTree<T> {
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn insert(&mut self, item: T, ctx: &<T::Summary as Summary>::Context) {
|
pub fn insert(&mut self, item: T, cx: &<T::Summary as Summary>::Context) {
|
||||||
*self = {
|
*self = {
|
||||||
let mut cursor = self.cursor::<T::Key, ()>();
|
let mut cursor = self.cursor::<T::Key, ()>();
|
||||||
let mut new_tree = cursor.slice(&item.key(), SeekBias::Left, ctx);
|
let mut new_tree = cursor.slice(&item.key(), SeekBias::Left, cx);
|
||||||
new_tree.push(item, ctx);
|
new_tree.push(item, cx);
|
||||||
new_tree.push_tree(cursor.suffix(ctx), ctx);
|
new_tree.push_tree(cursor.suffix(cx), cx);
|
||||||
new_tree
|
new_tree
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -402,7 +402,7 @@ impl<T: KeyedItem> SumTree<T> {
|
||||||
pub fn edit(
|
pub fn edit(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut edits: Vec<Edit<T>>,
|
mut edits: Vec<Edit<T>>,
|
||||||
ctx: &<T::Summary as Summary>::Context,
|
cx: &<T::Summary as Summary>::Context,
|
||||||
) -> Vec<T> {
|
) -> Vec<T> {
|
||||||
if edits.is_empty() {
|
if edits.is_empty() {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
|
@ -416,7 +416,7 @@ impl<T: KeyedItem> SumTree<T> {
|
||||||
let mut new_tree = SumTree::new();
|
let mut new_tree = SumTree::new();
|
||||||
let mut buffered_items = Vec::new();
|
let mut buffered_items = Vec::new();
|
||||||
|
|
||||||
cursor.seek(&T::Key::default(), SeekBias::Left, ctx);
|
cursor.seek(&T::Key::default(), SeekBias::Left, cx);
|
||||||
for edit in edits {
|
for edit in edits {
|
||||||
let new_key = edit.key();
|
let new_key = edit.key();
|
||||||
let mut old_item = cursor.item();
|
let mut old_item = cursor.item();
|
||||||
|
@ -425,9 +425,9 @@ impl<T: KeyedItem> SumTree<T> {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(false, |old_item| old_item.key() < new_key)
|
.map_or(false, |old_item| old_item.key() < new_key)
|
||||||
{
|
{
|
||||||
new_tree.extend(buffered_items.drain(..), ctx);
|
new_tree.extend(buffered_items.drain(..), cx);
|
||||||
let slice = cursor.slice(&new_key, SeekBias::Left, ctx);
|
let slice = cursor.slice(&new_key, SeekBias::Left, cx);
|
||||||
new_tree.push_tree(slice, ctx);
|
new_tree.push_tree(slice, cx);
|
||||||
old_item = cursor.item();
|
old_item = cursor.item();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,17 +446,17 @@ impl<T: KeyedItem> SumTree<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new_tree.extend(buffered_items, ctx);
|
new_tree.extend(buffered_items, cx);
|
||||||
new_tree.push_tree(cursor.suffix(ctx), ctx);
|
new_tree.push_tree(cursor.suffix(cx), cx);
|
||||||
new_tree
|
new_tree
|
||||||
};
|
};
|
||||||
|
|
||||||
removed
|
removed
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, key: &T::Key, ctx: &<T::Summary as Summary>::Context) -> Option<&T> {
|
pub fn get(&self, key: &T::Key, cx: &<T::Summary as Summary>::Context) -> Option<&T> {
|
||||||
let mut cursor = self.cursor::<T::Key, ()>();
|
let mut cursor = self.cursor::<T::Key, ()>();
|
||||||
if cursor.seek(key, SeekBias::Left, ctx) {
|
if cursor.seek(key, SeekBias::Left, cx) {
|
||||||
cursor.item()
|
cursor.item()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -553,14 +553,14 @@ impl<T: KeyedItem> Edit<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sum<'a, T, I>(iter: I, ctx: &T::Context) -> T
|
fn sum<'a, T, I>(iter: I, cx: &T::Context) -> T
|
||||||
where
|
where
|
||||||
T: 'a + Summary,
|
T: 'a + Summary,
|
||||||
I: Iterator<Item = &'a T>,
|
I: Iterator<Item = &'a T>,
|
||||||
{
|
{
|
||||||
let mut sum = T::default();
|
let mut sum = T::default();
|
||||||
for value in iter {
|
for value in iter {
|
||||||
sum.add_summary(value, ctx);
|
sum.add_summary(value, cx);
|
||||||
}
|
}
|
||||||
sum
|
sum
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,33 +342,28 @@ where
|
||||||
S: SeekDimension<'a, T::Summary>,
|
S: SeekDimension<'a, T::Summary>,
|
||||||
U: Dimension<'a, T::Summary>,
|
U: Dimension<'a, T::Summary>,
|
||||||
{
|
{
|
||||||
pub fn seek(
|
pub fn seek(&mut self, pos: &S, bias: SeekBias, cx: &<T::Summary as Summary>::Context) -> bool {
|
||||||
&mut self,
|
|
||||||
pos: &S,
|
|
||||||
bias: SeekBias,
|
|
||||||
ctx: &<T::Summary as Summary>::Context,
|
|
||||||
) -> bool {
|
|
||||||
self.reset();
|
self.reset();
|
||||||
self.seek_internal::<()>(pos, bias, &mut SeekAggregate::None, ctx)
|
self.seek_internal::<()>(pos, bias, &mut SeekAggregate::None, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn seek_forward(
|
pub fn seek_forward(
|
||||||
&mut self,
|
&mut self,
|
||||||
pos: &S,
|
pos: &S,
|
||||||
bias: SeekBias,
|
bias: SeekBias,
|
||||||
ctx: &<T::Summary as Summary>::Context,
|
cx: &<T::Summary as Summary>::Context,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
self.seek_internal::<()>(pos, bias, &mut SeekAggregate::None, ctx)
|
self.seek_internal::<()>(pos, bias, &mut SeekAggregate::None, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn slice(
|
pub fn slice(
|
||||||
&mut self,
|
&mut self,
|
||||||
end: &S,
|
end: &S,
|
||||||
bias: SeekBias,
|
bias: SeekBias,
|
||||||
ctx: &<T::Summary as Summary>::Context,
|
cx: &<T::Summary as Summary>::Context,
|
||||||
) -> SumTree<T> {
|
) -> SumTree<T> {
|
||||||
let mut slice = SeekAggregate::Slice(SumTree::new());
|
let mut slice = SeekAggregate::Slice(SumTree::new());
|
||||||
self.seek_internal::<()>(end, bias, &mut slice, ctx);
|
self.seek_internal::<()>(end, bias, &mut slice, cx);
|
||||||
if let SeekAggregate::Slice(slice) = slice {
|
if let SeekAggregate::Slice(slice) = slice {
|
||||||
slice
|
slice
|
||||||
} else {
|
} else {
|
||||||
|
@ -376,10 +371,10 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(&mut self, ctx: &<T::Summary as Summary>::Context) -> SumTree<T> {
|
pub fn suffix(&mut self, cx: &<T::Summary as Summary>::Context) -> SumTree<T> {
|
||||||
let extent = self.tree.extent::<S>();
|
let extent = self.tree.extent::<S>();
|
||||||
let mut slice = SeekAggregate::Slice(SumTree::new());
|
let mut slice = SeekAggregate::Slice(SumTree::new());
|
||||||
self.seek_internal::<()>(&extent, SeekBias::Right, &mut slice, ctx);
|
self.seek_internal::<()>(&extent, SeekBias::Right, &mut slice, cx);
|
||||||
if let SeekAggregate::Slice(slice) = slice {
|
if let SeekAggregate::Slice(slice) = slice {
|
||||||
slice
|
slice
|
||||||
} else {
|
} else {
|
||||||
|
@ -391,13 +386,13 @@ where
|
||||||
&mut self,
|
&mut self,
|
||||||
end: &S,
|
end: &S,
|
||||||
bias: SeekBias,
|
bias: SeekBias,
|
||||||
ctx: &<T::Summary as Summary>::Context,
|
cx: &<T::Summary as Summary>::Context,
|
||||||
) -> D
|
) -> D
|
||||||
where
|
where
|
||||||
D: Dimension<'a, T::Summary>,
|
D: Dimension<'a, T::Summary>,
|
||||||
{
|
{
|
||||||
let mut summary = SeekAggregate::Summary(D::default());
|
let mut summary = SeekAggregate::Summary(D::default());
|
||||||
self.seek_internal(end, bias, &mut summary, ctx);
|
self.seek_internal(end, bias, &mut summary, cx);
|
||||||
if let SeekAggregate::Summary(summary) = summary {
|
if let SeekAggregate::Summary(summary) = summary {
|
||||||
summary
|
summary
|
||||||
} else {
|
} else {
|
||||||
|
@ -410,12 +405,12 @@ where
|
||||||
target: &S,
|
target: &S,
|
||||||
bias: SeekBias,
|
bias: SeekBias,
|
||||||
aggregate: &mut SeekAggregate<T, D>,
|
aggregate: &mut SeekAggregate<T, D>,
|
||||||
ctx: &<T::Summary as Summary>::Context,
|
cx: &<T::Summary as Summary>::Context,
|
||||||
) -> bool
|
) -> bool
|
||||||
where
|
where
|
||||||
D: Dimension<'a, T::Summary>,
|
D: Dimension<'a, T::Summary>,
|
||||||
{
|
{
|
||||||
debug_assert!(target.cmp(&self.seek_dimension, ctx) >= Ordering::Equal);
|
debug_assert!(target.cmp(&self.seek_dimension, cx) >= Ordering::Equal);
|
||||||
let mut containing_subtree = None;
|
let mut containing_subtree = None;
|
||||||
|
|
||||||
if self.did_seek {
|
if self.did_seek {
|
||||||
|
@ -435,7 +430,7 @@ where
|
||||||
let mut child_end = self.seek_dimension.clone();
|
let mut child_end = self.seek_dimension.clone();
|
||||||
child_end.add_summary(&child_summary);
|
child_end.add_summary(&child_summary);
|
||||||
|
|
||||||
let comparison = target.cmp(&child_end, ctx);
|
let comparison = target.cmp(&child_end, cx);
|
||||||
if comparison == Ordering::Greater
|
if comparison == Ordering::Greater
|
||||||
|| (comparison == Ordering::Equal && bias == SeekBias::Right)
|
|| (comparison == Ordering::Equal && bias == SeekBias::Right)
|
||||||
{
|
{
|
||||||
|
@ -444,7 +439,7 @@ where
|
||||||
match aggregate {
|
match aggregate {
|
||||||
SeekAggregate::None => {}
|
SeekAggregate::None => {}
|
||||||
SeekAggregate::Slice(slice) => {
|
SeekAggregate::Slice(slice) => {
|
||||||
slice.push_tree(child_tree.clone(), ctx);
|
slice.push_tree(child_tree.clone(), cx);
|
||||||
}
|
}
|
||||||
SeekAggregate::Summary(summary) => {
|
SeekAggregate::Summary(summary) => {
|
||||||
summary.add_summary(child_summary);
|
summary.add_summary(child_summary);
|
||||||
|
@ -477,7 +472,7 @@ where
|
||||||
let mut item_end = self.seek_dimension.clone();
|
let mut item_end = self.seek_dimension.clone();
|
||||||
item_end.add_summary(item_summary);
|
item_end.add_summary(item_summary);
|
||||||
|
|
||||||
let comparison = target.cmp(&item_end, ctx);
|
let comparison = target.cmp(&item_end, cx);
|
||||||
if comparison == Ordering::Greater
|
if comparison == Ordering::Greater
|
||||||
|| (comparison == Ordering::Equal && bias == SeekBias::Right)
|
|| (comparison == Ordering::Equal && bias == SeekBias::Right)
|
||||||
{
|
{
|
||||||
|
@ -491,7 +486,7 @@ where
|
||||||
slice_items_summary
|
slice_items_summary
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.add_summary(item_summary, ctx);
|
.add_summary(item_summary, cx);
|
||||||
}
|
}
|
||||||
SeekAggregate::Summary(summary) => {
|
SeekAggregate::Summary(summary) => {
|
||||||
summary.add_summary(item_summary);
|
summary.add_summary(item_summary);
|
||||||
|
@ -506,7 +501,7 @@ where
|
||||||
items: slice_items,
|
items: slice_items,
|
||||||
item_summaries: slice_item_summaries,
|
item_summaries: slice_item_summaries,
|
||||||
})),
|
})),
|
||||||
ctx,
|
cx,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
break 'outer;
|
break 'outer;
|
||||||
|
@ -521,7 +516,7 @@ where
|
||||||
items: slice_items,
|
items: slice_items,
|
||||||
item_summaries: slice_item_summaries,
|
item_summaries: slice_item_summaries,
|
||||||
})),
|
})),
|
||||||
ctx,
|
cx,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -551,7 +546,7 @@ where
|
||||||
let mut child_end = self.seek_dimension.clone();
|
let mut child_end = self.seek_dimension.clone();
|
||||||
child_end.add_summary(child_summary);
|
child_end.add_summary(child_summary);
|
||||||
|
|
||||||
let comparison = target.cmp(&child_end, ctx);
|
let comparison = target.cmp(&child_end, cx);
|
||||||
if comparison == Ordering::Greater
|
if comparison == Ordering::Greater
|
||||||
|| (comparison == Ordering::Equal && bias == SeekBias::Right)
|
|| (comparison == Ordering::Equal && bias == SeekBias::Right)
|
||||||
{
|
{
|
||||||
|
@ -560,7 +555,7 @@ where
|
||||||
match aggregate {
|
match aggregate {
|
||||||
SeekAggregate::None => {}
|
SeekAggregate::None => {}
|
||||||
SeekAggregate::Slice(slice) => {
|
SeekAggregate::Slice(slice) => {
|
||||||
slice.push_tree(child_trees[index].clone(), ctx);
|
slice.push_tree(child_trees[index].clone(), cx);
|
||||||
}
|
}
|
||||||
SeekAggregate::Summary(summary) => {
|
SeekAggregate::Summary(summary) => {
|
||||||
summary.add_summary(child_summary);
|
summary.add_summary(child_summary);
|
||||||
|
@ -597,7 +592,7 @@ where
|
||||||
let mut child_end = self.seek_dimension.clone();
|
let mut child_end = self.seek_dimension.clone();
|
||||||
child_end.add_summary(item_summary);
|
child_end.add_summary(item_summary);
|
||||||
|
|
||||||
let comparison = target.cmp(&child_end, ctx);
|
let comparison = target.cmp(&child_end, cx);
|
||||||
if comparison == Ordering::Greater
|
if comparison == Ordering::Greater
|
||||||
|| (comparison == Ordering::Equal && bias == SeekBias::Right)
|
|| (comparison == Ordering::Equal && bias == SeekBias::Right)
|
||||||
{
|
{
|
||||||
|
@ -610,7 +605,7 @@ where
|
||||||
slice_items_summary
|
slice_items_summary
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.add_summary(item_summary, ctx);
|
.add_summary(item_summary, cx);
|
||||||
slice_item_summaries.push(item_summary.clone());
|
slice_item_summaries.push(item_summary.clone());
|
||||||
}
|
}
|
||||||
SeekAggregate::Summary(summary) => {
|
SeekAggregate::Summary(summary) => {
|
||||||
|
@ -636,7 +631,7 @@ where
|
||||||
items: slice_items,
|
items: slice_items,
|
||||||
item_summaries: slice_item_summaries,
|
item_summaries: slice_item_summaries,
|
||||||
})),
|
})),
|
||||||
ctx,
|
cx,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -658,9 +653,9 @@ where
|
||||||
if let Some(summary) = self.item_summary() {
|
if let Some(summary) = self.item_summary() {
|
||||||
end.add_summary(summary);
|
end.add_summary(summary);
|
||||||
}
|
}
|
||||||
target.cmp(&end, ctx) == Ordering::Equal
|
target.cmp(&end, cx) == Ordering::Equal
|
||||||
} else {
|
} else {
|
||||||
target.cmp(&self.seek_dimension, ctx) == Ordering::Equal
|
target.cmp(&self.seek_dimension, cx) == Ordering::Equal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue