This commit is contained in:
Savanni D'Gerinel 2024-04-30 22:05:15 -04:00
parent d5faf6e7a2
commit e053792061
1 changed files with 12 additions and 9 deletions

View File

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