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 {
|
||||
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;
|
||||
debug_assert!(self.max_fragment_id <= other.max_fragment_id);
|
||||
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 {
|
||||
type Context = ();
|
||||
|
||||
fn add_summary(&mut self, other: &Self) {
|
||||
fn add_summary(&mut self, other: &Self, _: Option<&Self::Context>) {
|
||||
self.extent += other.extent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ pub struct TextSummary {
|
|||
impl sum_tree::Summary for TextSummary {
|
||||
type Context = ();
|
||||
|
||||
fn add_summary(&mut self, other: &Self) {
|
||||
fn add_summary(&mut self, other: &Self, _: Option<&Self::Context>) {
|
||||
*self += other;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -459,7 +459,7 @@ impl sum_tree::Item for Transform {
|
|||
impl sum_tree::Summary for TransformSummary {
|
||||
type Context = ();
|
||||
|
||||
fn add_summary(&mut self, other: &Self) {
|
||||
fn add_summary(&mut self, other: &Self, _: Option<&Self::Context>) {
|
||||
self.buffer += &other.buffer;
|
||||
self.display += &other.display;
|
||||
}
|
||||
|
@ -467,7 +467,7 @@ impl sum_tree::Summary for TransformSummary {
|
|||
|
||||
impl<'a> sum_tree::Dimension<'a, TransformSummary> for 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 {
|
||||
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();
|
||||
if other.min_start.cmp(&self.min_start, buffer).unwrap() == Ordering::Less {
|
||||
self.min_start = other.min_start.clone();
|
||||
|
|
|
@ -68,7 +68,7 @@ impl<T: Operation> KeyedItem for T {
|
|||
impl Summary for OperationSummary {
|
||||
type Context = ();
|
||||
|
||||
fn add_summary(&mut self, other: &Self) {
|
||||
fn add_summary(&mut self, other: &Self, _: Option<&Self::Context>) {
|
||||
assert!(self.key < other.key);
|
||||
self.key = other.key;
|
||||
self.len += other.len;
|
||||
|
|
|
@ -560,7 +560,7 @@ where
|
|||
slice_items_summary
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.add_summary_with_ctx(item_summary, ctx);
|
||||
.add_summary(item_summary, ctx);
|
||||
}
|
||||
SeekAggregate::Summary(summary) => {
|
||||
summary.add_summary(item_summary);
|
||||
|
@ -679,7 +679,7 @@ where
|
|||
slice_items_summary
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.add_summary_with_ctx(item_summary, ctx);
|
||||
.add_summary(item_summary, ctx);
|
||||
slice_item_summaries.push(item_summary.clone());
|
||||
}
|
||||
SeekAggregate::Summary(summary) => {
|
||||
|
|
|
@ -25,14 +25,7 @@ pub trait KeyedItem: Item {
|
|||
pub trait Summary: Default + Clone + fmt::Debug {
|
||||
type Context;
|
||||
|
||||
fn add_summary(&mut self, _summary: &Self) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn add_summary_with_ctx(&mut self, summary: &Self, ctx: Option<&Self::Context>) {
|
||||
assert!(ctx.is_none());
|
||||
self.add_summary(summary);
|
||||
}
|
||||
fn add_summary(&mut self, summary: &Self, ctx: Option<&Self::Context>);
|
||||
}
|
||||
|
||||
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)
|
||||
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
|
||||
I: IntoIterator<Item = T>,
|
||||
{
|
||||
|
@ -159,7 +159,7 @@ impl<T: Item> SumTree<T> {
|
|||
}) = leaf.as_mut()
|
||||
{
|
||||
let item_summary = item.summary();
|
||||
summary.add_summary(&item_summary);
|
||||
summary.add_summary(&item_summary, ctx);
|
||||
items.push(item);
|
||||
item_summaries.push(item_summary);
|
||||
} else {
|
||||
|
@ -226,7 +226,7 @@ impl<T: Item> SumTree<T> {
|
|||
..
|
||||
} => {
|
||||
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 mut summaries_to_append = ArrayVec::<[T::Summary; 2 * TREE_BASE]>::new();
|
||||
|
@ -323,7 +323,7 @@ impl<T: Item> SumTree<T> {
|
|||
item_summaries: right_summaries,
|
||||
})))
|
||||
} else {
|
||||
summary.add_summary_with_ctx(other_node.summary(), ctx);
|
||||
summary.add_summary(other_node.summary(), ctx);
|
||||
items.extend(other_node.items().iter().cloned());
|
||||
item_summaries.extend(other_node.child_summaries().iter().cloned());
|
||||
None
|
||||
|
@ -538,7 +538,7 @@ where
|
|||
{
|
||||
let mut sum = T::default();
|
||||
for value in iter {
|
||||
sum.add_summary_with_ctx(value, ctx);
|
||||
sum.add_summary(value, ctx);
|
||||
}
|
||||
sum
|
||||
}
|
||||
|
@ -889,7 +889,7 @@ mod tests {
|
|||
impl Summary for IntegersSummary {
|
||||
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.sum.0 += &other.sum.0;
|
||||
self.contains_even |= other.contains_even;
|
||||
|
|
|
@ -538,7 +538,7 @@ impl Default for EntrySummary {
|
|||
impl sum_tree::Summary for EntrySummary {
|
||||
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.file_count += rhs.file_count;
|
||||
self.visible_file_count += rhs.visible_file_count;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue