mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-22 21:05:11 +00:00
Use a stack and push to it in reverse order
This commit is contained in:
parent
2d490e245a
commit
c9f22f108a
2 changed files with 11 additions and 12 deletions
|
@ -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};
|
||||||
|
@ -24,19 +22,20 @@ where
|
||||||
self.fetch(db, key);
|
self.fetch(db, key);
|
||||||
|
|
||||||
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> = FxHashSet::default();
|
||||||
let mut queue: VecDeque<DatabaseKeyIndex> = std::iter::once(db_key).collect();
|
let mut stack: Vec<DatabaseKeyIndex> = vec![db_key];
|
||||||
|
|
||||||
while let Some(k) = queue.pop_front() {
|
while let Some(k) = stack.pop() {
|
||||||
|
visited.insert(k);
|
||||||
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);
|
||||||
let inputs = origin.iter().flat_map(|origin| origin.inputs());
|
let inputs = origin.iter().flat_map(|origin| origin.inputs());
|
||||||
|
|
||||||
for input in inputs {
|
for input in inputs.rev() {
|
||||||
if let Ok(input) = input.try_into() {
|
if let Ok(input) = input.try_into() {
|
||||||
if visited.insert(input) {
|
if !visited.contains(&input) {
|
||||||
queue.push_back(input);
|
stack.push(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ pub enum QueryOrigin {
|
||||||
|
|
||||||
impl QueryOrigin {
|
impl QueryOrigin {
|
||||||
/// Indices for queries *read* by this query
|
/// Indices for queries *read* by this query
|
||||||
pub(crate) fn inputs(&self) -> impl Iterator<Item = DependencyIndex> + '_ {
|
pub(crate) fn inputs(&self) -> impl DoubleEndedIterator<Item = DependencyIndex> + '_ {
|
||||||
let opt_edges = match self {
|
let opt_edges = match self {
|
||||||
QueryOrigin::Derived(edges) | QueryOrigin::DerivedUntracked(edges) => Some(edges),
|
QueryOrigin::Derived(edges) | QueryOrigin::DerivedUntracked(edges) => Some(edges),
|
||||||
QueryOrigin::Assigned(_) | QueryOrigin::BaseInput => None,
|
QueryOrigin::Assigned(_) | QueryOrigin::BaseInput => None,
|
||||||
|
@ -86,7 +86,7 @@ impl QueryOrigin {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Indices for queries *written* by this query (if any)
|
/// Indices for queries *written* by this query (if any)
|
||||||
pub(crate) fn outputs(&self) -> impl Iterator<Item = DependencyIndex> + '_ {
|
pub(crate) fn outputs(&self) -> impl DoubleEndedIterator<Item = DependencyIndex> + '_ {
|
||||||
let opt_edges = match self {
|
let opt_edges = match self {
|
||||||
QueryOrigin::Derived(edges) | QueryOrigin::DerivedUntracked(edges) => Some(edges),
|
QueryOrigin::Derived(edges) | QueryOrigin::DerivedUntracked(edges) => Some(edges),
|
||||||
QueryOrigin::Assigned(_) | QueryOrigin::BaseInput => None,
|
QueryOrigin::Assigned(_) | QueryOrigin::BaseInput => None,
|
||||||
|
@ -127,7 +127,7 @@ impl QueryEdges {
|
||||||
/// Returns the (tracked) inputs that were executed in computing this memoized value.
|
/// Returns the (tracked) inputs that were executed in computing this memoized value.
|
||||||
///
|
///
|
||||||
/// These will always be in execution order.
|
/// These will always be in execution order.
|
||||||
pub(crate) fn inputs(&self) -> impl Iterator<Item = DependencyIndex> + '_ {
|
pub(crate) fn inputs(&self) -> impl DoubleEndedIterator<Item = DependencyIndex> + '_ {
|
||||||
self.input_outputs
|
self.input_outputs
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(edge_kind, _)| *edge_kind == EdgeKind::Input)
|
.filter(|(edge_kind, _)| *edge_kind == EdgeKind::Input)
|
||||||
|
@ -137,7 +137,7 @@ impl QueryEdges {
|
||||||
/// Returns the (tracked) outputs that were executed in computing this memoized value.
|
/// Returns the (tracked) outputs that were executed in computing this memoized value.
|
||||||
///
|
///
|
||||||
/// These will always be in execution order.
|
/// These will always be in execution order.
|
||||||
pub(crate) fn outputs(&self) -> impl Iterator<Item = DependencyIndex> + '_ {
|
pub(crate) fn outputs(&self) -> impl DoubleEndedIterator<Item = DependencyIndex> + '_ {
|
||||||
self.input_outputs
|
self.input_outputs
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(edge_kind, _)| *edge_kind == EdgeKind::Output)
|
.filter(|(edge_kind, _)| *edge_kind == EdgeKind::Output)
|
||||||
|
|
Loading…
Reference in a new issue