Debian Codegraph @

crates/graph/src/bfs.rs

raw symbols SCIP
1 //! Breadth-first ancestry search.
2 //!
3 //! Ported from the `_BreadthFirstSearcher` class in `vcsgraph/graph.py`.
4 //! The searcher walks the ancestry of a set of revisions, optionally with
5 //! ghosts split out, and supports mid-walk modifications via
6 //! [`BfsState::start_searching`] and [`BfsState::stop_searching_any`].
7 //!
8 //! The state is decoupled from the parents provider: each advance method
9 //! takes a `&impl ParentsProvider<K>` explicitly. This lets Python bindings
10 //! keep the provider adapter and the state as sibling fields in the same
11 //! pyclass without running into self-reference problems.
12
13 use craterust-analyzer cargo vcs-graph 3.6.0 crate/::{ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#, Parentsrust-analyzer cargo vcs-graph 3.6.0 Parents#, ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#};
14 use rustc_hashrust-analyzer cargo rustc-hash 2.1.2 crate/::{FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#, FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#};
15 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#;
16 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#;
17
18 /// Which kind of result the searcher returned on its most recent call.
19 ///
20 /// Callers can interleave `next` and `next_with_ghosts` calls; the searcher
21 /// transparently advances the underlying state when the mode flips.
22 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
23 enum ReturnModerust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode# {
24 /// Most recent return was a plain `next()` — revisions yielded before
25 /// their parents were queried, so ghosts are mixed in with real nodes.
26 Nextrust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#Next#,
27 /// Most recent return was `next_with_ghosts()` — revisions yielded after
28 /// their parents were queried, so ghosts are split out.
29 NextWithGhostsrust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#NextWithGhosts#,
30 }
31
32 /// Outcome of a `_do_query` step.
33 struct QueryResultrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#<K> {
34 /// Nodes present in the provider's response.
35 foundrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#found.: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>,
36 /// Nodes not found (ghosts).
37 ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#ghosts.: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>,
38 /// Parents of the found nodes that we haven't seen before.
39 nextrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#next.: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>,
40 /// The full parent map returned by the provider for the queried keys.
41 parentsrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#parents.: FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#<K, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K>>,
42 }
43
44 /// Mutable state of a breadth-first ancestry search.
45 ///
46 /// Constructed via [`BfsState::new`]; advanced with [`next`](Self::next) or
47 /// [`next_with_ghosts`](Self::next_with_ghosts), which both take a reference
48 /// to a parents provider. Mid-walk mutations go through
49 /// [`start_searching`](Self::start_searching) and
50 /// [`stop_searching_any`](Self::stop_searching_any).
51 pub struct BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#<K: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> {
52 /// All revisions the searcher has ever visited (seen or about to visit).
53 pub seenrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#seen.: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>,
54 /// Revisions the caller originally asked to search from, plus any added
55 /// via `start_searching`.
56 pub started_keysrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#started_keys.: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>,
57 /// Revisions the caller explicitly asked to not descend through, plus
58 /// any ghosts encountered. Ghosts are implicit stop points so the search
59 /// can be repeated after ghosts are filled in.
60 pub stopped_keysrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#stopped_keys.: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>,
61
62 next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#next_query.: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>,
63 current_presentrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_present.: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>,
64 current_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_ghosts.: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>,
65 current_parentsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_parents.: FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#<K, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K>>,
66 returningrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#returning.: ReturnModerust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#,
67 iterationsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#iterations.: usize,
68 }
69
70 impl<K: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#<K> {
71 /// Start a new search from `revisions`.
72 pub fn newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().<I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = K>>(revisions: I) -> Selfrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`] {
73 let next_query: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = revisions.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
74 let started_keys: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = next_query.iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
75 BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState# {
76 seenrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#seen.: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][Default]default().(),
77 started_keysrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#started_keys.,
78 stopped_keysrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#stopped_keys.: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][Default]default().(),
79 next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#next_query.,
80 current_presentrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_present.: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][Default]default().(),
81 current_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_ghosts.: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][Default]default().(),
82 current_parentsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_parents.: FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S>`][Default]default().(),
83 returningrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#returning.: ReturnModerust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#::NextWithGhostsrust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#NextWithGhosts#,
84 iterationsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#iterations.: 0,
85 }
86 }
87
88 /// Return the number of iterations performed so far.
89 pub fn iterationsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]iterations().(&self) -> usize {
90 self.iterationsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#iterations.
91 }
92
93 /// Borrow the current frontier (next query set).
94 ///
95 /// Exposed so bindings can reflect Python's `_next_query` attribute,
96 /// which existing callers in `graph.py` read (but do not mutate).
97 pub fn next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_query().(&self) -> &FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> {
98 &self.next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#next_query.
99 }
100
101 /// Borrow the present revisions from the most recent advance.
102 ///
103 /// Exposed so bindings can reflect Python's `_current_present`
104 /// attribute. Empty until the first advance.
105 pub fn current_presentrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]current_present().(&self) -> &FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> {
106 &self.current_presentrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_present.
107 }
108
109 /// Borrow the ghost revisions from the most recent advance.
110 ///
111 /// Exposed so bindings can reflect Python's `_current_ghosts`
112 /// attribute. Empty until the first advance.
113 pub fn current_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]current_ghosts().(&self) -> &FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> {
114 &self.current_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_ghosts.
115 }
116
117 /// Borrow the parent map of present revisions from the most recent
118 /// advance.
119 ///
120 /// Exposed so bindings can reflect Python's `_current_parents`
121 /// attribute. Empty until the first advance.
122 pub fn current_parentsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]current_parents().(&self) -> &FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#<K, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K>> {
123 &self.current_parentsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_parents.
124 }
125
126 /// Snapshot of `(started_keys, excludes, included_keys)` describing what
127 /// the searcher has reached. Matches Python's `get_state` return shape.
128 ///
129 /// This method intentionally calls the provider if the searcher is in
130 /// `Next` mode, since we need the current query's children in order to
131 /// list their parents as excludes. The subsequent iteration advances
132 /// normally; the preview read is backed out of `seen`.
133 pub fn get_staterust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]get_state().<P: ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K>>(
134 &mut self,
135 provider: &P,
136 ) -> (FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>, FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>, FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>) {
137 let next_query = if self.returningrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#returning. rust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[ReturnMode][`PartialEq<Self>`]eq().==rust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[ReturnMode][`PartialEq<Self>`]eq(). rust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[ReturnMode][`PartialEq<Self>`]eq().ReturnModerust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#::Nextrust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#Next# {
138 let result = Selfrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]::do_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]do_query().(&mut self.seenrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#seen., &self.next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#next_query., provider);
139 // Undo the `seen` updates the preview made.
140 for k in &result.nextrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#next. {
141 self.seenrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#seen..removerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]remove().(k);
142 }
143 let mut nq = result.nextrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#next.;
144 nq.extendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`Extend<T>`]extend().(result.ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#ghosts.);
145 nq
146 } else {
147 self.next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#next_query..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][Clone]clone().()
148 };
149 let mut excludes = self.stopped_keysrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#stopped_keys..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][Clone]clone().();
150 excludes.extendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`Extend<T>`]extend().(next_query);
151 let included: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = self.seenrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#seen..differencerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]difference().(&excludes).clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
152 (self.started_keysrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#started_keys..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][Clone]clone().(), excludes, included)
153 }
154
155 /// Advance the searcher and return the set yielded by Python's
156 /// `__next__` / `next`.
157 ///
158 /// Each call yields the current query before its parents are queried,
159 /// so ghosts are mixed in with present revisions.
160 ///
161 /// Returns `None` when there is nothing left to search.
162 pub fn next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().<P: ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K>>(&mut self, provider: &P) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>> {
163 if self.returningrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#returning. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().ReturnModerust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#::Nextrust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#Next# {
164 self.returningrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#returning. = ReturnModerust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#::Nextrust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#Next#;
165 self.iterationsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#iterations. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
166 } else {
167 self.advancerust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]advance().(provider);
168 }
169 if self.next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#next_query..is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]is_empty().() {
170 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
171 }
172 self.seenrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#seen..extendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`Extend<T>`]extend().(self.next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#next_query..iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
173 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#next_query..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][Clone]clone().())
174 }
175
176 /// Advance the searcher and return `(present, ghosts)` the way Python's
177 /// `next_with_ghosts` does.
178 ///
179 /// Returns `None` when there is nothing left to search.
180 pub fn next_with_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_with_ghosts().<P: ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K>>(
181 &mut self,
182 provider: &P,
183 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>, FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>)> {
184 if self.returningrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#returning. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().ReturnModerust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#::NextWithGhostsrust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#NextWithGhosts# {
185 self.returningrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#returning. = ReturnModerust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#::NextWithGhostsrust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#NextWithGhosts#;
186 self.advancerust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]advance().(provider);
187 }
188 if self.next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#next_query..is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]is_empty().() {
189 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
190 }
191 self.advancerust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]advance().(provider);
192 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((self.current_presentrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_present..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][Clone]clone().(), self.current_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_ghosts..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][Clone]clone().()))
193 }
194
195 fn advancerust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]advance().<P: ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K>>(&mut self, provider: &P) {
196 self.iterationsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#iterations. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
197 // Split borrow: `do_query` only needs to read `next_query` and
198 // write `seen`, so we pass them as separate references and avoid
199 // cloning `next_query` on every advance.
200 let result = Selfrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]::do_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]do_query().(&mut self.seenrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#seen., &self.next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#next_query., provider);
201 self.current_presentrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_present. = result.foundrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#found.;
202 self.current_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_ghosts. = result.ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#ghosts.;
203 self.next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#next_query. = result.nextrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#next.;
204 self.current_parentsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_parents. = result.parentsrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#parents.;
205 // Ghosts become implicit stop points.
206 self.stopped_keysrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#stopped_keys.
207 .extendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`Extend<T>`]extend().(self.current_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_ghosts..iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
208 }
209
210 fn do_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]do_query().<P: ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K>>(
211 seen: &mut FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>,
212 revisions: &FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>,
213 provider: &P,
214 ) -> QueryResultrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#<K> {
215 seen.extendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`Extend<T>`]extend().(revisions.iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
216
217 // ParentsProvider takes a std HashSet by reference.
218 let mut std_set: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<K> = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::with_capacityrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`]with_capacity().(revisions.lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]len().());
219 for k in revisions {
220 std_set.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(k.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().());
221 }
222 let parent_map: ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#<K> = provider.get_parent_maprust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#get_parent_map().(&std_set);
223
224 let mut found: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][Default]default().();
225 let mut parents_of_found: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][Default]default().();
226 let mut parents_owned: FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#<K, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K>> = FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S>`][Default]default().();
227 for (rev_id, parents) in parent_map.iterrust-analyzer cargo vcs-graph 3.6.0 impl#[`ParentMap<K>`]iter().() {
228 found.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(rev_id.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().());
229 match parents {
230 Parentsrust-analyzer cargo vcs-graph 3.6.0 Parents#::Knownrust-analyzer cargo vcs-graph 3.6.0 Parents#Known#(ps) => {
231 parents_owned.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(rev_id.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), ps.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().());
232 for p in ps {
233 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().seen.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(p) {
234 parents_of_found.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(p.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().());
235 }
236 }
237 }
238 // Python treats None parents as "continue" — no new parents
239 // contributed.
240 Parentsrust-analyzer cargo vcs-graph 3.6.0 Parents#::Ghostrust-analyzer cargo vcs-graph 3.6.0 Parents#Ghost# => {}
241 }
242 }
243 let ghosts: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = revisions.differencerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]difference().(&found).clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
244 QueryResultrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult# {
245 foundrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#found.,
246 ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#ghosts.,
247 nextrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#next.: parents_of_found,
248 parentsrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#parents.: parents_owned,
249 }
250 }
251
252 /// Find already-seen ancestors of `revisions`.
253 ///
254 /// This walks backwards from `revisions` through `seen` keys only,
255 /// querying the provider for parents. It matches the Python behavior:
256 /// nodes not yet searched (in `next_query` when we're in `Next` mode)
257 /// are skipped so we don't probe ahead of the search frontier.
258 pub fn find_seen_ancestorsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]find_seen_ancestors().<I, P>(&self, revisions: I, provider: &P) -> FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>
259 where
260 I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = K>,
261 P: ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K>,
262 {
263 let mut pending: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = revisions
264 .into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().()
265 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|r| self.seenrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#seen..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(r))
266 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
267 let mut seen_ancestors: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = pending.iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
268
269 // In `Next` mode `seen` contains nodes that have been *returned* but
270 // whose parents haven't been queried yet. Skip those so we don't
271 // probe ahead of the search frontier.
272 let empty: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][Default]default().();
273 let not_searched_yet: &FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = if self.returningrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#returning. rust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[ReturnMode][`PartialEq<Self>`]eq().==rust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[ReturnMode][`PartialEq<Self>`]eq(). rust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[ReturnMode][`PartialEq<Self>`]eq().ReturnModerust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#::Nextrust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#Next# {
274 &self.next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#next_query.
275 } else {
276 &empty
277 };
278
279 pending.retainrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]retain().(|k| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().not_searched_yet.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(k));
280
281 while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pending.is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]is_empty().() {
282 let mut std_set: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<K> = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::with_capacityrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`]with_capacity().(pending.lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]len().());
283 for k in &pending {
284 std_set.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(k.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().());
285 }
286 let parent_map = provider.get_parent_maprust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#get_parent_map().(&std_set);
287 let mut all_parents: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
288 for (_, parents) in parent_map.iterrust-analyzer cargo vcs-graph 3.6.0 impl#[`ParentMap<K>`]iter().() {
289 if let Parentsrust-analyzer cargo vcs-graph 3.6.0 Parents#::Knownrust-analyzer cargo vcs-graph 3.6.0 Parents#Known#(ps) = parents {
290 all_parents.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(ps.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
291 }
292 }
293 let mut next_pending: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][Default]default().();
294 for p in all_parents {
295 if self.seenrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#seen..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&p) && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().seen_ancestors.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&p) {
296 next_pending.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(p);
297 }
298 }
299 seen_ancestors.extendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`Extend<T>`]extend().(next_pending.iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
300 next_pending.retainrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]retain().(|k| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().not_searched_yet.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(k));
301 pending = next_pending;
302 }
303 seen_ancestors
304 }
305
306 /// Stop searching any of `revisions`. Returns the set of revisions
307 /// actually removed from the current search frontier (not the ones that
308 /// had already passed).
309 pub fn stop_searching_anyrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]stop_searching_any().<I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = K>>(&mut self, revisions: I) -> FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> {
310 let revisions: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = revisions.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
311 let stopped: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = if self.returningrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#returning. rust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[ReturnMode][`PartialEq<Self>`]eq().==rust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[ReturnMode][`PartialEq<Self>`]eq(). rust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[ReturnMode][`PartialEq<Self>`]eq().ReturnModerust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#::Nextrust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#Next# {
312 let stopped: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = self.next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#next_query..intersectionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]intersection().(&revisions).clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
313 self.next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#next_query..retainrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]retain().(|k| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().revisions.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(k));
314 stopped
315 } else {
316 let stopped_present: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = self
317 .current_presentrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_present.
318 .intersectionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]intersection().(&revisions)
319 .clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().()
320 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
321 let stopped_ghosts: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = self
322 .current_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_ghosts.
323 .intersectionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]intersection().(&revisions)
324 .clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().()
325 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
326 let stopped: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = stopped_present.unionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]union().(&stopped_ghosts).clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
327 self.current_presentrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_present..retainrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]retain().(|k| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().revisions.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(k));
328 self.current_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_ghosts..retainrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]retain().(|k| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().revisions.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(k));
329
330 // Stopping X should stop returning parents of X — but only if no
331 // other current node still references the same parent. Count
332 // references to each parent from stopped_present, then decrement
333 // for each non-stopped reference.
334 let mut stop_rev_references: FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#<K, i64> = FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S>`][Default]default().();
335 for rev in &stopped_present {
336 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parents) = self.current_parentsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_parents..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(rev) {
337 for parent_id in parents {
338 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().stop_rev_references.entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]entry().(parent_id.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()).or_insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`Entry<'a, K, V, A>`]or_insert().(0) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().1;
339 }
340 }
341 }
342 for parents in self.current_parentsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_parents..valuesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]values().() {
343 for parent_id in parents {
344 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(count) = stop_rev_references.get_mutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get_mut().(parent_id) {
345 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`SubAssign<Self>`]sub_assign().1;
346 }
347 }
348 }
349 let stop_parents: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = stop_rev_references
350 .into_iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][IntoIterator]into_iter().()
351 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|(k, refs)| if refs rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq().0 { Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(k) } else { Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# })
352 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
353 self.next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#next_query..retainrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]retain().(|k| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().stop_parents.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(k));
354 stopped
355 };
356 self.stopped_keysrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#stopped_keys..extendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`Extend<T>`]extend().(stopped.iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
357 self.stopped_keysrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#stopped_keys..extendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`Extend<T>`]extend().(revisions);
358 stopped
359 }
360
361 /// Add more revisions to the search.
362 ///
363 /// In `NextWithGhosts` mode this performs an immediate query on the new
364 /// revisions and returns `Some((present, ghosts))`. In `Next` mode the
365 /// new revisions join the current query without a provider call and the
366 /// function returns `None`.
367 pub fn start_searchingrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]start_searching().<I, P>(
368 &mut self,
369 revisions: I,
370 provider: &P,
371 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>, FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>)>
372 where
373 I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = K>,
374 P: ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K>,
375 {
376 let revisions: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = revisions.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
377 self.started_keysrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#started_keys..extendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`Extend<T>`]extend().(revisions.iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
378 let new_revisions: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = revisions.differencerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]difference().(&self.seenrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#seen.).clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
379 if self.returningrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#returning. rust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[ReturnMode][`PartialEq<Self>`]eq().==rust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[ReturnMode][`PartialEq<Self>`]eq(). rust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[ReturnMode][`PartialEq<Self>`]eq().ReturnModerust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#::Nextrust-analyzer cargo vcs-graph 3.6.0 bfs/ReturnMode#Next# {
380 self.next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#next_query..extendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`Extend<T>`]extend().(new_revisions.iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
381 self.seenrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#seen..extendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`Extend<T>`]extend().(new_revisions);
382 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
383 } else {
384 let result = Selfrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]::do_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]do_query().(&mut self.seenrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#seen., &revisions, provider);
385 self.stopped_keysrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#stopped_keys..extendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`Extend<T>`]extend().(result.ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#ghosts..iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
386 self.current_presentrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_present..extendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`Extend<T>`]extend().(result.foundrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#found..iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
387 self.current_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_ghosts..extendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`Extend<T>`]extend().(result.ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#ghosts..iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
388 self.next_queryrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#next_query..extendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`Extend<T>`]extend().(result.nextrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#next.);
389 for (k, v) in result.parentsrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#parents. {
390 self.current_parentsrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#current_parents..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(k, v);
391 }
392 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((result.foundrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#found., result.ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/QueryResult#ghosts.))
393 }
394 }
395 }
396
397 #[cfg(test)]
398 mod testsrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/ {
399 use superrust-analyzer cargo vcs-graph 3.6.0 bfs/::*;
400 use craterust-analyzer cargo vcs-graph 3.6.0 crate/::DictParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/DictParentsProvider#;
401 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#;
402
403 fn providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(edges: &[(&'static str, &[&'static str])]) -> DictParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/DictParentsProvider#<&'static str> {
404 let map: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<&'static str, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&'static str>> =
405 edges.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(k, ps)| (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().k, ps.to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().())).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
406 DictParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/DictParentsProvider#::fromrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`DictParentsProvider<K>`][`From<HashMap<K, Vec<K>>>`]from().(map)
407 }
408
409 fn as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().<const N: usize>(xs: [&'static str; N]) -> FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<&'static str> {
410 xs.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`[T; N]`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
411 }
412
413 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
414 fn next_walks_linearrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/next_walks_linear().() {
415 // a <- b <- c
416 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[("a", &[]), ("b", &["a"]), ("c", &["b"])]);
417 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["c"]);
418 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["c"])));
419 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["b"])));
420 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["a"])));
421 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
422 }
423
424 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
425 fn next_with_ghosts_splitsrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/next_with_ghosts_splits().() {
426 // head -> present -> (child, ghost); child has no parents; ghost missing
427 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[
428 ("head", &["present"]),
429 ("present", &["child", "ghost"]),
430 ("child", &[]),
431 ]);
432 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["head"]);
433 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_with_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_with_ghosts().(&p), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["head"]), as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().([]))));
434 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
435 s.next_with_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_with_ghosts().(&p),
436 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["present"]), as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().([])))
437 );
438 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
439 s.next_with_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_with_ghosts().(&p),
440 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["child"]), as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["ghost"])))
441 );
442 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_with_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_with_ghosts().(&p), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
443 }
444
445 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
446 fn next_mode_mixes_ghosts_in_with_presentrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/next_mode_mixes_ghosts_in_with_present().() {
447 // Same graph as above, but via next() — ghost should appear alongside child.
448 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[
449 ("head", &["present"]),
450 ("present", &["child", "ghost"]),
451 ("child", &[]),
452 ]);
453 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["head"]);
454 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["head"])));
455 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["present"])));
456 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["child", "ghost"])));
457 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
458 }
459
460 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
461 fn stop_searching_any_next_moderust-analyzer cargo vcs-graph 3.6.0 bfs/tests/stop_searching_any_next_mode().() {
462 // In Next mode, `next_query` holds the set just returned by `next()`
463 // (since the caller is given the query, not the results). So stopping
464 // the set that was just yielded removes it from the frontier.
465 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[
466 ("head", &["present"]),
467 ("present", &["stopped"]),
468 ("stopped", &[]),
469 ]);
470 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["head"]);
471 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["head"])));
472 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["present"])));
473 let stopped = s.stop_searching_anyrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]stop_searching_any().(["present"]);
474 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stopped, as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["present"]));
475 // With `present` stopped before its parents are queried, the search
476 // is now exhausted.
477 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
478 }
479
480 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
481 fn start_searching_next_with_ghosts_queries_immediatelyrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/start_searching_next_with_ghosts_queries_immediately().() {
482 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[("new_root", &["its_parent"]), ("its_parent", &[])]);
483 let mut s: BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#<&'static str> = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().([] as [&'static str; 0]);
484 let (found, ghosts) = s.start_searchingrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]start_searching().(["new_root", "ghost"], &p).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
485 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(found.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&"new_root"));
486 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ghosts.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&"ghost"));
487 }
488
489 /// Translated from `test_breadth_first_search_start_ghosts` in
490 /// `vcsgraph/tests/test_graph.py`: starting with only a ghost, the first
491 /// step yields just the ghost and then the search is exhausted.
492 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
493 fn start_with_only_a_ghostrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/start_with_only_a_ghost().() {
494 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[("a-ghost", &[])]);
495 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["a-ghost"]);
496 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["a-ghost"])));
497 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
498 }
499
500 /// Translated from `test_breadth_first_change_search`: stop the current
501 /// frontier, start a new search from an unrelated revision, and
502 /// verify the BFS picks up the new revision's ancestors.
503 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
504 fn change_search_via_stop_and_startrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/change_search_via_stop_and_start().() {
505 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[
506 ("head", &["present"]),
507 ("present", &["stopped"]),
508 ("stopped", &[]),
509 ("other", &["other_2"]),
510 ("other_2", &[]),
511 ]);
512 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["head"]);
513 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_with_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_with_ghosts().(&p), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["head"]), as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().([]))));
514 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
515 s.next_with_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_with_ghosts().(&p),
516 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["present"]), as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().([])))
517 );
518 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.stop_searching_anyrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]stop_searching_any().(["present"]), as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["present"]));
519 let (present, ghosts) = s.start_searchingrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]start_searching().(["other", "other_ghost"], &p).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
520 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(present, as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["other"]));
521 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ghosts, as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["other_ghost"]));
522 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
523 s.next_with_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_with_ghosts().(&p),
524 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["other_2"]), as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().([])))
525 );
526 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_with_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_with_ghosts().(&p), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
527 }
528
529 const NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL.: &str = "null:";
530
531 /// Mirrors `test_breadth_first_search_change_next_to_next_with_ghosts`:
532 /// interleave `next()` and `next_with_ghosts()` on the same searcher
533 /// and verify both modes produce sensible values.
534 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
535 fn change_next_to_next_with_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/change_next_to_next_with_ghosts().() {
536 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[
537 ("head", &["present"]),
538 ("present", &["child", "ghost"]),
539 ("child", &[]),
540 ]);
541 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["head"]);
542 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_with_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_with_ghosts().(&p), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["head"]), as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().([]))));
543 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["present"])));
544 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
545 s.next_with_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_with_ghosts().(&p),
546 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["child"]), as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["ghost"])))
547 );
548 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
549
550 // Symmetric: start with next(), switch to next_with_ghosts().
551 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["head"]);
552 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["head"])));
553 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
554 s.next_with_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_with_ghosts().(&p),
555 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["present"]), as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().([])))
556 );
557 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["child", "ghost"])));
558 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_with_ghostsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_with_ghosts().(&p), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
559 }
560
561 /// Mirrors `test_breadth_first_get_result_excludes_current_pending`:
562 /// at the start, nothing is seen; after each advance, `get_state()`
563 /// reports the started keys, the excluded set, and the included
564 /// (fully explored) set.
565 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
566 fn get_state_excludes_current_pendingrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/get_state_excludes_current_pending().() {
567 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[("head", &["child"]), ("child", &[NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL.]), (NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL., &[])]);
568 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["head"]);
569 let (started, excludes, included) = s.get_staterust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]get_state().(&p);
570 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(started, as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["head"]));
571 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(excludes, as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["head"]));
572 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(included, as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().([]));
573 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.seenrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#seen., as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().([]));
574
575 // After next: head is yielded, still excluded because child is
576 // the next frontier.
577 s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p);
578 let (_, excludes, included) = s.get_staterust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]get_state().(&p);
579 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(excludes, as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["child"]));
580 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(included, as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["head"]));
581 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.seenrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#seen., as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["head"]));
582
583 // After child: null is the next frontier.
584 s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p);
585 let (_, excludes, included) = s.get_staterust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]get_state().(&p);
586 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(excludes, as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().([NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL.]));
587 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(included, as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["head", "child"]));
588
589 // After null: nothing left in the frontier.
590 s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p);
591 let (_, excludes, included) = s.get_staterust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]get_state().(&p);
592 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(excludes, as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().([]));
593 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(included, as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["head", "child", NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL.]));
594 }
595
596 /// Mirrors `test_breadth_first_stop_searching_not_queried`: a client
597 /// may tell the searcher to stop a key, and stopped_keys records it
598 /// for later exclusion from the result's included-set.
599 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
600 fn stop_searching_records_stopsrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/stop_searching_records_stops().() {
601 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[
602 ("head", &["child", "ghost1"]),
603 ("child", &[NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL.]),
604 (NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL., &[]),
605 ]);
606 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["head"]);
607 s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p); // yields head
608 s.stop_searching_anyrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]stop_searching_any().([NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL., "ghost1"]);
609 // The stopped keys are in stopped_keys regardless of whether
610 // they've been visited yet.
611 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(s.stopped_keysrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#stopped_keys..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL.));
612 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(s.stopped_keysrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#stopped_keys..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&"ghost1"));
613 // get_state() should exclude the stopped keys from the
614 // "included" snapshot.
615 let (_, excludes, included) = s.get_staterust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]get_state().(&p);
616 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(excludes.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL.));
617 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(excludes.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&"ghost1"));
618 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().included.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL.));
619 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().included.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&"ghost1"));
620 }
621
622 /// Mirrors `test_breadth_first_stop_searching_late`: stopping a key
623 /// from an older iteration should still exclude it from the result.
624 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
625 fn stop_searching_laterust-analyzer cargo vcs-graph 3.6.0 bfs/tests/stop_searching_late().() {
626 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[
627 ("head", &["middle"]),
628 ("middle", &["child"]),
629 ("child", &[NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL.]),
630 (NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL., &[]),
631 ]);
632 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["head"]);
633 s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p); // yields head
634 s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p); // yields middle
635 s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p); // yields child
636 // Now stop both middle and child retroactively.
637 s.stop_searching_anyrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]stop_searching_any().(["middle", "child"]);
638 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(s.stopped_keysrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#stopped_keys..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&"middle"));
639 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(s.stopped_keysrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#stopped_keys..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&"child"));
640 // After the stop, the remaining state reflects that only the
641 // original head is included.
642 let (_, excludes, included) = s.get_staterust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]get_state().(&p);
643 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(excludes.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&"middle"));
644 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(excludes.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&"child"));
645 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(included, as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["head"]));
646 }
647
648 /// Mirrors `test_breadth_first_get_result_starting_a_ghost_ghost_is_excluded`:
649 /// start_searching a ghost key mid-walk. The ghost is recorded in seen
650 /// but gets filed under stopped_keys so it is excluded from included().
651 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
652 fn start_searching_a_ghost_excludes_itrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/start_searching_a_ghost_excludes_it().() {
653 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[("head", &["child"]), ("child", &[NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL.]), (NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL., &[])]);
654 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["head"]);
655 // Start-searching a ghost while in next_with_ghosts mode (the
656 // default after construction). This returns (present, ghosts).
657 let (present, ghosts) = s.start_searchingrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]start_searching().(["ghost"], &p).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
658 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(present, as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().([]));
659 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ghosts, as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["ghost"]));
660 // ghost is now in stopped_keys so included() doesn't report it.
661 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(s.stopped_keysrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#stopped_keys..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&"ghost"));
662 }
663
664 /// Mirrors `test_breadth_first_revision_count_includes_NULL_REVISION`:
665 /// walking to the sentinel should count it as part of `seen`.
666 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
667 fn walk_includes_null_revisionrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/walk_includes_null_revision().() {
668 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[("head", &[NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL.]), (NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL., &[])]);
669 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["head"]);
670 s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p); // yields head
671 s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p); // yields null
672 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.seenrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#seen., as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["head", NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL.]));
673 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
674 }
675
676 /// Mirrors `test_breadth_first_search_get_result_after_StopIteration`:
677 /// hitting StopIteration should not invalidate the searcher; a
678 /// subsequent get_state() still works.
679 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
680 fn get_state_after_stop_iterationrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/get_state_after_stop_iteration().() {
681 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[("head", &[NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL.]), (NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL., &[])]);
682 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["head"]);
683 while s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p).is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {}
684 // No more to yield.
685 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
686 let (started, _excludes, included) = s.get_staterust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]get_state().(&p);
687 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(started, as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["head"]));
688 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(included.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&"head"));
689 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(included.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL.));
690 }
691
692 /// find_seen_ancestors should walk the parent chain and collect all
693 /// ancestors already in `seen` — not new ones.
694 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
695 fn find_seen_ancestors_walks_seen_chainrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/find_seen_ancestors_walks_seen_chain().() {
696 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[
697 ("head", &["middle"]),
698 ("middle", &["child"]),
699 ("child", &[NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL.]),
700 (NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL., &[]),
701 ]);
702 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["head"]);
703 // Walk the whole thing.
704 while s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p).is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {}
705 // Ask for ancestors of "middle" — should find middle, child, null.
706 let anc = s.find_seen_ancestorsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]find_seen_ancestors().(["middle"], &p);
707 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(anc.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&"middle"));
708 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(anc.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&"child"));
709 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(anc.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL.));
710 }
711
712 /// find_seen_ancestors should filter out keys not in seen.
713 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
714 fn find_seen_ancestors_skips_unseenrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/find_seen_ancestors_skips_unseen().() {
715 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[("head", &[NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL.]), (NULLrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/NULL., &[]), ("unrelated", &[])]);
716 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["head"]);
717 s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p); // yields head
718 let anc = s.find_seen_ancestorsrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]find_seen_ancestors().(["unrelated"], &p);
719 // "unrelated" isn't in seen, so find_seen_ancestors returns an
720 // empty set for it.
721 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().anc.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&"unrelated"));
722 }
723
724 /// stop_searching_any should return only the keys that were actually
725 /// removed from the current frontier (not keys that had already been
726 /// processed).
727 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
728 fn stop_searching_any_returns_only_effective_stopsrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/stop_searching_any_returns_only_effective_stops().() {
729 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[("head", &["a"]), ("a", &["b"]), ("b", &[])]);
730 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["head"]);
731 s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p); // yields head
732 s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p); // yields a
733 // `head` is already returned; stopping it should report it as
734 // stopped but a no longer in frontier means only keys that are in
735 // next_query at stop time get returned.
736 let stopped = s.stop_searching_anyrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]stop_searching_any().(["a"]);
737 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stopped, as_setrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/as_set().(["a"]));
738 // After stopping a, the search is exhausted.
739 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
740 }
741
742 /// Starting an already-seen key should be a no-op on `seen` and the
743 /// key should not be re-queried.
744 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
745 fn start_searching_already_seen_is_nooprust-analyzer cargo vcs-graph 3.6.0 bfs/tests/start_searching_already_seen_is_noop().() {
746 let p = providerrust-analyzer cargo vcs-graph 3.6.0 bfs/tests/provider().(&[("head", &["child"]), ("child", &[])]);
747 let mut s = BfsStaterust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#::newrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]new().(["head"]);
748 s.next_setrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]next_set().(&p); // yields head, frontier now contains "child"
749 let pre_seen = s.seenrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#seen..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][Clone]clone().();
750 s.start_searchingrust-analyzer cargo vcs-graph 3.6.0 bfs/impl#[`BfsState<K>`]start_searching().(["head"], &p);
751 // seen should be unchanged (head was already there).
752 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s.seenrust-analyzer cargo vcs-graph 3.6.0 bfs/BfsState#seen., pre_seen);
753 }
754 }