Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
FP
ghostcell
Commits
3e17f3c8
Commit
3e17f3c8
authored
Feb 26, 2021
by
Hai Dang
Browse files
renaming and doc comments
parent
70de5343
Pipeline
#42496
passed with stage
in 22 minutes and 42 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ghostcell/src/dlist_arena.rs
View file @
3e17f3c8
...
...
@@ -10,6 +10,7 @@ pub struct Node<'arena, 'id, T> {
pub
type
NodeRef
<
'arena
,
'id
,
T
>
=
&
'arena
GhostCell
<
'id
,
Node
<
'arena
,
'id
,
T
>>
;
impl
<
'arena
,
'id
,
T
>
Node
<
'arena
,
'id
,
T
>
{
/// Create a new isolated node from T. Requires an arena.
pub
fn
new
(
data
:
T
,
arena
:
&
'arena
TypedArena
<
Node
<
'arena
,
'id
,
T
>>
...
...
@@ -43,27 +44,29 @@ impl<'arena, 'id, T> Node<'arena, 'id, T> {
}
}
/// Insert `node2` right after `node1` in the list.
pub
fn
insert_next
(
node
:
NodeRef
<
'arena
,
'id
,
T
>
,
n
ext
:
NodeRef
<
'arena
,
'id
,
T
>
,
node
1
:
NodeRef
<
'arena
,
'id
,
T
>
,
n
ode2
:
NodeRef
<
'arena
,
'id
,
T
>
,
token
:
&
mut
GhostToken
<
'id
>
,
)
{
// Step 1: unlink the prev and next pointers nodes adjacent to n
ext
.
Self
::
unlink
(
n
ext
,
token
);
// Step 1: unlink the prev and next pointers nodes adjacent to n
ode2
.
Self
::
unlink
(
n
ode2
,
token
);
// Step 2: link node.next pointer and node.next.prev pointer to n
ext
.
let
old_node_next
=
node
.borrow
(
token
)
.next
;
if
let
Some
(
node_next
)
=
old_
node_next
{
node_next
.borrow_mut
(
token
)
.prev
=
Some
(
n
ext
);
// Step 2: link node
1
.next pointer and node
1
.next.prev pointer to n
ode2
.
let
node1_old_next
:
Option
<
NodeRef
<
_
>>
=
node
1
.borrow
(
token
)
.next
;
if
let
Some
(
node
1_old
_next
)
=
node
1_old
_next
{
node
1_old
_next
.borrow_mut
(
token
)
.prev
=
Some
(
n
ode2
);
}
node
.borrow_mut
(
token
)
.next
=
Some
(
n
ext
);
node
1
.borrow_mut
(
token
)
.next
=
Some
(
n
ode2
);
// Step 3: link next to node and old_node_next (old node.next).
let
n
ext
=
next
.borrow_mut
(
token
);
n
ext
.prev
=
Some
(
node
);
n
ext
.next
=
old_
node_next
;
let
n
ode2
:
&
mut
Node
<
_
>
=
node2
.borrow_mut
(
token
);
n
ode2
.prev
=
Some
(
node
1
);
n
ode2
.next
=
node
1_old
_next
;
}
/// Remove the links of 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
);
...
...
@@ -99,6 +102,7 @@ impl<'arena, 'id, T> Node<'arena, 'id, T> {
}
}
/// Immutable interior iteration
pub
fn
iterate
(
node
:
NodeRef
<
'arena
,
'id
,
T
>
,
token
:
&
GhostToken
<
'id
>
,
...
...
@@ -106,7 +110,7 @@ impl<'arena, 'id, T> Node<'arena, 'id, T> {
)
{
let
mut
cur
:
Option
<
NodeRef
<
'arena
,
'id
,
T
>>
=
Some
(
node
);
while
let
Some
(
node
)
=
cur
{
let
node
=
node
.borrow
(
token
);
// immutably borrow `node` with `token`
let
node
:
&
Node
<
_
>
=
node
.borrow
(
token
);
// immutably borrow `node` with `token`
f
(
&
node
.data
);
cur
=
node
.next
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment