Remove add_summary_with_ctx
and always require a ctx in add_summary
This commit is contained in:
parent
901525bf77
commit
652fc9e4ec
7 changed files with 23 additions and 23 deletions
|
@ -2105,7 +2105,7 @@ impl sum_tree::Item for Fragment {
|
||||||
impl sum_tree::Summary for FragmentSummary {
|
impl sum_tree::Summary for FragmentSummary {
|
||||||
type Context = ();
|
type Context = ();
|
||||||
|
|
||||||
fn add_summary(&mut self, other: &Self) {
|
fn add_summary(&mut self, other: &Self, _: Option<&Self::Context>) {
|
||||||
self.text_summary += &other.text_summary;
|
self.text_summary += &other.text_summary;
|
||||||
debug_assert!(self.max_fragment_id <= other.max_fragment_id);
|
debug_assert!(self.max_fragment_id <= other.max_fragment_id);
|
||||||
self.max_fragment_id = other.max_fragment_id.clone();
|
self.max_fragment_id = other.max_fragment_id.clone();
|
||||||
|
@ -2171,7 +2171,7 @@ impl sum_tree::Item for InsertionSplit {
|
||||||
impl sum_tree::Summary for InsertionSplitSummary {
|
impl sum_tree::Summary for InsertionSplitSummary {
|
||||||
type Context = ();
|
type Context = ();
|
||||||
|
|
||||||
fn add_summary(&mut self, other: &Self) {
|
fn add_summary(&mut self, other: &Self, _: Option<&Self::Context>) {
|
||||||
self.extent += other.extent;
|
self.extent += other.extent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ pub struct TextSummary {
|
||||||
impl sum_tree::Summary for TextSummary {
|
impl sum_tree::Summary for TextSummary {
|
||||||
type Context = ();
|
type Context = ();
|
||||||
|
|
||||||
fn add_summary(&mut self, other: &Self) {
|
fn add_summary(&mut self, other: &Self, _: Option<&Self::Context>) {
|
||||||
*self += other;
|
*self += other;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -459,7 +459,7 @@ impl sum_tree::Item for Transform {
|
||||||
impl sum_tree::Summary for TransformSummary {
|
impl sum_tree::Summary for TransformSummary {
|
||||||
type Context = ();
|
type Context = ();
|
||||||
|
|
||||||
fn add_summary(&mut self, other: &Self) {
|
fn add_summary(&mut self, other: &Self, _: Option<&Self::Context>) {
|
||||||
self.buffer += &other.buffer;
|
self.buffer += &other.buffer;
|
||||||
self.display += &other.display;
|
self.display += &other.display;
|
||||||
}
|
}
|
||||||
|
@ -467,7 +467,7 @@ impl sum_tree::Summary for TransformSummary {
|
||||||
|
|
||||||
impl<'a> sum_tree::Dimension<'a, TransformSummary> for TransformSummary {
|
impl<'a> sum_tree::Dimension<'a, TransformSummary> for TransformSummary {
|
||||||
fn add_summary(&mut self, summary: &'a TransformSummary) {
|
fn add_summary(&mut self, summary: &'a TransformSummary) {
|
||||||
sum_tree::Summary::add_summary(self, summary);
|
sum_tree::Summary::add_summary(self, summary, None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,7 +512,7 @@ impl Default for FoldSummary {
|
||||||
impl sum_tree::Summary for FoldSummary {
|
impl sum_tree::Summary for FoldSummary {
|
||||||
type Context = Buffer;
|
type Context = Buffer;
|
||||||
|
|
||||||
fn add_summary_with_ctx(&mut self, other: &Self, buffer: Option<&Self::Context>) {
|
fn add_summary(&mut self, other: &Self, buffer: Option<&Self::Context>) {
|
||||||
let buffer = buffer.unwrap();
|
let buffer = buffer.unwrap();
|
||||||
if other.min_start.cmp(&self.min_start, buffer).unwrap() == Ordering::Less {
|
if other.min_start.cmp(&self.min_start, buffer).unwrap() == Ordering::Less {
|
||||||
self.min_start = other.min_start.clone();
|
self.min_start = other.min_start.clone();
|
||||||
|
|
|
@ -68,7 +68,7 @@ impl<T: Operation> KeyedItem for T {
|
||||||
impl Summary for OperationSummary {
|
impl Summary for OperationSummary {
|
||||||
type Context = ();
|
type Context = ();
|
||||||
|
|
||||||
fn add_summary(&mut self, other: &Self) {
|
fn add_summary(&mut self, other: &Self, _: Option<&Self::Context>) {
|
||||||
assert!(self.key < other.key);
|
assert!(self.key < other.key);
|
||||||
self.key = other.key;
|
self.key = other.key;
|
||||||
self.len += other.len;
|
self.len += other.len;
|
||||||
|
|
|
@ -560,7 +560,7 @@ where
|
||||||
slice_items_summary
|
slice_items_summary
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.add_summary_with_ctx(item_summary, ctx);
|
.add_summary(item_summary, ctx);
|
||||||
}
|
}
|
||||||
SeekAggregate::Summary(summary) => {
|
SeekAggregate::Summary(summary) => {
|
||||||
summary.add_summary(item_summary);
|
summary.add_summary(item_summary);
|
||||||
|
@ -679,7 +679,7 @@ where
|
||||||
slice_items_summary
|
slice_items_summary
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.add_summary_with_ctx(item_summary, ctx);
|
.add_summary(item_summary, ctx);
|
||||||
slice_item_summaries.push(item_summary.clone());
|
slice_item_summaries.push(item_summary.clone());
|
||||||
}
|
}
|
||||||
SeekAggregate::Summary(summary) => {
|
SeekAggregate::Summary(summary) => {
|
||||||
|
|
|
@ -25,14 +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) {
|
fn add_summary(&mut self, summary: &Self, ctx: Option<&Self::Context>);
|
||||||
unimplemented!();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_summary_with_ctx(&mut self, summary: &Self, ctx: Option<&Self::Context>) {
|
|
||||||
assert!(ctx.is_none());
|
|
||||||
self.add_summary(summary);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Dimension<'a, S: Summary>: Clone + fmt::Debug + Default {
|
pub trait Dimension<'a, S: Summary>: Clone + fmt::Debug + Default {
|
||||||
|
@ -134,6 +127,13 @@ impl<T: Item> SumTree<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extend<I>(&mut self, iter: I)
|
pub fn extend<I>(&mut self, iter: I)
|
||||||
|
where
|
||||||
|
I: IntoIterator<Item = T>,
|
||||||
|
{
|
||||||
|
self.extend_with_ctx(iter, None)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn extend_with_ctx<I>(&mut self, iter: I, ctx: Option<&<T::Summary as Summary>::Context>)
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = T>,
|
I: IntoIterator<Item = T>,
|
||||||
{
|
{
|
||||||
|
@ -159,7 +159,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);
|
summary.add_summary(&item_summary, ctx);
|
||||||
items.push(item);
|
items.push(item);
|
||||||
item_summaries.push(item_summary);
|
item_summaries.push(item_summary);
|
||||||
} else {
|
} else {
|
||||||
|
@ -226,7 +226,7 @@ impl<T: Item> SumTree<T> {
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
let other_node = other.0.clone();
|
let other_node = other.0.clone();
|
||||||
summary.add_summary_with_ctx(other_node.summary(), ctx);
|
summary.add_summary(other_node.summary(), ctx);
|
||||||
|
|
||||||
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();
|
||||||
|
@ -323,7 +323,7 @@ impl<T: Item> SumTree<T> {
|
||||||
item_summaries: right_summaries,
|
item_summaries: right_summaries,
|
||||||
})))
|
})))
|
||||||
} else {
|
} else {
|
||||||
summary.add_summary_with_ctx(other_node.summary(), ctx);
|
summary.add_summary(other_node.summary(), ctx);
|
||||||
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
|
||||||
|
@ -538,7 +538,7 @@ where
|
||||||
{
|
{
|
||||||
let mut sum = T::default();
|
let mut sum = T::default();
|
||||||
for value in iter {
|
for value in iter {
|
||||||
sum.add_summary_with_ctx(value, ctx);
|
sum.add_summary(value, ctx);
|
||||||
}
|
}
|
||||||
sum
|
sum
|
||||||
}
|
}
|
||||||
|
@ -889,7 +889,7 @@ mod tests {
|
||||||
impl Summary for IntegersSummary {
|
impl Summary for IntegersSummary {
|
||||||
type Context = ();
|
type Context = ();
|
||||||
|
|
||||||
fn add_summary(&mut self, other: &Self) {
|
fn add_summary(&mut self, other: &Self, _: Option<&Self::Context>) {
|
||||||
self.count.0 += &other.count.0;
|
self.count.0 += &other.count.0;
|
||||||
self.sum.0 += &other.sum.0;
|
self.sum.0 += &other.sum.0;
|
||||||
self.contains_even |= other.contains_even;
|
self.contains_even |= other.contains_even;
|
||||||
|
|
|
@ -538,7 +538,7 @@ impl Default for EntrySummary {
|
||||||
impl sum_tree::Summary for EntrySummary {
|
impl sum_tree::Summary for EntrySummary {
|
||||||
type Context = ();
|
type Context = ();
|
||||||
|
|
||||||
fn add_summary(&mut self, rhs: &Self) {
|
fn add_summary(&mut self, rhs: &Self, _: Option<&Self::Context>) {
|
||||||
self.max_path = rhs.max_path.clone();
|
self.max_path = rhs.max_path.clone();
|
||||||
self.file_count += rhs.file_count;
|
self.file_count += rhs.file_count;
|
||||||
self.visible_file_count += rhs.visible_file_count;
|
self.visible_file_count += rhs.visible_file_count;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue