debugs n stuff
This commit is contained in:
parent
2be18a200f
commit
74a6c78fff
3 changed files with 28 additions and 32 deletions
|
@ -205,7 +205,7 @@ where
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn prev(&mut self) {
|
pub fn prev(&mut self) {
|
||||||
self.search_backward(|_| Ordering::Greater)
|
self.search_backward(|_| Ordering::Equal)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
|
@ -283,7 +283,7 @@ where
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn next(&mut self) {
|
pub fn next(&mut self) {
|
||||||
self.search_forward(|_| Ordering::Less)
|
self.search_forward(|_| Ordering::Equal)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
|
@ -322,25 +322,18 @@ where
|
||||||
if entry.index < child_summaries.len() {
|
if entry.index < child_summaries.len() {
|
||||||
let index = child_summaries[entry.index..]
|
let index = child_summaries[entry.index..]
|
||||||
.partition_point(|item| filter_node(item).is_lt());
|
.partition_point(|item| filter_node(item).is_lt());
|
||||||
if index < child_summaries.len() - entry.index {
|
|
||||||
entry.index += index;
|
|
||||||
}
|
|
||||||
|
|
||||||
let position = Some(entry.index)
|
entry.index += index;
|
||||||
.filter(|index| *index < child_summaries.len())
|
|
||||||
.unwrap_or(child_summaries.len());
|
|
||||||
|
|
||||||
if let Some(summary) = child_summaries.get(position) {
|
if let Some(summary) = child_summaries.get(entry.index) {
|
||||||
entry.position.add_summary(summary, self.cx);
|
entry.position.add_summary(summary, self.cx);
|
||||||
self.position.add_summary(summary, self.cx);
|
self.position.add_summary(summary, self.cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dbg!((entry.index, child_trees.len()));
|
|
||||||
|
|
||||||
child_trees.get(entry.index)
|
child_trees.get(entry.index)
|
||||||
}
|
}
|
||||||
Node::Leaf { item_summaries, .. } => {
|
Node::Leaf { item_summaries, .. } => {
|
||||||
dbg!("Ayo");
|
|
||||||
if !descend {
|
if !descend {
|
||||||
let item_summary = &item_summaries[entry.index];
|
let item_summary = &item_summaries[entry.index];
|
||||||
entry.index += 1;
|
entry.index += 1;
|
||||||
|
@ -351,15 +344,10 @@ where
|
||||||
if entry.index < item_summaries.len() {
|
if entry.index < item_summaries.len() {
|
||||||
let index = item_summaries[entry.index..]
|
let index = item_summaries[entry.index..]
|
||||||
.partition_point(|item| filter_node(item).is_lt());
|
.partition_point(|item| filter_node(item).is_lt());
|
||||||
if index < item_summaries.len() - entry.index {
|
|
||||||
entry.index += index;
|
|
||||||
}
|
|
||||||
entry.index += index;
|
|
||||||
let position = Some(entry.index)
|
|
||||||
.filter(|index| *index < item_summaries.len())
|
|
||||||
.unwrap_or(item_summaries.len());
|
|
||||||
|
|
||||||
if let Some(summary) = item_summaries.get(position) {
|
entry.index += index;
|
||||||
|
|
||||||
|
if let Some(summary) = item_summaries.get(entry.index) {
|
||||||
entry.position.add_summary(summary, self.cx);
|
entry.position.add_summary(summary, self.cx);
|
||||||
self.position.add_summary(summary, self.cx);
|
self.position.add_summary(summary, self.cx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ use arrayvec::ArrayVec;
|
||||||
pub use cursor::{Cursor, FilterCursor, Iter};
|
pub use cursor::{Cursor, FilterCursor, Iter};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use std::fmt::Debug;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::{cmp::Ordering, fmt, iter::FromIterator, sync::Arc};
|
use std::{cmp::Ordering, fmt, iter::FromIterator, sync::Arc};
|
||||||
|
@ -54,7 +55,6 @@ impl Summary for &'static () {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_summary(&mut self, _: &Self, _: &()) {}
|
fn add_summary(&mut self, _: &Self, _: &()) {}
|
||||||
// fn sub_summary(&mut self, _: &Self, _: &()) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Each [`Summary`] type can have more than one [`Dimension`] type that it measures.
|
/// Each [`Summary`] type can have more than one [`Dimension`] type that it measures.
|
||||||
|
@ -214,14 +214,20 @@ impl<T: Item> SumTree<T> {
|
||||||
let mut iter = iter.into_iter().fuse().peekable();
|
let mut iter = iter.into_iter().fuse().peekable();
|
||||||
while iter.peek().is_some() {
|
while iter.peek().is_some() {
|
||||||
let items: ArrayVec<T, { 2 * TREE_BASE }> = iter.by_ref().take(2 * TREE_BASE).collect();
|
let items: ArrayVec<T, { 2 * TREE_BASE }> = iter.by_ref().take(2 * TREE_BASE).collect();
|
||||||
let item_summaries: ArrayVec<T::Summary, { 2 * TREE_BASE }> =
|
let item_summaries: ArrayVec<T::Summary, { 2 * TREE_BASE }> = items
|
||||||
items.iter().map(|item| item.summary(cx)).collect();
|
.iter()
|
||||||
|
.scan(None, |previous_item, item| {
|
||||||
let mut summary = item_summaries[0].clone();
|
let summary = item.summary(cx);
|
||||||
for item_summary in &item_summaries[1..] {
|
let current_item = if let Some(mut base) = previous_item.take() {
|
||||||
<T::Summary as Summary>::add_summary(&mut summary, item_summary, cx);
|
<T::Summary as Summary>::add_summary(&mut base, &summary, cx);
|
||||||
}
|
base
|
||||||
|
} else {
|
||||||
|
summary
|
||||||
|
};
|
||||||
|
_ = previous_item.insert(current_item.clone());
|
||||||
|
Some(current_item)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
nodes.push(Node::Leaf {
|
nodes.push(Node::Leaf {
|
||||||
items,
|
items,
|
||||||
item_summaries,
|
item_summaries,
|
||||||
|
@ -1189,9 +1195,11 @@ mod tests {
|
||||||
// Multiple-element tree
|
// Multiple-element tree
|
||||||
let mut tree = SumTree::default();
|
let mut tree = SumTree::default();
|
||||||
tree.extend(vec![1, 2, 3, 4, 5, 6], &());
|
tree.extend(vec![1, 2, 3, 4, 5, 6], &());
|
||||||
|
|
||||||
let mut cursor = tree.cursor::<IntegersSummary>(&());
|
let mut cursor = tree.cursor::<IntegersSummary>(&());
|
||||||
|
|
||||||
assert_eq!(cursor.slice(&Count(2), Bias::Right).items(&()), [1, 2]);
|
let slice = cursor.slice(&Count(2), Bias::Right);
|
||||||
|
assert_eq!(slice.items(&()), [1, 2]);
|
||||||
assert_eq!(cursor.item(), Some(&3));
|
assert_eq!(cursor.item(), Some(&3));
|
||||||
assert_eq!(cursor.prev_item(), Some(&2));
|
assert_eq!(cursor.prev_item(), Some(&2));
|
||||||
assert_eq!(cursor.next_item(), Some(&4));
|
assert_eq!(cursor.next_item(), Some(&4));
|
||||||
|
|
|
@ -406,9 +406,9 @@ mod tests {
|
||||||
map.insert("baa", 3);
|
map.insert("baa", 3);
|
||||||
map.insert("baaab", 4);
|
map.insert("baaab", 4);
|
||||||
map.insert("c", 5);
|
map.insert("c", 5);
|
||||||
dbg!(&map);
|
|
||||||
let result = map
|
let items = map.iter_from(&"ba");
|
||||||
.iter_from(&"ba")
|
let result = items
|
||||||
.take_while(|(key, _)| key.starts_with("ba"))
|
.take_while(|(key, _)| key.starts_with("ba"))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue