impl Display for Queue, impl Debug for Node

This commit is contained in:
tali 2023-04-15 17:10:40 -04:00
parent e439e1cb73
commit df1913d8f3
3 changed files with 24 additions and 1 deletions

View File

@ -130,7 +130,7 @@ impl SegmentedAStar {
let rating = cand.rating();
if self.best().map_or(true, |n| rating < n.rating()) {
tracing::debug!(
"update suggestion ({}): {rating}",
"update suggestion ({}): {cand:?}",
self.best.map_or("1st", |_| "new")
);
self.best = Some(cand.into());

View File

@ -148,6 +148,19 @@ impl Node {
}
}
impl core::fmt::Debug for Node {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Node(rating={}", self.rating)?;
if let Some(pc) = self.root_placement() {
write!(f, ", root_placement={}", pc.ty)?;
}
if !self.queue().is_empty() {
write!(f, ", queue={}", self.queue())?;
}
write!(f, ")")
}
}
/// Represents an edge in the graph, pointing from a node to its parent. Particularly,
/// contains the placement made in order to arrive at the child from the parent.
struct Edge {

View File

@ -64,6 +64,16 @@ impl<'a, T: Copy + Eq> Queue<'a, T> {
}
}
impl<T: Copy + core::fmt::Display> core::fmt::Display for Queue<'_, T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self.hold {
Some(t) => write!(f, "[{t}]"),
None => write!(f, "[]"),
}?;
self.next.iter().try_for_each(|t| write!(f, "{t}"))
}
}
#[cfg(test)]
mod test {
use super::*;