fn replace_child(
        &mut self,
        old: &WeakRef,
        old_id: KoID,
        new: WeakRef,
        new_range: Option<(usize, usize)>,
    ) {
        let (tag, other) = self.type_.get_tag_and_other(old);
        let arc_other_child = other.upgrade().unwrap();
        let mut other_child = arc_other_child.inner.borrow_mut();
        let mut unwanted = VecDeque::<usize>::new();
        if let Some((new_start, new_end)) = new_range {
            let other_start = other_child.parent_offset / PAGE_SIZE;
            let other_end = other_child.parent_limit / PAGE_SIZE;
            let start = new_start / PAGE_SIZE;
            let end = new_end / PAGE_SIZE;
            for i in 0..self.size / PAGE_SIZE {
                let not_in_range =
                    !((start <= i && end > i) || (other_start <= i && other_end > i));
                if not_in_range {
                    // if not in this node's range
                    if self.frames.contains_key(&i) {
                        // if the frame is in our, remove it
                        assert!(self.frames.remove(&i).is_some());
                    } else {
                        // or it is in our ancestor, tell them we do not need it.
                        unwanted.push_back(i + self.parent_offset / PAGE_SIZE);
                    }
                } else {
                    // if in this node's range, check if it can be moved
                    if let Some(frame) = self.frames.get(&i) {
                        if frame.tag.is_split() {
                            let mut new_frame = self.frames.remove(&i).unwrap();
                            if self.contiguous
                                && !other_child.contiguous
                                && new_frame.pin_count >= 1
                            {
                                new_frame.pin_count -= 1;
                            }
                            if new_frame.tag == tag && other_start <= i && other_end > i {
                                new_frame.tag = PageStateTag::Owned;
                                let new_key = i - other_child.parent_offset / PAGE_SIZE;
                                other_child.frames.insert(new_key, new_frame);
                            }
                        }
                    }
                }
            }
        }

        self.release_unwanted_pages_in_parent(unwanted);

        if old_id == self.owner {
            let mut option_parent = self.parent.clone();
            let mut child = self.self_ref.clone();
            let mut skip_owner = old_id;
            while let Some(parent) = option_parent {
                let mut parent_inner = parent.inner.borrow_mut();
                if parent_inner.owner == old_id {
                    let (_, other) = parent_inner.type_.get_tag_and_other(&child);
                    let new_owner = other.upgrade().unwrap().inner.borrow().owner;
                    child = parent_inner.self_ref.clone();
                    assert_ne!(new_owner, skip_owner);
                    parent_inner.owner = new_owner;
                    skip_owner = new_owner;
                    option_parent = parent_inner.parent.clone();
                } else {
                    break;
                }
            }
        }

        self.owner = other_child.owner;
        match &mut self.type_ {
            VMOType::Hidden { left, right, .. } => {
                if left.ptr_eq(old) {
                    *left = new;
                } else if right.ptr_eq(old) {
                    *right = new;
                } else {
                    panic!();
                }
            }
            _ => panic!(),
        }
    }
/// Replace a child of the hidden node.
/// `new_start` and `new_end` are in bytes
Replace a child of the hidden node.
Replace a child of the hidden node .
fn replace_child(
        &mut self,
        old: &WeakRef,
        old_id: KoID,
        new: WeakRef,
        new_range: Option<(usize, usize)>,
    ) {
        let (tag, other) = self.type_.get_tag_and_other(old);
        let arc_other_child = other.upgrade().unwrap();
        let mut other_child = arc_other_child.inner.borrow_mut();
        let mut unwanted = VecDeque::<usize>::new();
        if let Some((new_start, new_end)) = new_range {
            let other_start = other_child.parent_offset / PAGE_SIZE;
            let other_end = other_child.parent_limit / PAGE_SIZE;
            let start = new_start / PAGE_SIZE;
            let end = new_end / PAGE_SIZE;
            for i in 0..self.size / PAGE_SIZE {
                let not_in_range =
                    !((start <= i && end > i) || (other_start <= i && other_end > i));
                if not_in_range {
                    // if not in this node's range
                    if self.frames.contains_key(&i) {
                        // if the frame is in our, remove it
                        assert!(self.frames.remove(&i).is_some());
                    } else {
                        // or it is in our ancestor, tell them we do not need it.
                        unwanted.push_back(i + self.parent_offset / PAGE_SIZE);
                    }
                } else {
                    // if in this node's range, check if it can be moved
                    if let Some(frame) = self.frames.get(&i) {
                        if frame.tag.is_split() {
                            let mut new_frame = self.frames.remove(&i).unwrap();
                            if self.contiguous
                                && !other_child.contiguous
                                && new_frame.pin_count >= 1
                            {
                                new_frame.pin_count -= 1;
                            }
                            if new_frame.tag == tag && other_start <= i && other_end > i {
                                new_frame.tag = PageStateTag::Owned;
                                let new_key = i - other_child.parent_offset / PAGE_SIZE;
                                other_child.frames.insert(new_key, new_frame);
                            }
                        }
                    }
                }
            }
        }
        self.release_unwanted_pages_in_parent(unwanted);
        if old_id == self.owner {
            let mut option_parent = self.parent.clone();
            let mut child = self.self_ref.clone();
            let mut skip_owner = old_id;
            while let Some(parent) = option_parent {
                let mut parent_inner = parent.inner.borrow_mut();
                if parent_inner.owner == old_id {
                    let (_, other) = parent_inner.type_.get_tag_and_other(&child);
                    let new_owner = other.upgrade().unwrap().inner.borrow().owner;
                    child = parent_inner.self_ref.clone();
                    assert_ne!(new_owner, skip_owner);
                    parent_inner.owner = new_owner;
                    skip_owner = new_owner;
                    option_parent = parent_inner.parent.clone();
                } else {
                    break;
                }
            }
        }
        self.owner = other_child.owner;
        match &mut self.type_ {
            VMOType::Hidden { left, right, .. } => {
                if left.ptr_eq(old) {
                    *left = new;
                } else if right.ptr_eq(old) {
                    *right = new;
                } else {
                    panic!();
                }
            }
            _ => panic!(),
        }
    }
fn replace_child ( & mut self , old : & WeakRef , old_id : KoID , new : WeakRef , new_range : Option < ( usize , usize ) > , ) { let ( tag , other ) = self . type_ . get_tag_and_other ( old ) ; let arc_other_child = other . upgrade ( ) . unwrap ( ) ; let mut other_child = arc_other_child . inner . borrow_mut ( ) ; let mut unwanted = VecDeque :: < usize > :: new ( ) ; if let Some ( ( new_start , new_end ) ) = new_range { let other_start = other_child . parent_offset / PAGE_SIZE ; let other_end = other_child . parent_limit / PAGE_SIZE ; let start = new_start / PAGE_SIZE ; let end = new_end / PAGE_SIZE ; for i in 0 .. self . size / PAGE_SIZE { let not_in_range = ! ( ( start <= i && end > i ) || ( other_start <= i && other_end > i ) ) ; if not_in_range { // if not in this node's range if self . frames . contains_key ( & i ) { // if the frame is in our, remove it assert ! ( self frames remove ( i ) is_some ( ) ) ; } else { // or it is in our ancestor, tell them we do not need it. unwanted . push_back ( i + self . parent_offset / PAGE_SIZE ) ; } } else { // if in this node's range, check if it can be moved if let Some ( frame ) = self . frames . get ( & i ) { if frame . tag . is_split ( ) { let mut new_frame = self . frames . remove ( & i ) . unwrap ( ) ; if self . contiguous && ! other_child . contiguous && new_frame . pin_count >= 1 { new_frame . pin_count -= 1 ; } if new_frame . tag == tag && other_start <= i && other_end > i { new_frame . tag = PageStateTag :: Owned ; let new_key = i - other_child . parent_offset / PAGE_SIZE ; other_child . frames . insert ( new_key , new_frame ) ; } } } } } } self . release_unwanted_pages_in_parent ( unwanted ) ; if old_id == self . owner { let mut option_parent = self . parent . clone ( ) ; let mut child = self . self_ref . clone ( ) ; let mut skip_owner = old_id ; while let Some ( parent ) = option_parent { let mut parent_inner = parent . inner . borrow_mut ( ) ; if parent_inner . owner == old_id { let ( _ , other ) = parent_inner . type_ . get_tag_and_other ( & child ) ; let new_owner = other . upgrade ( ) . unwrap ( ) . inner . borrow ( ) . owner ; child = parent_inner . self_ref . clone ( ) ; assert_ne ! ( new_owner skip_owner ) ; parent_inner . owner = new_owner ; skip_owner = new_owner ; option_parent = parent_inner . parent . clone ( ) ; } else { break ; } } } self . owner = other_child . owner ; match & mut self . type_ { VMOType :: Hidden { left , right , .. } => { if left . ptr_eq ( old ) { * left = new ; } else if right . ptr_eq ( old ) { * right = new ; } else { panic ! ( ) ; } } _ => panic ! ( ) , } }
Replace a child of the hidden node.
Replace a child of the hidden node .
&mut self
old
&WeakRef
old_id
KoID
new
WeakRef
new_range
Option<(usize, usize)>
&mut self
old
&WeakRef
old_id
KoID
new
WeakRef
new_range
Option<(usize, usize)>