use relate_core::NodeId;
use crate::exec::test_support::Builder;
use crate::graph::Graph;
use super::take_shortest_expands;
pub(crate) fn counting_expands<T>(f: impl FnOnce() -> T) -> (T, u64) {
let _ = take_shortest_expands();
let out = f();
(out, take_shortest_expands())
}
pub(crate) trait TernaryTree {
fn fan_in_tree(&self, root: NodeId, levels: usize);
fn fan_out_tree(&self, root: NodeId, levels: usize);
}
impl TernaryTree for Builder {
fn fan_in_tree(&self, root: NodeId, levels: usize) {
ternary_tree(self, root, levels, |b, parent, child| b.edge(child, parent));
}
fn fan_out_tree(&self, root: NodeId, levels: usize) {
ternary_tree(self, root, levels, |b, parent, child| b.edge(parent, child));
}
}
fn ternary_tree(b: &Builder, root: NodeId, levels: usize, edge: impl Fn(&Builder, NodeId, NodeId)) {
let mut level = vec![root];
for _ in 0..levels {
let mut next = Vec::new();
for &parent in &level {
for _ in 0..3 {
let child = b.anon(&[]);
edge(b, parent, child);
next.push(child);
}
}
level = next;
}
}
pub(crate) fn min_hops_counterexample() -> Graph {
let b = Builder::new();
let (s, t) = (b.node("s", &["N"]), b.node("t", &["N"]));
for _ in 0..50 {
b.edge(s, b.node("", &[]));
}
let (p, x, y) = (b.node("p", &[]), b.node("x", &[]), b.node("y", &[]));
b.chain(&[s, p, x, t]);
b.chain(&[x, y, t]);
let q: Vec<_> = (0..4).map(|_| b.node("q", &[])).collect();
b.chain(&[&[s], &q[..], &[t]].concat());
b.fan_in_tree(t, 4);
b.done()
}