Switch to a standardized tree library in the game tree and depth tree #236

Merged
savanni merged 11 commits from savanni/improved-tree-structure into main 2024-05-01 02:26:47 +00:00
1 changed files with 12 additions and 9 deletions
Showing only changes of commit 278ec27b4e - Show all commits

View File

@ -4,7 +4,7 @@ use config_derive::ConfigOption;
use serde::{Deserialize, Serialize};
use sgf::GameTree;
use std::{
cell::RefCell, collections::{HashMap, VecDeque}, fmt, ops::Deref, path::PathBuf, time::Duration
collections::{HashMap, VecDeque}, fmt, ops::Deref, path::PathBuf, time::Duration
};
use thiserror::Error;
@ -254,9 +254,15 @@ impl Deref for DepthTree {
#[derive(Debug)]
pub struct SizeNode {
node_id: nary_tree::NodeId,
parent: Option<nary_tree::NodeId>,
/// Use this to map back to the node in the original game tree. This way we know how to
/// correspond from a node in the review tree back to there.
#[allow(dead_code)]
game_node_id: nary_tree::NodeId,
/// How deep into the tree is this node?
depth: usize,
/// How far from the leftmost margin is this node?
width: usize,
}
@ -398,7 +404,7 @@ impl DepthTree {
pub fn bfs_iter(&self) -> BFSIter<'_, SizeNode> {
let mut queue = VecDeque::new();
queue.push_back(self.0.root().unwrap());
BFSIter { tree: self, queue }
BFSIter { queue }
}
}
@ -425,8 +431,7 @@ impl<'a> From<&'a GameTree> for DepthTree {
// this branch.
let dest_root_id = tree.set_root(SizeNode {
node_id: source_root_node.node_id(),
parent: None,
game_node_id: source_root_node.node_id(),
depth: 0,
width: 0,
});
@ -441,8 +446,7 @@ impl<'a> From<&'a GameTree> for DepthTree {
let mut dest_parent = tree.get_mut(*dest_parent_id).unwrap();
let new_depth_node = SizeNode {
node_id: source_node.node_id(),
parent: Some(*dest_parent_id),
game_node_id: source_node.node_id(),
depth: 1 + dest_parent.data().depth,
width: dest_parent.data().width,
};
@ -521,7 +525,6 @@ impl<'a> From<&'a GameNode> for Tree<Uuid> {
*/
pub struct BFSIter<'a, T> {
tree: &'a DepthTree,
queue: VecDeque<nary_tree::NodeRef<'a, T>>,
}