Skip to content

Commit

Permalink
📦 NEW: Use scc map
Browse files Browse the repository at this point in the history
  • Loading branch information
ianagbip1oti committed Sep 1, 2024
1 parent 43b8ad1 commit e535534
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 161 deletions.
163 changes: 23 additions & 140 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ path = "src/main.rs"
[dependencies]
arc-swap = "=1.6.0"
arrayvec = "=0.7.4"
dashmap = "=5.5.3"
fastapprox = "=0.3.1"
goober = { git = "https://github.com/jw1912/goober/", rev = "32b9b52" }
nohash-hasher = "=0.2.0"
memmap = "=0.7.0"
scc = "=2.1.16"
scoped_threadpool = "=0.1.9"

[features]
Expand Down
2 changes: 1 addition & 1 deletion src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Arena {
}

pub fn allocator(&self) -> Allocator {
let id = IDS.fetch_add(1, Ordering::SeqCst);
let id = IDS.fetch_add(1, Ordering::Relaxed);

Allocator {
id,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

extern crate arc_swap;
extern crate arrayvec;
extern crate dashmap;
extern crate fastapprox;
extern crate memmap;
extern crate nohash_hasher;
extern crate scc;

mod arena;
mod mem;
Expand Down
10 changes: 4 additions & 6 deletions src/search_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl PositionNode {
let hots = unsafe { &*(self.hots.cast_mut()) };

for h in hots {
h.child.store(null_mut(), Ordering::SeqCst);
h.child.store(null_mut(), Ordering::Relaxed);
}
}

Expand Down Expand Up @@ -432,16 +432,14 @@ impl SearchTree {
self.search_options.mcts_options.policy_temperature,
)?;

// Copy any history
self.ttable.lookup_into(state, &mut created_here);

// Copy node to arena memory
let created = tld.allocator.alloc_node()?;

*created = created_here;

if let Some(node) = choice.set_or_get_child(created) {
return Ok(node);
}

// Insert the child into the ttable
let inserted = self.ttable.insert(state, created);
let inserted_ptr = ptr::from_ref(inserted).cast_mut();
choice.child.store(inserted_ptr, Ordering::Relaxed);
Expand Down
Loading

0 comments on commit e535534

Please sign in to comment.