Commit e40fd791 authored by Hai Dang's avatar Hai Dang
Browse files

remove unlink from arena

parent c6666053
Pipeline #42508 passed with stage
in 22 minutes and 24 seconds
......@@ -32,18 +32,6 @@ impl<'arena, 'id, T> Node<'arena, 'id, T> {
self.next
}
/// Unlink the nodes adjacent to the provided node (but do not touch the node itself).
fn unlink(node: NodeRef<'arena, 'id, T>, token: &mut GhostToken<'id>) {
let old_prev = node.borrow(token).prev;
let old_next = node.borrow(token).next;
if let Some(next) = old_next {
next.borrow_mut(token).prev = old_prev;
}
if let Some(prev) = old_prev {
prev.borrow_mut(token).next = old_next;
}
}
/// Insert `node2` right after `node1` in the list.
pub fn insert_next(
node1: NodeRef<'arena, 'id, T>,
......@@ -51,7 +39,7 @@ impl<'arena, 'id, T> Node<'arena, 'id, T> {
token: &mut GhostToken<'id>,
) {
// Step 1: unlink the prev and next pointers nodes adjacent to node2.
Self::unlink(node2, token);
Self::remove(node2, token);
// Step 2: link node1.next pointer and node1.next.prev pointer to node2.
let node1_old_next : Option<NodeRef<_>> = node1.borrow(token).next;
......@@ -66,10 +54,17 @@ impl<'arena, 'id, T> Node<'arena, 'id, T> {
node2.next = node1_old_next;
}
/// Remove the links of this node to and from its adjacent nodes.
/// Remove this node to and from its adjacent nodes.
pub fn remove(node: NodeRef<'arena, 'id, T>, token: &mut GhostToken<'id>) {
// Step 1: unlink the prev and next pointers nodes adjacent to node.
Self::unlink(node, token);
let old_prev = node.borrow(token).prev;
let old_next = node.borrow(token).next;
if let Some(next) = old_next {
next.borrow_mut(token).prev = old_prev;
}
if let Some(prev) = old_prev {
prev.borrow_mut(token).next = old_next;
}
// Step 2: null out the prev and next pointers.
let node = node.borrow_mut(token);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment