This commit is contained in:
Phoebe Szmucer 2024-07-21 18:20:26 +01:00
parent beedbd18e5
commit a20c6341ec
3 changed files with 30 additions and 33 deletions

View file

@ -1,5 +1,3 @@
use std::collections::VecDeque;
use crate::{accumulator, hash::FxHashSet, storage::DatabaseGen, DatabaseKeyIndex, Id}; use crate::{accumulator, hash::FxHashSet, storage::DatabaseGen, DatabaseKeyIndex, Id};
use super::{Configuration, IngredientImpl}; use super::{Configuration, IngredientImpl};
@ -25,10 +23,9 @@ where
let db_key = self.database_key_index(key); let db_key = self.database_key_index(key);
let mut visited: FxHashSet<DatabaseKeyIndex> = std::iter::once(db_key).collect(); let mut visited: FxHashSet<DatabaseKeyIndex> = std::iter::once(db_key).collect();
let mut stack = VecDeque::new(); let mut stack = vec![db_key];
stack.push_front(db_key);
while let Some(k) = stack.pop_front() { while let Some(k) = stack.pop() {
accumulator.produced_by(runtime, k, &mut output); accumulator.produced_by(runtime, k, &mut output);
let origin = db.lookup_ingredient(k.ingredient_index).origin(k.key_index); let origin = db.lookup_ingredient(k.ingredient_index).origin(k.key_index);
@ -37,7 +34,7 @@ where
for input in inputs { for input in inputs {
if let Ok(input) = input.try_into() { if let Ok(input) = input.try_into() {
if visited.insert(input) { if visited.insert(input) {
stack.push_back(input); stack.push(input);
} }
} }
} }

View file

@ -45,12 +45,6 @@ fn accumulate_a_called_twice() {
// Check that we don't see logs from `a` appearing twice in the input. // Check that we don't see logs from `a` appearing twice in the input.
expect![[r#" expect![[r#"
[ [
Log(
"log_a(0 of 2)",
),
Log(
"log_a(1 of 2)",
),
Log( Log(
"log_b(0 of 3)", "log_b(0 of 3)",
), ),
@ -60,6 +54,12 @@ fn accumulate_a_called_twice() {
Log( Log(
"log_b(2 of 3)", "log_b(2 of 3)",
), ),
Log(
"log_a(0 of 2)",
),
Log(
"log_a(1 of 2)",
),
]"#]] ]"#]]
.assert_eq(&format!("{:#?}", logs)); .assert_eq(&format!("{:#?}", logs));
}) })

View file

@ -94,12 +94,6 @@ fn accumulate_once() {
// (execution order). // (execution order).
expect![[r#" expect![[r#"
[ [
Log(
"log_a(0 of 2)",
),
Log(
"log_a(1 of 2)",
),
Log( Log(
"log_b(0 of 3)", "log_b(0 of 3)",
), ),
@ -109,6 +103,12 @@ fn accumulate_once() {
Log( Log(
"log_b(2 of 3)", "log_b(2 of 3)",
), ),
Log(
"log_a(0 of 2)",
),
Log(
"log_a(1 of 2)",
),
]"#]] ]"#]]
.assert_eq(&format!("{:#?}", logs)); .assert_eq(&format!("{:#?}", logs));
} }
@ -122,12 +122,6 @@ fn change_a_from_2_to_0() {
let logs = push_logs::accumulated::<Log>(&db, input); let logs = push_logs::accumulated::<Log>(&db, input);
expect![[r#" expect![[r#"
[ [
Log(
"log_a(0 of 2)",
),
Log(
"log_a(1 of 2)",
),
Log( Log(
"log_b(0 of 3)", "log_b(0 of 3)",
), ),
@ -137,6 +131,12 @@ fn change_a_from_2_to_0() {
Log( Log(
"log_b(2 of 3)", "log_b(2 of 3)",
), ),
Log(
"log_a(0 of 2)",
),
Log(
"log_a(1 of 2)",
),
]"#]] ]"#]]
.assert_eq(&format!("{:#?}", logs)); .assert_eq(&format!("{:#?}", logs));
db.assert_logs(expect![[r#" db.assert_logs(expect![[r#"
@ -177,12 +177,6 @@ fn change_a_from_2_to_1() {
let logs = push_logs::accumulated::<Log>(&db, input); let logs = push_logs::accumulated::<Log>(&db, input);
expect![[r#" expect![[r#"
[ [
Log(
"log_a(0 of 2)",
),
Log(
"log_a(1 of 2)",
),
Log( Log(
"log_b(0 of 3)", "log_b(0 of 3)",
), ),
@ -192,6 +186,12 @@ fn change_a_from_2_to_1() {
Log( Log(
"log_b(2 of 3)", "log_b(2 of 3)",
), ),
Log(
"log_a(0 of 2)",
),
Log(
"log_a(1 of 2)",
),
]"#]] ]"#]]
.assert_eq(&format!("{:#?}", logs)); .assert_eq(&format!("{:#?}", logs));
db.assert_logs(expect![[r#" db.assert_logs(expect![[r#"
@ -206,9 +206,6 @@ fn change_a_from_2_to_1() {
let logs = push_logs::accumulated::<Log>(&db, input); let logs = push_logs::accumulated::<Log>(&db, input);
expect![[r#" expect![[r#"
[ [
Log(
"log_a(0 of 1)",
),
Log( Log(
"log_b(0 of 3)", "log_b(0 of 3)",
), ),
@ -218,6 +215,9 @@ fn change_a_from_2_to_1() {
Log( Log(
"log_b(2 of 3)", "log_b(2 of 3)",
), ),
Log(
"log_a(0 of 1)",
),
]"#]] ]"#]]
.assert_eq(&format!("{:#?}", logs)); .assert_eq(&format!("{:#?}", logs));
db.assert_logs(expect![[r#" db.assert_logs(expect![[r#"