Skip to content
GitLab
Menu
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
c6666053
Commit
c6666053
authored
Feb 26, 2021
by
Hai Dang
Browse files
fix paper example to use arena
parent
3e17f3c8
Pipeline
#42500
passed with stage
in 22 minutes and 38 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ghostcell/examples/dlist_ar
c
_paper.rs
→
ghostcell/examples/dlist_ar
ena
_paper.rs
View file @
c6666053
use
ghostcell
::
dlist_arc
::
*
;
use
ghostcell
::
dlist_arena
::
*
;
use
typed_arena
::
Arena
as
TypedArena
;
use
ghostcell
::
GhostToken
;
use
std
::
sync
::
RwLock
;
use
std
::{
fmt
,
thread
,
time
};
fn
print_list
<
'id
,
T
:
fmt
::
Debug
>
(
tag
:
char
,
list
:
&
Node
Ptr
<
'id
,
T
>
,
token
:
&
GhostToken
<
'id
>
)
{
fn
print_list
<
'arena
,
'id
,
T
:
fmt
::
Debug
>
(
tag
:
char
,
list
:
Node
Ref
<
'arena
,
'id
,
T
>
,
token
:
&
GhostToken
<
'id
>
)
{
for
d
in
Node
::
iter
(
list
,
token
)
{
print!
(
"{}{:?}, "
,
tag
,
d
);
}
}
fn
init_list
<
'id
>
(
token
:
&
mut
GhostToken
<
'id
>
,
list_size
:
u32
)
->
NodePtr
<
'id
,
u32
>
{
let
head
:
NodePtr
<
u32
>
=
Node
::
new
(
0
);
let
mut
tail
=
Some
(
head
.clone
());
fn
init_list
<
'arena
,
'id
>
(
arena
:
&
'arena
TypedArena
<
Node
<
'arena
,
'id
,
u32
>>
,
token
:
&
mut
GhostToken
<
'id
>
,
list_size
:
u32
)
->
NodeRef
<
'arena
,
'id
,
u32
>
{
let
head
:
NodeRef
<
_
>
=
Node
::
new
(
0
,
arena
);
let
mut
tail
=
head
;
// To append to the list, we need a &mut GhostToken
for
i
in
1
..
list_size
{
let
node
=
Node
::
new
(
i
);
Node
::
insert_next
(
tail
.take
()
.unwrap
()
,
&
node
,
token
);
tail
=
Some
(
node
)
;
let
node
=
Node
::
new
(
i
,
arena
);
Node
::
insert_next
(
tail
,
node
,
token
);
tail
=
node
;
}
head
...
...
@@ -26,7 +31,8 @@ fn init_list<'id>(token: &mut GhostToken<'id>, list_size: u32) -> NodePtr<'id, u
fn
main
()
{
GhostToken
::
new
(|
mut
token
|
{
// Allocate a list of size 50.
let
list
=
init_list
(
&
mut
token
,
50
);
let
arena
=
TypedArena
::
with_capacity
(
50
);
let
list
=
init_list
(
&
arena
,
&
mut
token
,
50
);
rayon
::
join
(
||
Node
::
iterate
(
&
list
,
&
token
,
|
n
|
print!
(
"{:?}, "
,
n
)),
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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