@@ -366,30 +366,6 @@ pub struct BTreeCursor {
366
366
empty_record : Cell < bool > ,
367
367
}
368
368
369
- /// Stack of pages representing the tree traversal order.
370
- /// current_page represents the current page being used in the tree and current_page - 1 would be
371
- /// the parent. Using current_page + 1 or higher is undefined behaviour.
372
- struct PageStack {
373
- /// Pointer to the current page being consumed
374
- current_page : Cell < i32 > ,
375
- /// List of pages in the stack. Root page will be in index 0
376
- stack : RefCell < [ Option < PageRef > ; BTCURSOR_MAX_DEPTH + 1 ] > ,
377
- /// List of cell indices in the stack.
378
- /// cell_indices[current_page] is the current cell index being consumed. Similarly
379
- /// cell_indices[current_page-1] is the cell index of the parent of the current page
380
- /// that we save in case of going back up.
381
- /// There are two points that need special attention:
382
- /// If cell_indices[current_page] = -1, it indicates that the current iteration has reached the start of the current_page
383
- /// If cell_indices[current_page] = `cell_count`, it means that the current iteration has reached the end of the current_page
384
- cell_indices : RefCell < [ i32 ; BTCURSOR_MAX_DEPTH + 1 ] > ,
385
- }
386
-
387
- struct CellArray {
388
- cells : Vec < & ' static mut [ u8 ] > , // TODO(pere): make this with references
389
-
390
- number_of_cells_per_page : Vec < u16 > , // number of cells in each page
391
- }
392
-
393
369
impl BTreeCursor {
394
370
pub fn new (
395
371
mv_cursor : Option < Rc < RefCell < MvCursor > > > ,
@@ -3935,6 +3911,24 @@ fn validate_cells_after_insertion(cell_array: &CellArray, leaf_data: bool) {
3935
3911
}
3936
3912
}
3937
3913
3914
+ /// Stack of pages representing the tree traversal order.
3915
+ /// current_page represents the current page being used in the tree and current_page - 1 would be
3916
+ /// the parent. Using current_page + 1 or higher is undefined behaviour.
3917
+ struct PageStack {
3918
+ /// Pointer to the current page being consumed
3919
+ current_page : Cell < i32 > ,
3920
+ /// List of pages in the stack. Root page will be in index 0
3921
+ stack : RefCell < [ Option < PageRef > ; BTCURSOR_MAX_DEPTH + 1 ] > ,
3922
+ /// List of cell indices in the stack.
3923
+ /// cell_indices[current_page] is the current cell index being consumed. Similarly
3924
+ /// cell_indices[current_page-1] is the cell index of the parent of the current page
3925
+ /// that we save in case of going back up.
3926
+ /// There are two points that need special attention:
3927
+ /// If cell_indices[current_page] = -1, it indicates that the current iteration has reached the start of the current_page
3928
+ /// If cell_indices[current_page] = `cell_count`, it means that the current iteration has reached the end of the current_page
3929
+ cell_indices : RefCell < [ i32 ; BTCURSOR_MAX_DEPTH + 1 ] > ,
3930
+ }
3931
+
3938
3932
impl PageStack {
3939
3933
fn increment_current ( & self ) {
3940
3934
self . current_page . set ( self . current_page . get ( ) + 1 ) ;
@@ -4056,6 +4050,13 @@ impl PageStack {
4056
4050
}
4057
4051
}
4058
4052
4053
+ /// Used for redistributing cells during a balance operation.
4054
+ struct CellArray {
4055
+ cells : Vec < & ' static mut [ u8 ] > , // TODO(pere): make this with references
4056
+
4057
+ number_of_cells_per_page : Vec < u16 > , // number of cells in each page
4058
+ }
4059
+
4059
4060
impl CellArray {
4060
4061
pub fn cell_size ( & self , cell_idx : usize ) -> u16 {
4061
4062
self . cells [ cell_idx] . len ( ) as u16
@@ -4739,7 +4740,7 @@ fn fill_cell_payload(
4739
4740
}
4740
4741
4741
4742
// we still have bytes to add, we will need to allocate new overflow page
4742
- let overflow_page = allocate_overflow_page ( pager. clone ( ) ) ;
4743
+ let overflow_page = pager. allocate_overflow_page ( ) ;
4743
4744
overflow_pages. push ( overflow_page. clone ( ) ) ;
4744
4745
{
4745
4746
let id = overflow_page. get ( ) . id as u32 ;
@@ -4762,20 +4763,6 @@ fn fill_cell_payload(
4762
4763
assert_eq ! ( cell_size, cell_payload. len( ) ) ;
4763
4764
}
4764
4765
4765
- /// Allocate a new overflow page.
4766
- /// This is done when a cell overflows and new space is needed.
4767
- fn allocate_overflow_page ( pager : Rc < Pager > ) -> PageRef {
4768
- let page = pager. allocate_page ( ) . unwrap ( ) ;
4769
- tracing:: debug!( "allocate_overflow_page(id={})" , page. get( ) . id) ;
4770
-
4771
- // setup overflow page
4772
- let contents = page. get ( ) . contents . as_mut ( ) . unwrap ( ) ;
4773
- let buf = contents. as_ptr ( ) ;
4774
- buf. fill ( 0 ) ;
4775
-
4776
- page
4777
- }
4778
-
4779
4766
/// Returns the maximum payload size (X) that can be stored directly on a b-tree page without spilling to overflow pages.
4780
4767
///
4781
4768
/// For table leaf pages: X = usable_size - 35
0 commit comments