using BoxedNode alias instead of Rc<Node>

This commit is contained in:
Janis 2023-04-06 11:47:34 +02:00
parent 6762812ec5
commit e1f59b1b46

View file

@ -25,7 +25,7 @@ pub struct BTreeLeafNode {
#[derive(Debug, Clone)]
pub enum NodePtr {
Unvisited(KeyPtr),
Visited { key: KeyPtr, node: Rc<Node> }, // TODO: this doesnt need to be an Rc, can just be a NonNull with manual memory management
Visited { key: KeyPtr, node: BoxedNode }, // TODO: this doesnt need to be an Rc, can just be a NonNull with manual memory management
}
impl NodePtr {
@ -36,7 +36,7 @@ impl NodePtr {
}
}
pub fn node(&self) -> Option<&Rc<Node>> {
pub fn node(&self) -> Option<&BoxedNode> {
match self {
NodePtr::Unvisited(_) => None,
NodePtr::Visited { node, .. } => Some(&node),
@ -62,7 +62,7 @@ impl BTreeInternalNode {
&self,
idx: usize,
volume: &super::volume::Volume<R>,
) -> Result<Rc<Node>> {
) -> Result<BoxedNode> {
match self.children.get(idx) {
Some(child) => self.visit_child_inner(child, volume),
None => Err(Error::OutOfBounds {
@ -76,7 +76,7 @@ impl BTreeInternalNode {
&self,
child: &Cell<NodePtr>,
volume: &super::volume::Volume<R>,
) -> Result<Rc<Node>> {
) -> Result<BoxedNode> {
match unsafe { &*child.as_ptr() } {
NodePtr::Unvisited(keyptr) => {
let node = volume
@ -105,7 +105,7 @@ impl BTreeInternalNode {
pub fn visit_children<'a, 'b, R: super::Read>(
&'a self,
volume: &'b super::volume::Volume<R>,
) -> impl Iterator<Item = (usize, Result<Rc<Node>>)> + 'a
) -> impl Iterator<Item = (usize, Result<BoxedNode>)> + 'a
where
'b: 'a,
{
@ -680,7 +680,7 @@ where
}
}
pub fn new(volume: Rc<Volume<R>>, start: Rc<Node>, end: Rc<Node>) -> Self {
pub fn new(volume: Rc<Volume<R>>, start: BoxedNode, end: BoxedNode) -> Self {
Self::from_handles(volume, NodeHandle::start(start), NodeHandle::end(end))
}