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

fix paper example to use arena

parent 3e17f3c8
Pipeline #42500 passed with stage
in 22 minutes and 38 seconds
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: &NodePtr<'id, T>, token: &GhostToken<'id>) {
fn print_list<'arena, 'id, T: fmt::Debug>(tag: char, list: NodeRef<'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)),
......
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