turn count_targets_help into a loop

This commit is contained in:
Folkert 2021-01-12 22:16:33 +01:00
parent c4e5af554b
commit 30023ac86b

View file

@ -1631,8 +1631,12 @@ fn count_targets(decision_tree: &Decider<u64>) -> MutMap<u64, u64> {
result result
} }
fn count_targets_help(decision_tree: &Decider<u64>, targets: &mut MutMap<u64, u64>) { fn count_targets_help(initial: &Decider<u64>, targets: &mut MutMap<u64, u64>) {
use Decider::*; use Decider::*;
let mut stack = vec![initial];
while let Some(decision_tree) = stack.pop() {
match decision_tree { match decision_tree {
Leaf(target) => match targets.get_mut(target) { Leaf(target) => match targets.get_mut(target) {
None => { None => {
@ -1646,17 +1650,18 @@ fn count_targets_help(decision_tree: &Decider<u64>, targets: &mut MutMap<u64, u6
Chain { Chain {
success, failure, .. success, failure, ..
} => { } => {
count_targets_help(success, targets); stack.push(success);
count_targets_help(failure, targets); stack.push(failure);
} }
FanOut { FanOut {
tests, fallback, .. tests, fallback, ..
} => { } => {
count_targets_help(fallback, targets); stack.push(fallback);
for (_, decider) in tests { for (_, decider) in tests {
count_targets_help(decider, targets); stack.push(decider);
}
} }
} }
} }