fn check_invariants_at(
        &self,
        page: PageId,
        expected_level: Option<u8>,
        infimum: Option<&Datom>,
        supremum: Option<&Datom>,
    ) -> io::Result<()> {
        let node = get_node(&self.store, page);

        if let Some(level) = expected_level {
            assert_eq!(node.level, level);
        }

        // We track two infima: one for the datoms array, and one for the
        // children. For the datoms array, we need every datom to be larger than
        // the previous one. For the children, we need every child to be larger
        // than the previous midpoint datom.
        let mut all_infimum = infimum;
        let mut mid_infimum = infimum;

        for (i, datom) in node.datoms.iter().enumerate() {
            if let Some(inf) = all_infimum {
                assert_eq!(
                    self.comparator.cmp(inf, datom, &self.heap), Ordering::Less,
                    "Violation at page {:?}: infimum ({:?}) >= datom {} ({:?}).", page, inf, i, datom
                );
            }
            if node.is_midpoint_at(i) {
                assert!(
                    node.level > 0,
                    "Violation at page {:?}: node {} at level 0 has child.", page, i,
                );
                self.check_invariants_at(
                    node.children[i],
                    // The level of the child should be one less than the parent.
                    Some(node.level - 1),
                    mid_infimum,
                    Some(datom)
                )?;
                mid_infimum = Some(datom);
            }
            all_infimum = Some(datom);
        }

        if let (Some(inf), Some(sup)) = (all_infimum, supremum) {
            assert_eq!(
                self.comparator.cmp(inf, sup, &self.heap), Ordering::Less,
                "Violation at page {:?}, final infimum >= supremum.", page,
            );
        }

        if node.is_midpoint_at(node.datoms.len()) {
            self.check_invariants_at(
                node.children[node.datoms.len()],
                Some(node.level - 1),
                mid_infimum,
                supremum,
            )?;
        } else {
            assert_eq!(
                node.level, 0,
                "Violation at page {:?}: only level 0 nodes can lack a final child.", page,
            );
        }

        Ok(())
    }
/// Assert that the node at the given page, and its children, are well-formed.
///
/// This is used in tests and during fuzzing. Checks furthermore that all
/// datoms in the node are greater than the infimum, if one is provided, and
/// smaller than the supremum, if one is provided.
Assert that the node at the given page, and its children, are well-formed.
This is used in tests and during fuzzing. Checks furthermore that all
datoms in the node are greater than the infimum, if one is provided, and
smaller than the supremum, if one is provided.
Assert that the node at the given page and its children are well - formed . This is used in tests and during fuzzing . Checks furthermore that all datoms in the node are greater than the infimum if one is provided and smaller than the supremum if one is provided .
fn check_invariants_at(
        &self,
        page: PageId,
        expected_level: Option<u8>,
        infimum: Option<&Datom>,
        supremum: Option<&Datom>,
    ) -> io::Result<()> {
        let node = get_node(&self.store, page);
        if let Some(level) = expected_level {
            assert_eq!(node.level, level);
        }
        // We track two infima: one for the datoms array, and one for the
        // children. For the datoms array, we need every datom to be larger than
        // the previous one. For the children, we need every child to be larger
        // than the previous midpoint datom.
        let mut all_infimum = infimum;
        let mut mid_infimum = infimum;
        for (i, datom) in node.datoms.iter().enumerate() {
            if let Some(inf) = all_infimum {
                assert_eq!(
                    self.comparator.cmp(inf, datom, &self.heap), Ordering::Less,
                    "Violation at page {:?}: infimum ({:?}) >= datom {} ({:?}).", page, inf, i, datom
                );
            }
            if node.is_midpoint_at(i) {
                assert!(
                    node.level > 0,
                    "Violation at page {:?}: node {} at level 0 has child.", page, i,
                );
                self.check_invariants_at(
                    node.children[i],
                    // The level of the child should be one less than the parent.
                    Some(node.level - 1),
                    mid_infimum,
                    Some(datom)
                )?;
                mid_infimum = Some(datom);
            }
            all_infimum = Some(datom);
        }
        if let (Some(inf), Some(sup)) = (all_infimum, supremum) {
            assert_eq!(
                self.comparator.cmp(inf, sup, &self.heap), Ordering::Less,
                "Violation at page {:?}, final infimum >= supremum.", page,
            );
        }
        if node.is_midpoint_at(node.datoms.len()) {
            self.check_invariants_at(
                node.children[node.datoms.len()],
                Some(node.level - 1),
                mid_infimum,
                supremum,
            )?;
        } else {
            assert_eq!(
                node.level, 0,
                "Violation at page {:?}: only level 0 nodes can lack a final child.", page,
            );
        }
        Ok(())
    }
fn check_invariants_at ( & self , page : PageId , expected_level : Option < u8 > , infimum : Option < & Datom > , supremum : Option < & Datom > , ) -> io :: Result < ( ) > { let node = get_node ( & self . store , page ) ; if let Some ( level ) = expected_level { assert_eq ! ( node level level ) ; } // We track two infima: one for the datoms array, and one for the // children. For the datoms array, we need every datom to be larger than // the previous one. For the children, we need every child to be larger // than the previous midpoint datom. let mut all_infimum = infimum ; let mut mid_infimum = infimum ; for ( i , datom ) in node . datoms . iter ( ) . enumerate ( ) { if let Some ( inf ) = all_infimum { assert_eq ! ( self comparator cmp ( inf datom self heap ) Ordering Less " " page inf i datom ) ; } if node . is_midpoint_at ( i ) { assert ! ( node level 0 " " page i ) ; self . check_invariants_at ( node . children [ i ] , // The level of the child should be one less than the parent. Some ( node . level - 1 ) , mid_infimum , Some ( datom ) ) ? ; mid_infimum = Some ( datom ) ; } all_infimum = Some ( datom ) ; } if let ( Some ( inf ) , Some ( sup ) ) = ( all_infimum , supremum ) { assert_eq ! ( self comparator cmp ( inf sup self heap ) Ordering Less " " page ) ; } if node . is_midpoint_at ( node . datoms . len ( ) ) { self . check_invariants_at ( node . children [ node . datoms . len ( ) ] , Some ( node . level - 1 ) , mid_infimum , supremum , ) ? ; } else { assert_eq ! ( node level 0 " " page ) ; } Ok ( ( ) ) }
Assert that the node at the given page, and its children, are well-formed.
Assert that the node at the given page and its children are well - formed .
&self
page
PageId
expected_level
Option<u8>
infimum
Option<&Datom>
supremum
Option<&Datom>
&self
page
PageId
expected_level
Option<u8>
infimum
Option<&Datom>
supremum
Option<&Datom>