Two iterators (convenience functions), along with tests to move cursors (put and del still destroy cursors though)
[?]
Feb 7, 2021, 5:48 PM
LROAI3NBBSCU4T2YA6EHJYKKKL75AU5A7C7WIRCGIQ56S6HPLRXQCDependencies
- [2]
KM3JAFGPAdding a test for next/prev - [3]
EAAYH6BQDebugging put - [4]
PXF3R6SVImproving test coverage for btree::cursor - [5]
AOX2XQISActually, with the correct functions, Unsized pages are always slower than Sized pages (especially for writing) - [6]
W26CFMAQImproving safety of cursors - [7]
WS4ZQM4RDebugging, tests, etc. - [8]
DV4A2LR7Double-inserts (rebalancing near an internal deletion) - [9]
6UVFCERMFormatting, debugging, etc. - [10]
OTWDDJE7Trait/type cleanup - [11]
UUUVNC4DDebugging/cleanup around cursors - [12]
ONES3V46reference counting works for put - [13]
EYNN7RLSTests++ (including UUID) - [14]
QEUTVAZ4Splitting btree::page - [15]
7WJNSPEWUsing the same definition of the "occupied" field uniform everywhere - [16]
OP6SVMODResetting history - [17]
H3FVSQIQUnsized pages - [18]
6DCQHIFPMinor changes after benchmarking - [19]
OFINGD26implementing prev() on cursors (+ some cleanup) - [20]
KX3WVNZWTesting/debugging "rebalance causes split of the root" - [*]
UAQX27N4Tests
Change contents
- replacement in sanakirja-core/src/btree/page_unsized.rs at line 68
c: &Cursor,c: &PageCursor, - replacement in sanakirja-core/src/btree/page_unsized.rs at line 135
c: &Cursor,c: &PageCursor, - replacement in sanakirja-core/src/btree/page_unsized.rs at line 241
let rc = Cursor::new(m.other.as_page(), 0);let rc = PageCursor::new(m.other.as_page(), 0); - replacement in sanakirja-core/src/btree/page_unsized.rs at line 292
type Cursor = Cursor;type Cursor = PageCursor; - replacement in sanakirja-core/src/btree/page_unsized.rs at line 294
Cursor::new(p, -1)PageCursor::new(p, -1) - replacement in sanakirja-core/src/btree/page_unsized.rs at line 297
Cursor::after(p)PageCursor::after(p) - replacement in sanakirja-core/src/btree/page_unsized.rs at line 389
c: &mut Cursor,c: &mut PageCursor, - replacement in sanakirja-core/src/btree/page_unsized.rs at line 427
Cursor {PageCursor { - replacement in sanakirja-core/src/btree/page_unsized.rs at line 440
c: &mut Cursor,c: &mut PageCursor, - replacement in sanakirja-core/src/btree/page_unsized.rs at line 503
pub struct Cursor {pub struct PageCursor { - replacement in sanakirja-core/src/btree/page_unsized.rs at line 509
impl Cursor {pub(in super) fn new(p: crate::Page, cur: isize) -> Cursor {impl PageCursor {pub(in super) fn new(p: crate::Page, cur: isize) -> Self { - replacement in sanakirja-core/src/btree/page_unsized.rs at line 513
Cursor {PageCursor { - replacement in sanakirja-core/src/btree/page_unsized.rs at line 519
pub(in super) fn after(p: crate::Page) -> Cursor {pub(in super) fn after(p: crate::Page) -> Self { - replacement in sanakirja-core/src/btree/page_unsized.rs at line 522
Cursor {PageCursor { - replacement in sanakirja-core/src/btree/page_unsized.rs at line 528
pub(in super) fn last(p: crate::Page) -> Cursor {pub(in super) fn last(p: crate::Page) -> Self { - replacement in sanakirja-core/src/btree/page_unsized.rs at line 531
Cursor {PageCursor { - replacement in sanakirja-core/src/btree/page_unsized.rs at line 590
let mut rc = Cursor::new(m.other.as_page(), 0);let mut rc = PageCursor::new(m.other.as_page(), 0); - replacement in sanakirja-core/src/btree/page_unsized.rs at line 597
let mut rc = Cursor::new(m.other.as_page(), 0);let mut rc = PageCursor::new(m.other.as_page(), 0); - replacement in sanakirja-core/src/btree/page_unsized/rebalance.rs at line 18
let rc = super::Cursor::new(m.other.as_page(), 0);let rc = super::PageCursor::new(m.other.as_page(), 0); - replacement in sanakirja-core/src/btree/page_unsized/rebalance.rs at line 51
let lc = Cursor::after(m.modified.page.as_page());let lc = PageCursor::after(m.modified.page.as_page()); - replacement in sanakirja-core/src/btree/page_unsized/rebalance.rs at line 101
let lc = super::Cursor::last(m.other.as_page());let lc = super::PageCursor::last(m.other.as_page()); - replacement in sanakirja-core/src/btree/page_unsized/rebalance.rs at line 105
let rc = super::Cursor::new(m.modified.page.as_page(), 0);let rc = super::PageCursor::new(m.modified.page.as_page(), 0); - replacement in sanakirja-core/src/btree/page.rs at line 12
pub use super::page_unsized::Cursor;pub use super::page_unsized::PageCursor; - replacement in sanakirja-core/src/btree/page.rs at line 86
c: &Cursor,c: &PageCursor, - replacement in sanakirja-core/src/btree/page.rs at line 152
c: &Cursor,c: &PageCursor, - replacement in sanakirja-core/src/btree/page.rs at line 256
let rc = Cursor::new(m.other.as_page(), 0);let rc = PageCursor::new(m.other.as_page(), 0); - replacement in sanakirja-core/src/btree/page.rs at line 307
type Cursor = Cursor;type Cursor = PageCursor; - replacement in sanakirja-core/src/btree/page.rs at line 309
Cursor::new(p, -1)PageCursor::new(p, -1) - replacement in sanakirja-core/src/btree/page.rs at line 312
Cursor::after(p)PageCursor::after(p) - replacement in sanakirja-core/src/btree/page.rs at line 413
c: &mut Cursor,c: &mut PageCursor, - replacement in sanakirja-core/src/btree/page.rs at line 452
Cursor {PageCursor { - replacement in sanakirja-core/src/btree/page.rs at line 481
c: &mut Cursor,c: &mut PageCursor, - replacement in sanakirja-core/src/btree/page.rs at line 583
let mut rc = Cursor::new(m.other.as_page(), 0);let mut rc = PageCursor::new(m.other.as_page(), 0); - replacement in sanakirja-core/src/btree/page.rs at line 590
let mut rc = Cursor::new(m.other.as_page(), 0);let mut rc = PageCursor::new(m.other.as_page(), 0); - replacement in sanakirja-core/src/btree/page/rebalance.rs at line 17
let rc = super::Cursor::new(m.other.as_page(), 0);let rc = super::PageCursor::new(m.other.as_page(), 0); - replacement in sanakirja-core/src/btree/page/rebalance.rs at line 50
let lc = Cursor::after(m.modified.page.as_page());let lc = PageCursor::after(m.modified.page.as_page()); - replacement in sanakirja-core/src/btree/page/rebalance.rs at line 131
let lc = Cursor::last(m.other.as_page());let lc = PageCursor::last(m.other.as_page()); - replacement in sanakirja-core/src/btree/page/rebalance.rs at line 135
let rc = super::Cursor::new(m.modified.page.as_page(), 0);let rc = super::PageCursor::new(m.modified.page.as_page(), 0); - edit in sanakirja-core/src/btree/mod.rs at line 3
pub use cursor::{Cursor, iter, rev_iter, Iter, RevIter}; - edit in sanakirja-core/src/btree/cursor.rs at line 6
#[doc(hidden)] - replacement in sanakirja-core/src/btree/cursor.rs at line 7
pub struct PageCursor<K: Representable + ?Sized, V: Representable + ?Sized, P: BTreePage<K, V>> {pub(in super) struct PageCursor<K: Representable + ?Sized, V: Representable + ?Sized, P: BTreePage<K, V>> { - edit in sanakirja-core/src/btree/cursor.rs at line 46
}impl<K: Representable + ?Sized, V: Representable + ?Sized, P: BTreePage<K, V>>core::ops::Index<usize> for Cursor<K, V, P>{type Output = PageCursor<K, V, P>;fn index(&self, i: usize) -> &PageCursor<K, V, P> {assert!(i <= self.pointer);unsafe { &*self.stack.index(i).as_ptr() }}}impl<K: Representable + ?Sized, V: Representable + ?Sized, P: BTreePage<K, V>>core::ops::IndexMut<usize> for Cursor<K, V, P>{fn index_mut(&mut self, i: usize) -> &mut PageCursor<K, V, P> {assert!(i <= self.pointer);unsafe { &mut *self.stack.index_mut(i).as_mut_ptr() }} - replacement in sanakirja-core/src/btree/cursor.rs at line 63
pub fn push(&mut self, p: PageCursor<K, V, P>) {pub(in super) fn push(&mut self, p: PageCursor<K, V, P>) { - replacement in sanakirja-core/src/btree/cursor.rs at line 68
pub fn last(&mut self) -> &mut PageCursor<K, V, P> {pub(in super) fn last(&mut self) -> &mut PageCursor<K, V, P> { - replacement in sanakirja-core/src/btree/cursor.rs at line 74
pub fn current(&self) -> &PageCursor<K, V, P> {pub(in super) fn current(&self) -> &PageCursor<K, V, P> { - replacement in sanakirja-core/src/btree/cursor.rs at line 78
pub fn pointer(&self) -> usize {pub(in super) fn pointer(&self) -> usize { - replacement in sanakirja-core/src/btree/cursor.rs at line 82
pub fn pop(&mut self) {pub(in super) fn pop(&mut self) { - replacement in sanakirja-core/src/btree/cursor.rs at line 87
pub fn current_mut(&mut self) -> &mut PageCursor<K, V, P> {pub(in super) fn current_mut(&mut self) -> &mut PageCursor<K, V, P> { - edit in sanakirja-core/src/btree/cursor.rs at line 107[3.66515]→[3.11057:11101](∅→∅),[3.11101]→[3.34164:34236](∅→∅),[3.66557]→[3.34164:34236](∅→∅),[3.34236]→[3.11102:11118](∅→∅)
/*if current.cursor.is_none() {current.cursor = Some(P::first_cursor(page.as_page()));}*/ - edit in sanakirja-core/src/btree/cursor.rs at line 177
// Cursor invariant: the lower levels (in the tree, upper levels// on the stack) are the left children of the cursor's position on// a page. - replacement in sanakirja-core/src/btree/cursor.rs at line 189
// Then visit the right child (if any), i.e. push.P::move_next(current.page.as_page(), &mut current.cursor);// Then visit the left child of the page (if any), i.e. push. - edit in sanakirja-core/src/btree/cursor.rs at line 197
} else {P::move_next(current.page.as_page(), &mut current.cursor); - edit in sanakirja-core/src/btree/cursor.rs at line 199
P::move_next(current.page.as_page(), &mut current.cursor); - edit in sanakirja-core/src/btree/cursor.rs at line 206
} else {P::move_next(current.page.as_page(), &mut current.cursor); - edit in sanakirja-core/src/btree/cursor.rs at line 210
let current = unsafe { &mut *self.stack[self.pointer].as_mut_ptr() };P::move_next(current.page.as_page(), &mut current.cursor); - replacement in sanakirja-core/src/btree/cursor.rs at line 223
P::move_prev(current.page.as_page(), &mut current.cursor);let right = P::right_child(current.page.as_page(), ¤t.cursor);if right != 0 {let page = txn.load_page(right)?;let left = P::left_child(current.page.as_page(), ¤t.cursor);if left != 0 {let page = txn.load_page(left)?; - edit in sanakirja-core/src/btree/cursor.rs at line 230
} else {P::move_prev(current.page.as_page(), &mut current.cursor); - replacement in sanakirja-core/src/btree/cursor.rs at line 235
P::move_prev(current.page.as_page(), &mut current.cursor);let l = P::right_child(current.page.as_page(), ¤t.cursor);let l = P::left_child(current.page.as_page(), ¤t.cursor); - edit in sanakirja-core/src/btree/cursor.rs at line 242
} else {P::move_prev(current.page.as_page(), &mut current.cursor); - edit in sanakirja-core/src/btree/cursor.rs at line 249
let current = unsafe { &mut *self.stack[self.pointer].as_mut_ptr() };P::move_prev(current.page.as_page(), &mut current.cursor); - edit in sanakirja-core/src/btree/cursor.rs at line 256
} - edit in sanakirja-core/src/btree/cursor.rs at line 258
pub struct Iter<'a, T: LoadPage, K: Representable + ?Sized, V: Representable + ?Sized, P: BTreePage<K, V>> {txn: &'a T,cursor: Cursor<K, V, P>,} - edit in sanakirja-core/src/btree/cursor.rs at line 263
pub fn iter<'a, T, K, V, P>(txn: &'a T,db: &super::Db_<K, V, P>,origin: Option<(&K, Option<&V>)>) -> Result<Iter<'a, T, K, V, P>, T::Error>where T: LoadPage, K: Representable + ?Sized, V: Representable + ?Sized, P: BTreePage<K, V> {let mut cursor = Cursor::new(txn, db)?;cursor.set(txn, origin)?;Ok(Iter {cursor,txn,}) - edit in sanakirja-core/src/btree/cursor.rs at line 276[3.70763]
impl<'a, T: LoadPage, K: Representable + ?Sized + 'a, V: Representable + ?Sized + 'a, P: BTreePage<K, V> + 'a> Iterator for Iter<'a, T, K, V, P> {type Item = Result<(&'a K, &'a V), T::Error>;fn next(&mut self) -> Option<Self::Item> {self.cursor.next(self.txn).transpose()}}pub struct RevIter<'a, T: LoadPage, K: Representable + ?Sized, V: Representable + ?Sized, P: BTreePage<K, V>> {txn: &'a T,cursor: Cursor<K, V, P>,}pub fn rev_iter<'a, T, K, V, P>(txn: &'a T,db: &super::Db_<K, V, P>,origin: Option<(&K, Option<&V>)>) -> Result<RevIter<'a, T, K, V, P>, T::Error>where T: LoadPage, K: Representable + ?Sized, V: Representable + ?Sized, P: BTreePage<K, V> {let mut cursor = Cursor::new(txn, db)?;cursor.set(txn, origin)?;Ok(RevIter {cursor,txn,})}impl<'a, T: LoadPage, K: Representable + ?Sized + 'a, V: Representable + ?Sized + 'a, P: BTreePage<K, V> + 'a> Iterator for RevIter<'a, T, K, V, P> {type Item = Result<(&'a K, &'a V), T::Error>;fn next(&mut self) -> Option<Self::Item> {self.cursor.prev(self.txn).transpose()}} - edit in sanakirja/src/tests.rs at line 756
crate::debug::debug(&txn, &[&db], "debug", true); - edit in sanakirja/src/tests.rs at line 759
debug!("a {:?} {:?}", i, k); - edit in sanakirja/src/tests.rs at line 762
debug!("{:?}", i); - edit in sanakirja/src/tests.rs at line 763
crate::debug::debug(&txn, &[&db], "debug", true);debug!("======="); - replacement in sanakirja/src/tests.rs at line 765
debug!("{:?} {:?}", i, k);debug!("b {:?} {:?}", i, k); - edit in sanakirja/src/tests.rs at line 769
debug!("======="); - edit in sanakirja/src/tests.rs at line 771
debug!("c {:?} {:?}", i, k); - replacement in sanakirja/src/tests.rs at line 774
debug!("{:?}", i);}for i in (0..75).rev() {let (k, v) = cursor.prev(&txn).unwrap().unwrap();debug!("d {:?} {:?}", i, k);assert_eq!(*k, i);assert_eq!(v.0[0], i);}crate::debug::debug(&txn, &[&db], "debug", true);let i0 = 30;for (kv, n) in btree::rev_iter(&txn, &db, Some((&i0, None))).unwrap().zip((0..=i0).rev()){let (k, v) = kv.unwrap();assert_eq!(*k, n);debug!("k = {:?}", k);}let i0 = 40;for (kv, n) in btree::iter(&txn, &db, Some((&i0, None))).unwrap().zip(i0..) {let (k, v) = kv.unwrap();assert_eq!(*k, n);debug!("k = {:?}", k);