Switch to a standardized tree library in the game tree and depth tree #236
|
@ -2503,6 +2503,16 @@ dependencies = [
|
||||||
"version_check 0.9.4",
|
"version_check 0.9.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nary_tree"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fb86edb8951cb3852cbb33ef558650e9f18c9d2e7fd79a6849c984a3825719c7"
|
||||||
|
dependencies = [
|
||||||
|
"slab",
|
||||||
|
"snowflake",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "native-tls"
|
name = "native-tls"
|
||||||
version = "0.2.11"
|
version = "0.2.11"
|
||||||
|
@ -2705,10 +2715,10 @@ dependencies = [
|
||||||
"config-derive",
|
"config-derive",
|
||||||
"cool_asserts",
|
"cool_asserts",
|
||||||
"grid",
|
"grid",
|
||||||
|
"nary_tree",
|
||||||
"serde 1.0.193",
|
"serde 1.0.193",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sgf",
|
"sgf",
|
||||||
"slab_tree",
|
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"uuid 0.8.2",
|
"uuid 0.8.2",
|
||||||
]
|
]
|
||||||
|
@ -3686,9 +3696,9 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"cool_asserts",
|
"cool_asserts",
|
||||||
|
"nary_tree",
|
||||||
"nom",
|
"nom",
|
||||||
"serde 1.0.193",
|
"serde 1.0.193",
|
||||||
"slab_tree",
|
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"typeshare",
|
"typeshare",
|
||||||
"uuid 0.8.2",
|
"uuid 0.8.2",
|
||||||
|
@ -3762,15 +3772,6 @@ dependencies = [
|
||||||
"autocfg 1.1.0",
|
"autocfg 1.1.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "slab_tree"
|
|
||||||
version = "0.3.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f9e8b45abe77b7cab703054a11973cffe164c82c5ff5e211ae5a73af5e42e39f"
|
|
||||||
dependencies = [
|
|
||||||
"snowflake",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smallvec"
|
name = "smallvec"
|
||||||
version = "1.11.2"
|
version = "1.11.2"
|
||||||
|
|
|
@ -14,7 +14,7 @@ sgf = { path = "../../sgf" }
|
||||||
grid = { version = "0.9" }
|
grid = { version = "0.9" }
|
||||||
serde_json = { version = "1" }
|
serde_json = { version = "1" }
|
||||||
serde = { version = "1", features = [ "derive" ] }
|
serde = { version = "1", features = [ "derive" ] }
|
||||||
slab_tree = { version = "0.3" }
|
nary_tree = { version = "0.4" }
|
||||||
thiserror = { version = "1" }
|
thiserror = { version = "1" }
|
||||||
uuid = { version = "0.8", features = ["v4", "serde"] }
|
uuid = { version = "0.8", features = ["v4", "serde"] }
|
||||||
|
|
||||||
|
|
|
@ -242,10 +242,10 @@ pub struct Tree<T> {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pub struct DepthTree(slab_tree::Tree<SizeNode>);
|
pub struct DepthTree(nary_tree::Tree<SizeNode>);
|
||||||
|
|
||||||
impl Deref for DepthTree {
|
impl Deref for DepthTree {
|
||||||
type Target = slab_tree::Tree<SizeNode>;
|
type Target = nary_tree::Tree<SizeNode>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.0
|
&self.0
|
||||||
|
@ -254,8 +254,8 @@ impl Deref for DepthTree {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SizeNode {
|
pub struct SizeNode {
|
||||||
node_id: slab_tree::NodeId,
|
node_id: nary_tree::NodeId,
|
||||||
parent: Option<slab_tree::NodeId>,
|
parent: Option<nary_tree::NodeId>,
|
||||||
depth: usize,
|
depth: usize,
|
||||||
width: usize,
|
width: usize,
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ impl DepthTree {
|
||||||
// so I want to eliminate the "Tree" above and keep using the slab tree. I think I should be able
|
// so I want to eliminate the "Tree" above and keep using the slab tree. I think I should be able
|
||||||
// to build these Node objects without needing a custom data structure.
|
// to build these Node objects without needing a custom data structure.
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self(slab_tree::Tree::new())
|
Self(nary_tree::Tree::new())
|
||||||
/*
|
/*
|
||||||
Tree {
|
Tree {
|
||||||
nodes: vec![Node {
|
nodes: vec![Node {
|
||||||
|
@ -415,8 +415,8 @@ impl<'a> From<&'a GameTree> for DepthTree {
|
||||||
// The id_map indexes from the source tree to the destination tree. Reverse
|
// The id_map indexes from the source tree to the destination tree. Reverse
|
||||||
// indexing is accomplished by looking at the node_id in a node in the destination
|
// indexing is accomplished by looking at the node_id in a node in the destination
|
||||||
// tree.
|
// tree.
|
||||||
let mut id_map: HashMap<slab_tree::NodeId, slab_tree::NodeId> = HashMap::new();
|
let mut id_map: HashMap<nary_tree::NodeId, nary_tree::NodeId> = HashMap::new();
|
||||||
let mut tree = slab_tree::Tree::new();
|
let mut tree = nary_tree::Tree::new();
|
||||||
|
|
||||||
let mut iter = source_root_node.traverse_pre_order();
|
let mut iter = source_root_node.traverse_pre_order();
|
||||||
let _ = iter.next().unwrap(); // we already know that the first element to be
|
let _ = iter.next().unwrap(); // we already know that the first element to be
|
||||||
|
@ -522,7 +522,7 @@ impl<'a> From<&'a GameNode> for Tree<Uuid> {
|
||||||
|
|
||||||
pub struct BFSIter<'a, T> {
|
pub struct BFSIter<'a, T> {
|
||||||
tree: &'a DepthTree,
|
tree: &'a DepthTree,
|
||||||
queue: VecDeque<slab_tree::NodeRef<'a, T>>,
|
queue: VecDeque<nary_tree::NodeRef<'a, T>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T> Iterator for BFSIter<'a, T> {
|
impl<'a, T> Iterator for BFSIter<'a, T> {
|
||||||
|
|
|
@ -9,7 +9,7 @@ edition = "2021"
|
||||||
chrono = { version = "0.4", features = [ "serde" ] }
|
chrono = { version = "0.4", features = [ "serde" ] }
|
||||||
nom = { version = "7" }
|
nom = { version = "7" }
|
||||||
serde = { version = "1", features = [ "derive" ] }
|
serde = { version = "1", features = [ "derive" ] }
|
||||||
slab_tree = { version = "0.3" }
|
nary_tree = { version = "0.4" }
|
||||||
thiserror = { version = "1"}
|
thiserror = { version = "1"}
|
||||||
typeshare = { version = "1" }
|
typeshare = { version = "1" }
|
||||||
uuid = { version = "0.8", features = ["v4", "serde"] }
|
uuid = { version = "0.8", features = ["v4", "serde"] }
|
||||||
|
|
|
@ -3,9 +3,10 @@ use crate::{
|
||||||
Color, Date, GameResult, GameType,
|
Color, Date, GameResult, GameType,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use slab_tree::{NodeId, NodeMut, NodeRef, Tree};
|
use nary_tree::{NodeId, NodeMut, NodeRef, Tree};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet, VecDeque},
|
collections::{HashMap, HashSet, VecDeque},
|
||||||
|
fmt,
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
|
@ -425,6 +426,15 @@ pub enum GameNode {
|
||||||
SetupNode(SetupNode),
|
SetupNode(SetupNode),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for GameNode {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||||
|
match self {
|
||||||
|
GameNode::MoveNode(_) => write!(f, "MoveNode"),
|
||||||
|
GameNode::SetupNode(_) => write!(f, "SetupNode"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl GameNode {
|
impl GameNode {
|
||||||
pub fn id(&self) -> Uuid {
|
pub fn id(&self) -> Uuid {
|
||||||
match self {
|
match self {
|
||||||
|
|
Loading…
Reference in New Issue