| 1 | //! KnownGraph: graph algorithms that assume the full ancestry is already loaded. |
| 2 | //! |
| 3 | //! Ported from `vcsgraph/known_graph.py`. |
| 4 | |
| 5 | use craterust-analyzer cargo vcs-graph 3.6.0 crate/::tsortrust-analyzer cargo vcs-graph 3.6.0 tsort/::MergeSorterrust-analyzer cargo vcs-graph 3.6.0 tsort/MergeSorter#; |
| 6 | use craterust-analyzer cargo vcs-graph 3.6.0 crate/::{Errorrust-analyzer cargo vcs-graph 3.6.0 Error#, RevnoVecrust-analyzer cargo vcs-graph 3.6.0 RevnoVec#}; |
| 7 | 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#}; |
| 8 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Reverserust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Reverse#; |
| 9 | 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/::{BinaryHeaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/binary_heap/BinaryHeap#, HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#, VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#}; |
| 10 | 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#; |
| 11 | |
| 12 | /// A key that may either be a real node or the synthetic "origin" sentinel |
| 13 | /// (equivalent to `NULL_REVISION` in the Python implementation). |
| 14 | /// |
| 15 | /// Only used by [`KnownGraph::heads`], which has special semantics for the |
| 16 | /// origin: it is only considered a head when it is the sole candidate. |
| 17 | #[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:, 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:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)] |
| 18 | pub enum Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#<K> { |
| 19 | Originrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#Origin#, |
| 20 | Noderust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#Node#(K), |
| 21 | } |
| 22 | |
| 23 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 24 | struct KnownGraphNoderust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#<K> { |
| 25 | parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#parent_keys.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K>>, |
| 26 | child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#child_keys.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K>, |
| 27 | gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#gdfo.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u64>, |
| 28 | } |
| 29 | |
| 30 | /// Produce a Vec of `items` ordered by hash of each element. Used as a stable |
| 31 | /// (within one process) cache key for unordered sets when `K: Ord` is not |
| 32 | /// required. |
| 33 | fn sort_by_hashrust-analyzer cargo vcs-graph 3.6.0 known_graph/sort_by_hash().<K: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#, 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>>(items: I) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K> { |
| 34 | 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/::hash_maprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash_map/::DefaultHasherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/random/DefaultHasher#; |
| 35 | 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/::Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#; |
| 36 | let hash_of = |k: &K| { |
| 37 | let mut h = DefaultHasherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/random/DefaultHasher#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/random/impl#[DefaultHasher]new().(); |
| 38 | k.hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#hash().(&mut h); |
| 39 | h.finishrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/random/impl#[DefaultHasher][Hasher]finish().() |
| 40 | }; |
| 41 | let mut v: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K> = items.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().(); |
| 42 | v.sort_by_keyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort_by_key().(hash_of); |
| 43 | v |
| 44 | } |
| 45 | |
| 46 | impl<K> KnownGraphNoderust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#<K> { |
| 47 | fn newrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraphNode<K>`]new().(parent_keys: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K>>) -> Selfrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraphNode<K>`] { |
| 48 | KnownGraphNoderust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode# { |
| 49 | parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#parent_keys., |
| 50 | child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#child_keys.: 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().(), |
| 51 | gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#gdfo.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | fn is_ghostrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraphNode<K>`]is_ghost().(&self) -> bool { |
| 56 | self.parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#parent_keys..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /// Information about a node in a merge-sorted graph. |
| 61 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, 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:)] |
| 62 | pub struct MergeSortNoderust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#<K> { |
| 63 | pub keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#key.: K, |
| 64 | pub merge_depthrust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#merge_depth.: usize, |
| 65 | pub revnorust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#revno.: RevnoVecrust-analyzer cargo vcs-graph 3.6.0 RevnoVec#, |
| 66 | pub end_of_mergerust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#end_of_merge.: bool, |
| 67 | } |
| 68 | |
| 69 | /// A graph where the full ancestry is already known. |
| 70 | /// |
| 71 | /// Supports gdfo-based queries like [`heads`](Self::heads), plus various |
| 72 | /// topological orderings. |
| 73 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 74 | pub struct KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#<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#> { |
| 75 | nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes.: FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#<K, KnownGraphNoderust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#<K>>, |
| 76 | known_headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#known_heads.: FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K>, FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>>, |
| 77 | do_cacherust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#do_cache.: bool, |
| 78 | } |
| 79 | |
| 80 | 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#> KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#<K> { |
| 81 | /// Build a new KnownGraph from a parent map. |
| 82 | pub fn newrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]new().<I>(parent_map: I, do_cache: bool) -> Selfrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`] |
| 83 | where |
| 84 | 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, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K>)>, |
| 85 | { |
| 86 | let iter = parent_map.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().(); |
| 87 | // Use the lower bound of size_hint to pre-allocate when the caller |
| 88 | // passes a sized iterator (HashMap, Vec, etc). Ghosts will grow the |
| 89 | // map a little beyond this. |
| 90 | let cap = iter.size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().().0; |
| 91 | let mut g = KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph# { |
| 92 | nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::with_capacity_and_hasherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S>`]with_capacity_and_hasher().(cap, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo rustc-hash 2.1.2 impl#[FxBuildHasher][Default]default().()), |
| 93 | known_headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#known_heads.: 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().(), |
| 94 | do_cacherust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#do_cache., |
| 95 | }; |
| 96 | g.initialize_nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]initialize_nodes().(iter); |
| 97 | g.find_gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]find_gdfo().(); |
| 98 | g |
| 99 | } |
| 100 | |
| 101 | fn initialize_nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]initialize_nodes().<I>(&mut self, parent_map: I) |
| 102 | where |
| 103 | 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, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K>)>, |
| 104 | { |
| 105 | for (key, parent_keys) in parent_map { |
| 106 | // Ensure all parent nodes exist and record the reverse edge. |
| 107 | for parent_key in &parent_keys { |
| 108 | self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes. |
| 109 | .entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]entry().(parent_key.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()) |
| 110 | .or_insert_withrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`Entry<'a, K, V, A>`]or_insert_with().(|| KnownGraphNoderust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#::newrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraphNode<K>`]new().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)) |
| 111 | .child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#child_keys. |
| 112 | .pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(key.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()); |
| 113 | } |
| 114 | // Insert or update the node itself. |
| 115 | let node = self |
| 116 | .nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes. |
| 117 | .entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]entry().(key) |
| 118 | .or_insert_withrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`Entry<'a, K, V, A>`]or_insert_with().(|| KnownGraphNoderust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#::newrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraphNode<K>`]new().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)); |
| 119 | node.parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#parent_keys. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parent_keys); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | fn find_tailsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]find_tails().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K> { |
| 124 | // A "tail" has no parents — either a real root (Some(empty)) or a |
| 125 | // ghost (None). Both kinds are treated as gdfo=1 starting points, |
| 126 | // matching the Python `not node.parent_keys` check. |
| 127 | self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes. |
| 128 | .iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]iter().() |
| 129 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|(k, n)| match &n.parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#parent_keys. { |
| 130 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(p) if p.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(k.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()), |
| 131 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(k.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()), |
| 132 | _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 133 | }) |
| 134 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().() |
| 135 | } |
| 136 | |
| 137 | fn find_tipsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]find_tips().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K> { |
| 138 | self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes. |
| 139 | .iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]iter().() |
| 140 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|(k, n)| { |
| 141 | if n.child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#child_keys..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 142 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(k.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()) |
| 143 | } else { |
| 144 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 145 | } |
| 146 | }) |
| 147 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().() |
| 148 | } |
| 149 | |
| 150 | fn find_gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]find_gdfo().(&mut self) { |
| 151 | let mut known_parent_gdfos: FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#<K, usize> = 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().(); |
| 152 | let mut pending: 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().(); |
| 153 | |
| 154 | for key in self.find_tailsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]find_tails().() { |
| 155 | self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes..get_mutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get_mut().(&key).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#gdfo. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1); |
| 156 | pending.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(key); |
| 157 | } |
| 158 | |
| 159 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node_key) = pending.poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().() { |
| 160 | let node_gdfo = self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().&node_key]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()..gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#gdfo..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 161 | let child_keys = self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().&node_key]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()..child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#child_keys..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().(); |
| 162 | for child_key in child_keys { |
| 163 | let (known_gdfo, present) = match known_parent_gdfos.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&child_key) { |
| 164 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1, true), |
| 165 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => (1, false), |
| 166 | }; |
| 167 | let child = self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes..get_mutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get_mut().(&child_key).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 168 | let new_gdfo = node_gdfo rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().1; |
| 169 | if child.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#gdfo..is_none_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none_or().(|g| new_gdfo rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().g) { |
| 170 | child.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#gdfo. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(new_gdfo); |
| 171 | } |
| 172 | let parent_len = child.parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#parent_keys..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|p| p.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0); |
| 173 | if known_gdfo rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().parent_len { |
| 174 | pending.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(child_key.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()); |
| 175 | if present { |
| 176 | known_parent_gdfos.removerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]remove().(&child_key); |
| 177 | } |
| 178 | } else { |
| 179 | known_parent_gdfos.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(child_key, known_gdfo); |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /// Return the parent keys for `key`. Returns `None` if `key` is a ghost, |
| 186 | /// and an error-equivalent `None` lookup via `contains_key` otherwise. |
| 187 | /// |
| 188 | /// Matches the Python semantics: `None` means ghost, missing key would |
| 189 | /// raise `KeyError` in Python — here the caller should check |
| 190 | /// [`contains`](Self::contains) if disambiguation is needed. |
| 191 | pub fn get_parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_parent_keys().(&self, key: &K) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&[K]> { |
| 192 | self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(key)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#parent_keys..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().() |
| 193 | } |
| 194 | |
| 195 | /// Return the child keys for `key`. Returns an empty slice for tips. |
| 196 | pub fn get_child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_child_keys().(&self, key: &K) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&[K]> { |
| 197 | self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(key).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|n| n.child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#child_keys..as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().()) |
| 198 | } |
| 199 | |
| 200 | /// Return whether `key` is present in the graph at all (including ghosts). |
| 201 | pub fn containsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]contains().(&self, key: &K) -> bool { |
| 202 | self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(key) |
| 203 | } |
| 204 | |
| 205 | /// Return the number of nodes in the graph (including ghosts). |
| 206 | pub fn lenrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]len().(&self) -> usize { |
| 207 | self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().() |
| 208 | } |
| 209 | |
| 210 | /// Return whether the graph is empty. |
| 211 | pub fn is_emptyrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]is_empty().(&self) -> bool { |
| 212 | self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes..is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]is_empty().() |
| 213 | } |
| 214 | |
| 215 | /// Iterate over all node keys in the graph (including ghosts). |
| 216 | pub fn keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]keys().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &K> { |
| 217 | self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes..keysrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]keys().() |
| 218 | } |
| 219 | |
| 220 | /// Return the gdfo (greatest distance from origin) of `key`, if known. |
| 221 | pub fn gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&self, key: &K) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u64> { |
| 222 | self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(key).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|n| n.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#gdfo.) |
| 223 | } |
| 224 | |
| 225 | /// Add a new node to the graph, possibly filling in a ghost. |
| 226 | pub fn add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().(&mut self, key: K, parent_keys: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo vcs-graph 3.6.0 Error#<K>> { |
| 227 | // Validate against existing state, then ensure the node exists with |
| 228 | // its parents recorded. We hold off on inserting parents into the |
| 229 | // graph until after this match, so the borrow of `existing` ends. |
| 230 | match self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes..get_mutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get_mut().(&key) { |
| 231 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(existing) => match &existing.parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#parent_keys. { |
| 232 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(existing_parents) if existing_parents rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().&parent_keys => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()), |
| 233 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(existing_parents) => { |
| 234 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo vcs-graph 3.6.0 Error#::ParentMismatchrust-analyzer cargo vcs-graph 3.6.0 Error#ParentMismatch# { |
| 235 | expectedrust-analyzer cargo vcs-graph 3.6.0 Error#ParentMismatch#expected.: existing_parents.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().(), |
| 236 | actualrust-analyzer cargo vcs-graph 3.6.0 Error#ParentMismatch#actual.: parent_keys, |
| 237 | keyrust-analyzer cargo vcs-graph 3.6.0 Error#ParentMismatch#key., |
| 238 | }); |
| 239 | } |
| 240 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 241 | // Filling in a ghost: the heads cache is no longer |
| 242 | // trustworthy. |
| 243 | existing.parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#parent_keys. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parent_keys.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().()); |
| 244 | self.known_headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#known_heads..clearrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]clear().(); |
| 245 | } |
| 246 | }, |
| 247 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 248 | self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes. |
| 249 | .insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(key.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), KnownGraphNoderust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#::newrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraphNode<K>`]new().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parent_keys.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().()))); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | let mut parent_gdfo: u64 = 0; |
| 254 | for parent_key in &parent_keys { |
| 255 | let parent_node = self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes..entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]entry().(parent_key.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()).or_insert_withrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`Entry<'a, K, V, A>`]or_insert_with().(|| { |
| 256 | let mut n = KnownGraphNoderust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#::newrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraphNode<K>`]new().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 257 | // Ghosts and roots have gdfo 1. |
| 258 | n.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#gdfo. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1); |
| 259 | n |
| 260 | }); |
| 261 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(g) = parent_node.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#gdfo. { |
| 262 | parent_gdfo = parent_gdfo.maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#max().(g); |
| 263 | } |
| 264 | parent_node.child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#child_keys..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(key.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()); |
| 265 | } |
| 266 | self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes..get_mutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get_mut().(&key).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#gdfo. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parent_gdfo rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().1); |
| 267 | |
| 268 | // Propagate gdfo updates to descendants (BFS). |
| 269 | let mut pending: VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#<K> = VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T>`]new().(); |
| 270 | pending.push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_back().(key); |
| 271 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node_key) = pending.pop_frontrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]pop_front().() { |
| 272 | let next_gdfo = self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().&node_key]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()..gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#gdfo..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().1; |
| 273 | let child_keys = self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().&node_key]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()..child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#child_keys..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().(); |
| 274 | for child_key in child_keys { |
| 275 | let child = self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes..get_mutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get_mut().(&child_key).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 276 | if child.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#gdfo..is_none_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none_or().(|g| g rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt().next_gdfo) { |
| 277 | child.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#gdfo. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(next_gdfo); |
| 278 | pending.push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_back().(child_key); |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 283 | } |
| 284 | |
| 285 | /// Return the heads from amongst `keys`. |
| 286 | /// |
| 287 | /// Any key reachable from another key is filtered out. This method is |
| 288 | /// sentinel-free on the core; the caller handles origin semantics by |
| 289 | /// wrapping `K` in [`Key<K>`] and calling [`heads_with_origin`]. |
| 290 | /// |
| 291 | /// All keys in `candidates` must be present in the graph (not ghosts). |
| 292 | pub fn headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().<I>(&mut self, candidates: I) -> FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> |
| 293 | where |
| 294 | 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>, |
| 295 | { |
| 296 | let candidates: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = candidates.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().(); |
| 297 | if candidates.lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().2 { |
| 298 | return candidates; |
| 299 | } |
| 300 | |
| 301 | // Build a process-stable cache key by sorting candidates by their |
| 302 | // hash. Hash collisions in the comparator just produce non-unique |
| 303 | // orderings; the resulting Vec still uniquely identifies the input |
| 304 | // set within a single process (different sets differ in length or |
| 305 | // contents). We can't use BTreeSet here because K is not required |
| 306 | // to be Ord. |
| 307 | let heads_cache_key = sort_by_hashrust-analyzer cargo vcs-graph 3.6.0 known_graph/sort_by_hash().(candidates.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().()); |
| 308 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cached) = self.known_headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#known_heads..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&heads_cache_key) { |
| 309 | return cached.clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][Clone]clone().(); |
| 310 | } |
| 311 | |
| 312 | let mut seen: 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().(); |
| 313 | let mut pending: 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().(); |
| 314 | let mut min_gdfo: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u64> = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 315 | for key in &candidates { |
| 316 | let node = &self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().key]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().; |
| 317 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parents) = &node.parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#parent_keys. { |
| 318 | pending.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(parents.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().()); |
| 319 | } |
| 320 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(g) = node.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#gdfo. { |
| 321 | min_gdfo = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(min_gdfo.map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(g, |m| m.minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#min().(g))); |
| 322 | } |
| 323 | } |
| 324 | let min_gdfo = min_gdfo.unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0); |
| 325 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node_key) = pending.poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().() { |
| 326 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().seen.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(node_key.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()) { |
| 327 | continue; |
| 328 | } |
| 329 | let node = &self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().&node_key]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().; |
| 330 | if node.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#gdfo..is_some_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some_and().(|g| g rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]le().min_gdfo) { |
| 331 | continue; |
| 332 | } |
| 333 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parents) = &node.parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#parent_keys. { |
| 334 | pending.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(parents.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().()); |
| 335 | } |
| 336 | } |
| 337 | let heads: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> = candidates.differencerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]difference().(&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().(); |
| 338 | if self.do_cacherust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#do_cache. { |
| 339 | self.known_headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#known_heads..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(heads_cache_key, heads.clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][Clone]clone().()); |
| 340 | } |
| 341 | heads |
| 342 | } |
| 343 | |
| 344 | /// Return the nodes of the graph in topological order (parents first). |
| 345 | /// |
| 346 | /// Errors with [`Error::Cycle`] if the graph is not fully connected via |
| 347 | /// gdfo (i.e. contains a cycle). |
| 348 | pub fn topo_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]topo_sort().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K>, Errorrust-analyzer cargo vcs-graph 3.6.0 Error#<K>> { |
| 349 | let unreachable: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K> = self |
| 350 | .nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes. |
| 351 | .iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]iter().() |
| 352 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|(_, n)| n.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#gdfo..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()) |
| 353 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(k, _)| k.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()) |
| 354 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 355 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().unreachable.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 356 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo vcs-graph 3.6.0 Error#::Cyclerust-analyzer cargo vcs-graph 3.6.0 Error#Cycle#(unreachable)); |
| 357 | } |
| 358 | let mut pending = self.find_tailsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]find_tails().(); |
| 359 | let mut num_seen_parents: FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#<K, usize> = |
| 360 | self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes..keysrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]keys().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|k| (k.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), 0)).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 361 | let mut topo_order: 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#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().()); |
| 362 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node_key) = pending.poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().() { |
| 363 | let node = &self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().&node_key]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().; |
| 364 | // Skip ghosts in the output (matches Python behavior). |
| 365 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().node.is_ghostrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraphNode<K>`]is_ghost().() { |
| 366 | topo_order.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(node_key.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()); |
| 367 | } |
| 368 | let child_keys = node.child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#child_keys..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().(); |
| 369 | for child_key in child_keys { |
| 370 | let child = &self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().&child_key]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().; |
| 371 | let seen_parents = num_seen_parents[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().&child_key]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1; |
| 372 | let parent_len = child.parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#parent_keys..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|p| p.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0); |
| 373 | if seen_parents rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().parent_len { |
| 374 | pending.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(child_key.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()); |
| 375 | num_seen_parents.removerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]remove().(&child_key); |
| 376 | } else { |
| 377 | num_seen_parents.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(child_key, seen_parents); |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(topo_order) |
| 382 | } |
| 383 | |
| 384 | /// Return a reverse topological ordering grouped by prefix. |
| 385 | /// |
| 386 | /// `prefix_of` maps each key to its prefix bucket. Within each bucket the |
| 387 | /// ordering is lexicographic (by `K: Ord`), which mirrors Python's use of |
| 388 | /// tuple/bytes ordering there. Ghost nodes are skipped in the output. |
| 389 | pub fn gc_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gc_sort().<P, PFX>(&self, mut prefix_of: P) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K> |
| 390 | where |
| 391 | K: Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#, |
| 392 | P: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&K) -> PFX, |
| 393 | PFX: Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#, |
| 394 | { |
| 395 | let mut prefix_tips: FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#<PFX, 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().(); |
| 396 | for key in self.find_tipsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]find_tips().() { |
| 397 | prefix_tips.entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]entry().(prefix_of(&key)).or_defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`Entry<'a, K, V>`]or_default().().pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(key); |
| 398 | } |
| 399 | let mut num_seen_children: FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#<K, usize> = |
| 400 | self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes..keysrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]keys().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|k| (k.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), 0)).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 401 | |
| 402 | let mut prefix_list: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(PFX, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K>)> = prefix_tips.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().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 403 | prefix_list.sort_byrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort_by().(|a, b| a.0.cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#cmp().(&b.0)); |
| 404 | |
| 405 | let mut result: 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#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().()); |
| 406 | for (_prefix, tips) in prefix_list { |
| 407 | // A min-heap (via Reverse) keeps the next-smallest key at the top |
| 408 | // in O(log n), instead of re-sorting the pending vector after |
| 409 | // every parent insertion. |
| 410 | let mut pending: BinaryHeaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/binary_heap/BinaryHeap#<Reverserust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Reverse#<K>> = tips.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Reverserust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Reverse#).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 411 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Reverserust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Reverse#(node_key)) = pending.poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/binary_heap/impl#[`BinaryHeap<T, A>`]pop().() { |
| 412 | let node = &self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().&node_key]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().; |
| 413 | if node.is_ghostrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraphNode<K>`]is_ghost().() { |
| 414 | continue; |
| 415 | } |
| 416 | let parent_keys = node.parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#parent_keys..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(&[]); |
| 417 | for parent_key in parent_keys { |
| 418 | let parent_node = &self.nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().parent_key]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().; |
| 419 | let seen_children = num_seen_children[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().parent_key]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1; |
| 420 | if seen_children rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().parent_node.child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#child_keys..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() { |
| 421 | pending.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/binary_heap/impl#[`BinaryHeap<T, A>`]push().(Reverserust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Reverse#(parent_key.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().())); |
| 422 | num_seen_children.removerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]remove().(parent_key); |
| 423 | } else { |
| 424 | num_seen_children.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(parent_key.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), seen_children); |
| 425 | } |
| 426 | } |
| 427 | result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(node_key); |
| 428 | } |
| 429 | } |
| 430 | result |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | 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# + stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#> KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#<K> { |
| 435 | /// Merge-sort the graph starting from `tip_key`. |
| 436 | /// |
| 437 | /// Requires `K: Debug` because the underlying [`MergeSorter`] does. |
| 438 | pub fn merge_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]merge_sort().(&self, tip_key: K) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<MergeSortNoderust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#<K>>, Errorrust-analyzer cargo vcs-graph 3.6.0 Error#<K>> { |
| 439 | let as_parent_map: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<K, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K>> = self |
| 440 | .nodesrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#nodes. |
| 441 | .iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]iter().() |
| 442 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|(k, n)| n.parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraphNode#parent_keys..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|p| (k.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), p.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().()))) |
| 443 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 444 | MergeSorterrust-analyzer cargo vcs-graph 3.6.0 tsort/MergeSorter#::newrust-analyzer cargo vcs-graph 3.6.0 tsort/impl#[`MergeSorter<K>`]new().(as_parent_map, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tip_key), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, true) |
| 445 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|item| { |
| 446 | item.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|(_, key, merge_depth, revno, end_of_merge)| MergeSortNoderust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode# { |
| 447 | keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#key., |
| 448 | merge_depthrust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#merge_depth., |
| 449 | revnorust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#revno.: revno.unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().(), |
| 450 | end_of_mergerust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#end_of_merge., |
| 451 | }) |
| 452 | }) |
| 453 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().() |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | 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#> KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#<Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#<K>> { |
| 458 | /// `heads()` variant that implements the Python `NULL_REVISION` filter: |
| 459 | /// [`Key::Origin`] is only a head if it is the sole candidate. |
| 460 | pub fn heads_with_originrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<Key<K>>`]heads_with_origin().<I>(&mut self, candidates: I) -> FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#<K>> |
| 461 | where |
| 462 | 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# = Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#<K>>, |
| 463 | { |
| 464 | let mut candidates: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#<K>> = candidates.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().(); |
| 465 | if candidates.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#::Originrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#Origin#) { |
| 466 | candidates.removerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]remove().(&Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#::Originrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#Origin#); |
| 467 | if candidates.is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]is_empty().() { |
| 468 | let mut r = 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().(); |
| 469 | r.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#::Originrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#Origin#); |
| 470 | return r; |
| 471 | } |
| 472 | } |
| 473 | self.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(candidates) |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | #[cfg(test)] |
| 478 | mod testsrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/ { |
| 479 | use superrust-analyzer cargo vcs-graph 3.6.0 known_graph/::*; |
| 480 | |
| 481 | fn makerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/make().(edges: &[(&'static str, &[&'static str])]) -> KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#<&'static str> { |
| 482 | let pm = 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().())); |
| 483 | KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#::newrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]new().(pm, true) |
| 484 | } |
| 485 | |
| 486 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 487 | fn gdfo_linearrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/gdfo_linear().() { |
| 488 | // a -> b -> c |
| 489 | let g = makerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/make().(&[("a", &[]), ("b", &["a"]), ("c", &["b"])]); |
| 490 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"a"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1)); |
| 491 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"b"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2)); |
| 492 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"c"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3)); |
| 493 | } |
| 494 | |
| 495 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 496 | fn gdfo_diamondrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/gdfo_diamond().() { |
| 497 | // a |
| 498 | // / \ |
| 499 | // b c |
| 500 | // \ / |
| 501 | // d |
| 502 | let g = makerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/make().(&[("a", &[]), ("b", &["a"]), ("c", &["a"]), ("d", &["b", "c"])]); |
| 503 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"a"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1)); |
| 504 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"b"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2)); |
| 505 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"c"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2)); |
| 506 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"d"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3)); |
| 507 | } |
| 508 | |
| 509 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 510 | fn heads_trivialrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/heads_trivial().() { |
| 511 | let mut g = makerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/make().(&[("a", &[]), ("b", &["a"])]); |
| 512 | let h = g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a", "b"]); |
| 513 | let expected: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<_> = ["b"].iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#copied().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 514 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(h, expected); |
| 515 | } |
| 516 | |
| 517 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 518 | fn heads_diamondrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/heads_diamond().() { |
| 519 | let mut g = makerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/make().(&[("a", &[]), ("b", &["a"]), ("c", &["a"]), ("d", &["b", "c"])]); |
| 520 | let h = g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["b", "c"]); |
| 521 | let expected: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<_> = ["b", "c"].iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#copied().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 522 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(h, expected); |
| 523 | let h2 = g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a", "d"]); |
| 524 | let expected2: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<_> = ["d"].iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#copied().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 525 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(h2, expected2); |
| 526 | } |
| 527 | |
| 528 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 529 | fn heads_with_origin_onlyrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/heads_with_origin_only().() { |
| 530 | let mut g: KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#<Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#<&'static str>> = |
| 531 | KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#::newrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]new().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#::Noderust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#Node#("a"), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#::Originrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#Origin#])], true); |
| 532 | let h = g.heads_with_originrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<Key<K>>`]heads_with_origin().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#::Originrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#Origin#]); |
| 533 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(h.lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]len().(), 1); |
| 534 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(h.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#::Originrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#Origin#)); |
| 535 | } |
| 536 | |
| 537 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 538 | fn heads_with_origin_ignoredrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/heads_with_origin_ignored().() { |
| 539 | let mut g: KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#<Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#<&'static str>> = |
| 540 | KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#::newrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]new().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#::Noderust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#Node#("a"), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#::Originrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#Origin#])], true); |
| 541 | let h = g.heads_with_originrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<Key<K>>`]heads_with_origin().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#::Originrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#Origin#, Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#::Noderust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#Node#("a")]); |
| 542 | let expected: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<_> = [Keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#::Noderust-analyzer cargo vcs-graph 3.6.0 known_graph/Key#Node#("a")].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().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 543 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(h, expected); |
| 544 | } |
| 545 | |
| 546 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 547 | fn topo_sort_basicrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/topo_sort_basic().() { |
| 548 | let g = makerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/make().(&[("a", &[]), ("b", &["a"]), ("c", &["a"]), ("d", &["b", "c"])]); |
| 549 | let order = g.topo_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]topo_sort().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 550 | // a must come before b, c; b, c must come before d. |
| 551 | let pos = |x: &&str| order.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().positionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]position().(|n| n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().x).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 552 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pos(&"a") <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). pos(&"b")); |
| 553 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pos(&"a") <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). pos(&"c")); |
| 554 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pos(&"b") <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). pos(&"d")); |
| 555 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pos(&"c") <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). pos(&"d")); |
| 556 | } |
| 557 | |
| 558 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 559 | fn add_node_fills_ghostrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/add_node_fills_ghost().() { |
| 560 | // Start with b having ghost parent a. |
| 561 | let mut g = makerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/make().(&[("b", &["a"])]); |
| 562 | // a is a ghost: present with None parents. |
| 563 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(g.get_parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_parent_keys().(&"a").is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()); |
| 564 | g.add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().("a", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 565 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.get_parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_parent_keys().(&"a"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&[][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)); |
| 566 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"a"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1)); |
| 567 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"b"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2)); |
| 568 | } |
| 569 | |
| 570 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 571 | fn add_node_duplicate_okrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/add_node_duplicate_ok().() { |
| 572 | let mut g = makerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/make().(&[("a", &[]), ("b", &["a"])]); |
| 573 | g.add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().("b", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a"]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 574 | } |
| 575 | |
| 576 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 577 | fn add_node_mismatch_errorsrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/add_node_mismatch_errors().() { |
| 578 | let mut g = makerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/make().(&[("a", &[]), ("b", &["a"])]); |
| 579 | let r = g.add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().("b", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]); |
| 580 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(r, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo vcs-graph 3.6.0 Error#::ParentMismatchrust-analyzer cargo vcs-graph 3.6.0 Error#ParentMismatch# { .. }))); |
| 581 | } |
| 582 | |
| 583 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 584 | fn merge_sort_simplerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/merge_sort_simple().() { |
| 585 | // a -> b -> c, linear |
| 586 | let g = makerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/make().(&[("a", &[]), ("b", &["a"]), ("c", &["b"])]); |
| 587 | let ms = g.merge_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]merge_sort().("c").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 588 | let keys: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = ms.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().(|n| n.keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#key.).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 589 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(keys, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["c", "b", "a"]); |
| 590 | } |
| 591 | |
| 592 | /// Shared fixtures mirrored from `vcsgraph/tests/test_graph.py`. |
| 593 | const NULLrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/NULL.: &str = "null:"; |
| 594 | |
| 595 | fn ancestry_1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/ancestry_1().() -> KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#<&'static str> { |
| 596 | makerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/make().(&[ |
| 597 | ("rev1", &[NULLrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/NULL.]), |
| 598 | ("rev2a", &["rev1"]), |
| 599 | ("rev2b", &["rev1"]), |
| 600 | ("rev3", &["rev2a"]), |
| 601 | ("rev4", &["rev3", "rev2b"]), |
| 602 | ]) |
| 603 | } |
| 604 | |
| 605 | fn feature_branchrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/feature_branch().() -> KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#<&'static str> { |
| 606 | makerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/make().(&[ |
| 607 | ("rev1", &[NULLrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/NULL.]), |
| 608 | ("rev2b", &["rev1"]), |
| 609 | ("rev3b", &["rev2b"]), |
| 610 | ]) |
| 611 | } |
| 612 | |
| 613 | fn extended_history_shortcutrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/extended_history_shortcut().() -> KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#<&'static str> { |
| 614 | makerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/make().(&[ |
| 615 | ("a", &[NULLrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/NULL.]), |
| 616 | ("b", &["a"]), |
| 617 | ("c", &["b"]), |
| 618 | ("d", &["c"]), |
| 619 | ("e", &["d"]), |
| 620 | ("f", &["a", "d"]), |
| 621 | ]) |
| 622 | } |
| 623 | |
| 624 | fn with_ghostrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/with_ghost().() -> KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#<&'static str> { |
| 625 | // A graph with a ghost at `g`. |
| 626 | makerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/make().(&[ |
| 627 | ("a", &["b"]), |
| 628 | ("c", &["b", "d"]), |
| 629 | ("b", &["e"]), |
| 630 | ("d", &["e", "g"]), |
| 631 | ("e", &["f"]), |
| 632 | ("f", &[NULLrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/NULL.]), |
| 633 | (NULLrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/NULL., &[]), |
| 634 | ]) |
| 635 | } |
| 636 | |
| 637 | fn criss_crossrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/criss_cross().() -> KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#<&'static str> { |
| 638 | makerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/make().(&[ |
| 639 | ("rev1", &[NULLrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/NULL.]), |
| 640 | ("rev2a", &["rev1"]), |
| 641 | ("rev2b", &["rev1"]), |
| 642 | ("rev3a", &["rev2a", "rev2b"]), |
| 643 | ("rev3b", &["rev2b", "rev2a"]), |
| 644 | ]) |
| 645 | } |
| 646 | |
| 647 | fn history_shortcutrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/history_shortcut().() -> KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#<&'static str> { |
| 648 | makerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/make().(&[ |
| 649 | ("rev1", &[NULLrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/NULL.]), |
| 650 | ("rev2a", &["rev1"]), |
| 651 | ("rev2b", &["rev1"]), |
| 652 | ("rev2c", &["rev1"]), |
| 653 | ("rev3a", &["rev2a", "rev2b"]), |
| 654 | ("rev3b", &["rev2b", "rev2c"]), |
| 655 | ]) |
| 656 | } |
| 657 | |
| 658 | /// Equivalent of Python's `alt_merge` fixture. |
| 659 | fn alt_mergerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/alt_merge().() -> KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#<&'static str> { |
| 660 | makerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/make().(&[("a", &[]), ("b", &["a"]), ("c", &["b"]), ("d", &["a", "c"])]) |
| 661 | } |
| 662 | |
| 663 | fn setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().<const N: usize>(xs: [&'static str; N]) -> FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<&'static str> { |
| 664 | 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().() |
| 665 | } |
| 666 | |
| 667 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 668 | fn test_children_ancestry1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_children_ancestry1().() { |
| 669 | let g = ancestry_1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/ancestry_1().(); |
| 670 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.get_child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_child_keys().(&NULLrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/NULL.), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&["rev1"][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)); |
| 671 | let mut rev1_children: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = g.get_child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_child_keys().(&"rev1").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().(); |
| 672 | rev1_children.sortrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort().(); |
| 673 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rev1_children, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev2a", "rev2b"]); |
| 674 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.get_child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_child_keys().(&"rev2a"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&["rev3"][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)); |
| 675 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.get_child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_child_keys().(&"rev3"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&["rev4"][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)); |
| 676 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.get_child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_child_keys().(&"rev2b"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&["rev4"][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)); |
| 677 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.get_child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_child_keys().(&"not_in_graph"), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 678 | } |
| 679 | |
| 680 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 681 | fn test_parent_ancestry1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_parent_ancestry1().() { |
| 682 | let g = ancestry_1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/ancestry_1().(); |
| 683 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.get_parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_parent_keys().(&"rev1"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&[NULLrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/NULL.][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)); |
| 684 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.get_parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_parent_keys().(&"rev2a"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&["rev1"][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)); |
| 685 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.get_parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_parent_keys().(&"rev2b"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&["rev1"][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)); |
| 686 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.get_parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_parent_keys().(&"rev3"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&["rev2a"][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)); |
| 687 | let mut rev4_parents: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = g.get_parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_parent_keys().(&"rev4").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().(); |
| 688 | rev4_parents.sortrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort().(); |
| 689 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rev4_parents, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev2b", "rev3"]); |
| 690 | } |
| 691 | |
| 692 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 693 | fn test_parent_with_ghostrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_parent_with_ghost().() { |
| 694 | // In `with_ghost`, "g" is a ghost: present as a parent of `d` but |
| 695 | // has no parent_keys of its own. |
| 696 | let g = with_ghostrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/with_ghost().(); |
| 697 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.get_parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_parent_keys().(&"g"), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 698 | } |
| 699 | |
| 700 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 701 | fn test_gdfo_ancestry_1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_gdfo_ancestry_1().() { |
| 702 | let g = ancestry_1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/ancestry_1().(); |
| 703 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev1"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2)); |
| 704 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev2a"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3)); |
| 705 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev2b"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3)); |
| 706 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev3"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(4)); |
| 707 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev4"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(5)); |
| 708 | } |
| 709 | |
| 710 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 711 | fn test_gdfo_feature_branchrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_gdfo_feature_branch().() { |
| 712 | let g = feature_branchrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/feature_branch().(); |
| 713 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev1"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2)); |
| 714 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev2b"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3)); |
| 715 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev3b"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(4)); |
| 716 | } |
| 717 | |
| 718 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 719 | fn test_gdfo_extended_history_shortcutrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_gdfo_extended_history_shortcut().() { |
| 720 | let g = extended_history_shortcutrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/extended_history_shortcut().(); |
| 721 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"a"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2)); |
| 722 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"b"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3)); |
| 723 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"c"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(4)); |
| 724 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"d"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(5)); |
| 725 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"e"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(6)); |
| 726 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"f"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(6)); |
| 727 | } |
| 728 | |
| 729 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 730 | fn test_gdfo_with_ghostrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_gdfo_with_ghost().() { |
| 731 | let g = with_ghostrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/with_ghost().(); |
| 732 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"f"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2)); |
| 733 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"e"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3)); |
| 734 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"g"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1)); |
| 735 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"b"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(4)); |
| 736 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"d"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(4)); |
| 737 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"a"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(5)); |
| 738 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"c"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(5)); |
| 739 | } |
| 740 | |
| 741 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 742 | fn test_add_existing_node_nooprust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_add_existing_node_noop().() { |
| 743 | let mut g = ancestry_1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/ancestry_1().(); |
| 744 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev4"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(5)); |
| 745 | g.add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().("rev4", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev3", "rev2b"]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 746 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev4"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(5)); |
| 747 | } |
| 748 | |
| 749 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 750 | fn test_add_existing_node_mismatched_parentsrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_add_existing_node_mismatched_parents().() { |
| 751 | let mut g = ancestry_1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/ancestry_1().(); |
| 752 | let r = g.add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().("rev4", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev2b", "rev3"]); |
| 753 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(r, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo vcs-graph 3.6.0 Error#::ParentMismatchrust-analyzer cargo vcs-graph 3.6.0 Error#ParentMismatch# { .. }))); |
| 754 | } |
| 755 | |
| 756 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 757 | fn test_add_node_with_ghost_parentrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_add_node_with_ghost_parent().() { |
| 758 | let mut g = ancestry_1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/ancestry_1().(); |
| 759 | g.add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().("rev5", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev2b", "revGhost"]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 760 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev5"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(4)); |
| 761 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"revGhost"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1)); |
| 762 | } |
| 763 | |
| 764 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 765 | fn test_add_new_rootrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_add_new_root().() { |
| 766 | let mut g = ancestry_1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/ancestry_1().(); |
| 767 | g.add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().("rev5", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 768 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev5"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1)); |
| 769 | } |
| 770 | |
| 771 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 772 | fn test_add_with_all_ghost_parentsrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_add_with_all_ghost_parents().() { |
| 773 | let mut g = ancestry_1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/ancestry_1().(); |
| 774 | g.add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().("rev5", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["ghost"]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 775 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev5"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2)); |
| 776 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"ghost"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1)); |
| 777 | } |
| 778 | |
| 779 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 780 | fn test_gdfo_after_add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_gdfo_after_add_node().() { |
| 781 | let mut g = ancestry_1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/ancestry_1().(); |
| 782 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.get_child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_child_keys().(&"rev4"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&[][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)); |
| 783 | g.add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().("rev5", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev4"]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 784 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.get_parent_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_parent_keys().(&"rev5"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&["rev4"][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)); |
| 785 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.get_child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_child_keys().(&"rev4"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&["rev5"][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)); |
| 786 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.get_child_keysrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]get_child_keys().(&"rev5"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&[][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)); |
| 787 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev5"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(6)); |
| 788 | g.add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().("rev6", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev2b"]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 789 | g.add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().("rev7", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev6"]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 790 | g.add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().("rev8", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev7", "rev5"]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 791 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev5"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(6)); |
| 792 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev6"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(4)); |
| 793 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev7"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(5)); |
| 794 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"rev8"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(7)); |
| 795 | } |
| 796 | |
| 797 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 798 | fn test_fill_in_ghostrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_fill_in_ghost().() { |
| 799 | // Add a few new roots, then fill in the ghost `g` so the |
| 800 | // children's gdfos get renumbered. |
| 801 | let mut g = with_ghostrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/with_ghost().(); |
| 802 | g.add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().("x", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 803 | g.add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().("y", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["x"]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 804 | g.add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().("z", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["y"]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 805 | g.add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().("g", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["z"]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 806 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"f"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2)); |
| 807 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"e"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3)); |
| 808 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"x"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1)); |
| 809 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"y"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2)); |
| 810 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"z"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3)); |
| 811 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"g"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(4)); |
| 812 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"b"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(4)); |
| 813 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"d"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(5)); |
| 814 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"a"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(5)); |
| 815 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.gdforust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]gdfo().(&"c"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(6)); |
| 816 | } |
| 817 | |
| 818 | /// Rust-side `heads()` is sentinel-free; callers are expected to filter |
| 819 | /// NULL themselves. These tests use the core method directly (not |
| 820 | /// `heads_with_origin`) and only test non-null cases — NULL-filtering |
| 821 | /// semantics are covered by existing `heads_with_origin_*` tests. |
| 822 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 823 | fn test_heads_one_non_nullrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_heads_one_non_null().() { |
| 824 | let mut g = ancestry_1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/ancestry_1().(); |
| 825 | for key in ["rev1", "rev2a", "rev2b", "rev3", "rev4"] { |
| 826 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![key]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().([key])); |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 831 | fn test_heads_single_from_ancestry_1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_heads_single_from_ancestry_1().() { |
| 832 | let mut g = ancestry_1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/ancestry_1().(); |
| 833 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev1", "rev2a"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev2a"])); |
| 834 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev1", "rev2b"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev2b"])); |
| 835 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev1", "rev3"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev3"])); |
| 836 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev3", "rev2a"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev3"])); |
| 837 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev1", "rev4"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev4"])); |
| 838 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev2a", "rev4"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev4"])); |
| 839 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev2b", "rev4"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev4"])); |
| 840 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev3", "rev4"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev4"])); |
| 841 | } |
| 842 | |
| 843 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 844 | fn test_heads_two_heads_from_ancestry_1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_heads_two_heads_from_ancestry_1().() { |
| 845 | let mut g = ancestry_1rust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/ancestry_1().(); |
| 846 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev2a", "rev2b"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev2a", "rev2b"])); |
| 847 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev3", "rev2b"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev3", "rev2b"])); |
| 848 | } |
| 849 | |
| 850 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 851 | fn test_heads_criss_cross_fixturerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_heads_criss_cross_fixture().() { |
| 852 | let mut g = criss_crossrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/criss_cross().(); |
| 853 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev2a", "rev1"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev2a"])); |
| 854 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev2b", "rev1"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev2b"])); |
| 855 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev3a", "rev1"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev3a"])); |
| 856 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev3b", "rev1"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev3b"])); |
| 857 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev2a", "rev2b"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev2a", "rev2b"])); |
| 858 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev3a", "rev2a"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev3a"])); |
| 859 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev3a", "rev2b"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev3a"])); |
| 860 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev3a", "rev2a", "rev2b"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev3a"])); |
| 861 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev3b", "rev2a"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev3b"])); |
| 862 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev3b", "rev2b"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev3b"])); |
| 863 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev3b", "rev2a", "rev2b"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev3b"])); |
| 864 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev3a", "rev3b"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev3a", "rev3b"])); |
| 865 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 866 | g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev3a", "rev3b", "rev2a", "rev2b"]), |
| 867 | setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev3a", "rev3b"]) |
| 868 | ); |
| 869 | } |
| 870 | |
| 871 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 872 | fn test_heads_history_shortcut_fixturerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_heads_history_shortcut_fixture().() { |
| 873 | let mut g = history_shortcutrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/history_shortcut().(); |
| 874 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 875 | g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev2a", "rev2b", "rev2c"]), |
| 876 | setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev2a", "rev2b", "rev2c"]) |
| 877 | ); |
| 878 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev3a", "rev3b"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev3a", "rev3b"])); |
| 879 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 880 | g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev2a", "rev3a", "rev3b"]), |
| 881 | setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev3a", "rev3b"]) |
| 882 | ); |
| 883 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev2a", "rev3b"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev2a", "rev3b"])); |
| 884 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rev2c", "rev3a"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["rev2c", "rev3a"])); |
| 885 | } |
| 886 | |
| 887 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 888 | fn test_heads_alt_mergerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_heads_alt_merge().() { |
| 889 | let mut g = alt_mergerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/alt_merge().(); |
| 890 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a", "c"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["c"])); |
| 891 | } |
| 892 | |
| 893 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 894 | fn test_heads_with_ghost_fixturerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_heads_with_ghost_fixture().() { |
| 895 | let mut g = with_ghostrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/with_ghost().(); |
| 896 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["e", "g"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["e", "g"])); |
| 897 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a", "c"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["a", "c"])); |
| 898 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a", "g"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["a", "g"])); |
| 899 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["f", "g"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["f", "g"])); |
| 900 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["c", "g"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["c"])); |
| 901 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["c", "b", "d", "g"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["c"])); |
| 902 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a", "c", "e", "g"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["a", "c"])); |
| 903 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a", "c", "f"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["a", "c"])); |
| 904 | } |
| 905 | |
| 906 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 907 | fn test_filling_in_ghosts_resets_head_cacherust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_filling_in_ghosts_resets_head_cache().() { |
| 908 | let mut g = with_ghostrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/with_ghost().(); |
| 909 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["e", "g"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["e", "g"])); |
| 910 | // Fill in the ghost so that `g` descends from `e`; the heads |
| 911 | // cache must be invalidated, otherwise the second query would |
| 912 | // return the stale result. |
| 913 | g.add_noderust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]add_node().("g", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["e"]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 914 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(g.headsrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]heads().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["e", "g"]), setrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/set().(["g"])); |
| 915 | } |
| 916 | |
| 917 | /// Helper: assert that `topo_sort` yields a valid topological order |
| 918 | /// for the given parent map. |
| 919 | fn assert_topo_sort_orderrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/assert_topo_sort_order().(edges: &[(&'static str, &[&'static str])]) { |
| 920 | let pm: FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#<&'static str, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&'static str>> = |
| 921 | 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().(); |
| 922 | let g = KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#::newrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]new().(pm.clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][Clone]clone().(), true); |
| 923 | let result = g.topo_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]topo_sort().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 924 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), pm.lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().()); |
| 925 | let idx: FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#<&str, usize> = result.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(i, k)| (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().k, i)).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 926 | for (node, parents) in &pm { |
| 927 | for parent in parents { |
| 928 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pm.contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(parent) { |
| 929 | continue; // ghost |
| 930 | } |
| 931 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 932 | idx[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().node]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index(). >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). idx[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().parent]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., |
| 933 | "parent {parent} must come before child {node}: {:?}", |
| 934 | result |
| 935 | ); |
| 936 | } |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 941 | fn test_topo_sort_emptyrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_topo_sort_empty().() { |
| 942 | assert_topo_sort_orderrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/assert_topo_sort_order().(&[]); |
| 943 | } |
| 944 | |
| 945 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 946 | fn test_topo_sort_easyrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_topo_sort_easy().() { |
| 947 | assert_topo_sort_orderrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/assert_topo_sort_order().(&[("a", &[])]); |
| 948 | } |
| 949 | |
| 950 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 951 | fn test_topo_sort_cycle_simplerust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_topo_sort_cycle_simple().() { |
| 952 | let pm = [("a", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["b"]), ("b", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a"])]; |
| 953 | let g = KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#::newrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]new().(pm, true); |
| 954 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(g.topo_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]topo_sort().(), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo vcs-graph 3.6.0 Error#::Cyclerust-analyzer cargo vcs-graph 3.6.0 Error#Cycle#(_)))); |
| 955 | } |
| 956 | |
| 957 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 958 | fn test_topo_sort_cycle_longrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_topo_sort_cycle_long().() { |
| 959 | let pm = [("a", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["b"]), ("b", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["c"]), ("c", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a"])]; |
| 960 | let g = KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#::newrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]new().(pm, true); |
| 961 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(g.topo_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]topo_sort().(), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo vcs-graph 3.6.0 Error#::Cyclerust-analyzer cargo vcs-graph 3.6.0 Error#Cycle#(_)))); |
| 962 | } |
| 963 | |
| 964 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 965 | fn test_topo_sort_cycle_with_tailrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_topo_sort_cycle_with_tail().() { |
| 966 | let pm = [ |
| 967 | ("a", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["b"]), |
| 968 | ("b", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["c"]), |
| 969 | ("c", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["d", "e"]), |
| 970 | ("d", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a"]), |
| 971 | ("e", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), |
| 972 | ]; |
| 973 | let g = KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#::newrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]new().(pm, true); |
| 974 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(g.topo_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]topo_sort().(), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo vcs-graph 3.6.0 Error#::Cyclerust-analyzer cargo vcs-graph 3.6.0 Error#Cycle#(_)))); |
| 975 | } |
| 976 | |
| 977 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 978 | fn test_topo_sort_nontrivialrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_topo_sort_nontrivial().() { |
| 979 | assert_topo_sort_orderrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/assert_topo_sort_order().(&[ |
| 980 | ("a", &["d"]), |
| 981 | ("b", &["e"]), |
| 982 | ("c", &["b", "e"]), |
| 983 | ("d", &[]), |
| 984 | ("e", &["a", "d"]), |
| 985 | ]); |
| 986 | } |
| 987 | |
| 988 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 989 | fn test_topo_sort_partialrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_topo_sort_partial().() { |
| 990 | assert_topo_sort_orderrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/assert_topo_sort_order().(&[ |
| 991 | ("a", &[]), |
| 992 | ("b", &["a"]), |
| 993 | ("c", &["a"]), |
| 994 | ("d", &["a"]), |
| 995 | ("e", &["b", "c", "d"]), |
| 996 | ("f", &["b", "c"]), |
| 997 | ("g", &["b", "c"]), |
| 998 | ("h", &["c", "d"]), |
| 999 | ("i", &["a", "b", "e", "f", "g"]), |
| 1000 | ]); |
| 1001 | } |
| 1002 | |
| 1003 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1004 | fn test_topo_sort_ghost_parentrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_topo_sort_ghost_parent().() { |
| 1005 | // `b` is a ghost parent of `a` (not in the map). `c`'s parent |
| 1006 | // `b` references the same. Output order must place `a` after `b` |
| 1007 | // and `b` after `c` (treating `b` as a tail since it has no |
| 1008 | // known parents in the output graph). |
| 1009 | assert_topo_sort_orderrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/assert_topo_sort_order().(&[("a", &["b"]), ("b", &["c"])]); |
| 1010 | } |
| 1011 | |
| 1012 | /// Merge-sort assertion helper: compares against Python-shaped |
| 1013 | /// (key, merge_depth, revno, end_of_merge) tuples. |
| 1014 | fn assert_merge_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/assert_merge_sort().( |
| 1015 | edges: &[(&'static str, &[&'static str])], |
| 1016 | tip: &'static str, |
| 1017 | expected: &[(&'static str, usize, &[usize], bool)], |
| 1018 | ) { |
| 1019 | let pm: FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#<&'static str, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&'static str>> = |
| 1020 | 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().(); |
| 1021 | let g = KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#::newrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]new().(pm, true); |
| 1022 | let result = g.merge_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]merge_sort().(tip).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1023 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1024 | result.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), |
| 1025 | expected.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), |
| 1026 | "length mismatch: got {:?}", |
| 1027 | result |
| 1028 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 1029 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|n| (n.keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#key., n.merge_depthrust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#merge_depth., n.revnorust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#revno..clonerust-analyzer cargo vcs-graph 3.6.0 impl#[RevnoVec][Clone]clone().(), n.end_of_mergerust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#end_of_merge.)) |
| 1030 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>() |
| 1031 | ); |
| 1032 | for (i, ((got_key, got_depth, got_eom), (exp_key, exp_depth, exp_revno, exp_eom))) in result |
| 1033 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 1034 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|n| (n.keyrust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#key., n.merge_depthrust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#merge_depth., n.end_of_mergerust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#end_of_merge.)) |
| 1035 | .ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(expected.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()) |
| 1036 | .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() |
| 1037 | { |
| 1038 | let got_revno: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<usize> = result[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..revnorust-analyzer cargo vcs-graph 3.6.0 known_graph/MergeSortNode#revno..clonerust-analyzer cargo vcs-graph 3.6.0 impl#[RevnoVec][Clone]clone().().into_iterrust-analyzer cargo vcs-graph 3.6.0 impl#[RevnoVec][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 1039 | let exp_revno_v: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<usize> = exp_revno.to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().(); |
| 1040 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1041 | (got_key, got_depth, got_revno.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().(), got_eom), |
| 1042 | (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().exp_key, *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().exp_depth, exp_revno_v.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().(), *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().exp_eom), |
| 1043 | "row {i} mismatch" |
| 1044 | ); |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1049 | fn test_merge_sort_one_revisionrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_merge_sort_one_revision().() { |
| 1050 | assert_merge_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/assert_merge_sort().(&[("id", &[])], "id", &[("id", 0, &[1], true)]); |
| 1051 | } |
| 1052 | |
| 1053 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1054 | fn test_merge_sort_sequence_no_mergesrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_merge_sort_sequence_no_merges().() { |
| 1055 | assert_merge_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/assert_merge_sort().( |
| 1056 | &[("A", &[]), ("B", &["A"]), ("C", &["B"])], |
| 1057 | "C", |
| 1058 | &[ |
| 1059 | ("C", 0, &[3], false), |
| 1060 | ("B", 0, &[2], false), |
| 1061 | ("A", 0, &[1], true), |
| 1062 | ], |
| 1063 | ); |
| 1064 | } |
| 1065 | |
| 1066 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1067 | fn test_merge_sort_sequence_with_mergesrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_merge_sort_sequence_with_merges().() { |
| 1068 | assert_merge_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/assert_merge_sort().( |
| 1069 | &[("A", &[]), ("B", &["A"]), ("C", &["A", "B"])], |
| 1070 | "C", |
| 1071 | &[ |
| 1072 | ("C", 0, &[2], false), |
| 1073 | ("B", 1, &[1, 1, 1], true), |
| 1074 | ("A", 0, &[1], true), |
| 1075 | ], |
| 1076 | ); |
| 1077 | } |
| 1078 | |
| 1079 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1080 | fn test_merge_sort_merge_depth_with_nested_mergesrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_merge_sort_merge_depth_with_nested_merges().() { |
| 1081 | assert_merge_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/assert_merge_sort().( |
| 1082 | &[ |
| 1083 | ("A", &["D", "B"]), |
| 1084 | ("B", &["C", "F"]), |
| 1085 | ("C", &["H"]), |
| 1086 | ("D", &["H", "E"]), |
| 1087 | ("E", &["G", "F"]), |
| 1088 | ("F", &["G"]), |
| 1089 | ("G", &["H"]), |
| 1090 | ("H", &[]), |
| 1091 | ], |
| 1092 | "A", |
| 1093 | &[ |
| 1094 | ("A", 0, &[3], false), |
| 1095 | ("B", 1, &[1, 3, 2], false), |
| 1096 | ("C", 1, &[1, 3, 1], true), |
| 1097 | ("D", 0, &[2], false), |
| 1098 | ("E", 1, &[1, 1, 2], false), |
| 1099 | ("F", 2, &[1, 2, 1], true), |
| 1100 | ("G", 1, &[1, 1, 1], true), |
| 1101 | ("H", 0, &[1], true), |
| 1102 | ], |
| 1103 | ); |
| 1104 | } |
| 1105 | |
| 1106 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1107 | fn test_merge_sort_end_of_merge_not_lastrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_merge_sort_end_of_merge_not_last().() { |
| 1108 | assert_merge_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/assert_merge_sort().( |
| 1109 | &[("A", &["B"]), ("B", &[])], |
| 1110 | "A", |
| 1111 | &[("A", 0, &[2], false), ("B", 0, &[1], true)], |
| 1112 | ); |
| 1113 | } |
| 1114 | |
| 1115 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1116 | fn test_merge_sort_parallel_rootsrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_merge_sort_parallel_roots().() { |
| 1117 | assert_merge_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/assert_merge_sort().( |
| 1118 | &[("A", &[]), ("B", &[]), ("C", &["A", "B"])], |
| 1119 | "C", |
| 1120 | &[ |
| 1121 | ("C", 0, &[2], false), |
| 1122 | ("B", 1, &[0, 1, 1], true), |
| 1123 | ("A", 0, &[1], true), |
| 1124 | ], |
| 1125 | ); |
| 1126 | } |
| 1127 | |
| 1128 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1129 | fn test_merge_sort_cycle_errorsrust-analyzer cargo vcs-graph 3.6.0 known_graph/tests/test_merge_sort_cycle_errors().() { |
| 1130 | // E <- D <- C <- B, B <- D creates a cycle B-C-D-B |
| 1131 | let pm = [ |
| 1132 | ("A", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![] as Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&'static str>), |
| 1133 | ("B", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["D"]), |
| 1134 | ("C", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["B"]), |
| 1135 | ("D", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["C"]), |
| 1136 | ("E", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["D"]), |
| 1137 | ]; |
| 1138 | let g = KnownGraphrust-analyzer cargo vcs-graph 3.6.0 known_graph/KnownGraph#::newrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]new().(pm, true); |
| 1139 | let r = g.merge_sortrust-analyzer cargo vcs-graph 3.6.0 known_graph/impl#[`KnownGraph<K>`]merge_sort().("E"); |
| 1140 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(r, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo vcs-graph 3.6.0 Error#::Cyclerust-analyzer cargo vcs-graph 3.6.0 Error#Cycle#(_)))); |
| 1141 | } |
| 1142 | } |