impl Display for Queue, impl Debug for Node
This commit is contained in:
parent
e439e1cb73
commit
df1913d8f3
|
@ -130,7 +130,7 @@ impl SegmentedAStar {
|
||||||
let rating = cand.rating();
|
let rating = cand.rating();
|
||||||
if self.best().map_or(true, |n| rating < n.rating()) {
|
if self.best().map_or(true, |n| rating < n.rating()) {
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
"update suggestion ({}): {rating}",
|
"update suggestion ({}): {cand:?}",
|
||||||
self.best.map_or("1st", |_| "new")
|
self.best.map_or("1st", |_| "new")
|
||||||
);
|
);
|
||||||
self.best = Some(cand.into());
|
self.best = Some(cand.into());
|
||||||
|
|
|
@ -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,
|
/// 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.
|
/// contains the placement made in order to arrive at the child from the parent.
|
||||||
struct Edge {
|
struct Edge {
|
||||||
|
|
|
@ -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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in New Issue