Debian Codegraph @

src/dense.rs

raw symbols SCIP
1 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::{collectionsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#};
2 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#, RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#};
3
4 use superrust-analyzer cargo rangemap 1.7.1 crate/::{RangeInclusiveMaprust-analyzer cargo rangemap 1.7.1 inclusive_map/RangeInclusiveMap#, RangeMaprust-analyzer cargo rangemap 1.7.1 map/RangeMap#};
5
6 // A simple but infeasibly slow and memory-hungry
7 // version of `RangeInclusiveMap` for testing.
8 //
9 // Only understands `u32` keys, so that we don't
10 // have to be generic over `step`. This is just for
11 // testing, so it's fine.
12 //
13 // Note that even though this mirrors the semantics
14 // of `RangeInclusiveMap`, it can also be used to
15 // test `RangeMap` just fine.
16 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
17 pub struct DenseU32RangeMaprust-analyzer cargo rangemap 1.7.1 dense/DenseU32RangeMap#<V> {
18 // Inner B-Tree map. Stores values and their keys
19 // directly rather than as ranges.
20 btmrust-analyzer cargo rangemap 1.7.1 dense/DenseU32RangeMap#btm.: BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<u32, V>,
21 }
22
23 impl<V> DenseU32RangeMaprust-analyzer cargo rangemap 1.7.1 dense/DenseU32RangeMap#<V>
24 where
25 V: PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#,
26 {
27 pub fn newrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`]new().() -> DenseU32RangeMaprust-analyzer cargo rangemap 1.7.1 dense/DenseU32RangeMap#<V> {
28 DenseU32RangeMaprust-analyzer cargo rangemap 1.7.1 dense/DenseU32RangeMap# {
29 btmrust-analyzer cargo rangemap 1.7.1 dense/DenseU32RangeMap#btm.: BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().(),
30 }
31 }
32
33 pub fn insertrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`]insert().(&mut self, range: RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#<u32>, value: V) {
34 for k in range {
35 self.btmrust-analyzer cargo rangemap 1.7.1 dense/DenseU32RangeMap#btm..insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(k, value.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().());
36 }
37 }
38
39 pub fn iterrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`]iter().(&self) -> Iterrust-analyzer cargo rangemap 1.7.1 dense/Iter#<'_, V> {
40 Iterrust-analyzer cargo rangemap 1.7.1 dense/Iter# {
41 innerrust-analyzer cargo rangemap 1.7.1 dense/Iter#inner.: self.btmrust-analyzer cargo rangemap 1.7.1 dense/DenseU32RangeMap#btm..iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]iter().(),
42 currentrust-analyzer cargo rangemap 1.7.1 dense/Iter#current.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
43 }
44 }
45
46 pub fn end_exclusive_iterrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`]end_exclusive_iter().(&self) -> EndExclusiveIterrust-analyzer cargo rangemap 1.7.1 dense/EndExclusiveIter#<'_, V> {
47 EndExclusiveIterrust-analyzer cargo rangemap 1.7.1 dense/EndExclusiveIter# { innerrust-analyzer cargo rangemap 1.7.1 dense/EndExclusiveIter#inner.: self.iterrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`]iter().() }
48 }
49
50 // Vecs are easier to use for assertions than iterators,
51 // because you don't have to consume them to compare them.
52 pub fn to_vecrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`]to_vec().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#<u32>, V)> {
53 self.iterrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`]iter().()
54 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(range, value)| (range, value.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()))
55 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
56 }
57
58 pub fn to_end_exclusive_vecrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`]to_end_exclusive_vec().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<u32>, V)> {
59 self.end_exclusive_iterrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`]end_exclusive_iter().()
60 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(range, value)| (range, value.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()))
61 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
62 }
63 }
64
65 impl<V> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<RangeMaprust-analyzer cargo rangemap 1.7.1 map/RangeMap#<u32, V>> for DenseU32RangeMaprust-analyzer cargo rangemap 1.7.1 dense/DenseU32RangeMap#<V>
66 where
67 V: PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#,
68 {
69 fn fromrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`][`From<RangeMap<u32, V>>`]from().(range_map: RangeMaprust-analyzer cargo rangemap 1.7.1 map/RangeMap#<u32, V>) -> Selfrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`][`From<RangeMap<u32, V>>`] {
70 let mut dense = Selfrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`][`From<RangeMap<u32, V>>`]::newrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`]new().();
71 for (range, value) in range_map.iterrust-analyzer cargo rangemap 1.7.1 map/impl#[`RangeMap<K, V>`]iter().() {
72 // Convert to inclusive end.
73 // (This is only valid because u32 has
74 // the "successor function".)
75 //
76 // NOTE: Clippy's `range_minus_one` lint is a bit overzealous here,
77 // because we _can't_ pass an open-ended range to `insert`.
78 #[allow(clippy::range_minus_one)]
79 dense.insertrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`]insert().(range.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start...=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#(range.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().1), value.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().());
80 }
81 dense
82 }
83 }
84
85 impl<V> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<RangeInclusiveMaprust-analyzer cargo rangemap 1.7.1 inclusive_map/RangeInclusiveMap#<u32, V>> for DenseU32RangeMaprust-analyzer cargo rangemap 1.7.1 dense/DenseU32RangeMap#<V>
86 where
87 V: PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#,
88 {
89 fn fromrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`][`From<RangeInclusiveMap<u32, V>>`]from().(range_inclusive_map: RangeInclusiveMaprust-analyzer cargo rangemap 1.7.1 inclusive_map/RangeInclusiveMap#<u32, V, u32>) -> Selfrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`][`From<RangeInclusiveMap<u32, V>>`] {
90 let mut dense = Selfrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`][`From<RangeInclusiveMap<u32, V>>`]::newrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`]new().();
91 for (range, value) in range_inclusive_map.iterrust-analyzer cargo rangemap 1.7.1 inclusive_map/impl#[`RangeInclusiveMap<K, V, StepFnsT>`]iter().() {
92 dense.insertrust-analyzer cargo rangemap 1.7.1 dense/impl#[`DenseU32RangeMap<V>`]insert().(range.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`][Clone]clone().(), value.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().());
93 }
94 dense
95 }
96 }
97
98 pub struct Iterrust-analyzer cargo rangemap 1.7.1 dense/Iter#<'a, V> {
99 innerrust-analyzer cargo rangemap 1.7.1 dense/Iter#inner.: allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::collectionsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/::btree_maprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree_map/::Iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/Iter#<'a, u32, V>,
100 // Current range being built for output.
101 // We modify it as we iterate through the underlying
102 // dense map.
103 currentrust-analyzer cargo rangemap 1.7.1 dense/Iter#current.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#<u32>, &'a V)>,
104 }
105
106 // Coalesce items from the underlying dense map as we go.
107 impl<'a, V> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Iterrust-analyzer cargo rangemap 1.7.1 dense/Iter#<'a, V>
108 where
109 V: 'a + PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#,
110 {
111 type Itemrust-analyzer cargo rangemap 1.7.1 dense/impl#[`Iter<'a, V>`][Iterator]Item# = (RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#<u32>, &'a V);
112
113 fn nextrust-analyzer cargo rangemap 1.7.1 dense/impl#[`Iter<'a, V>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#<u32>, &'a V)> {
114 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(next_dense) = self.innerrust-analyzer cargo rangemap 1.7.1 dense/Iter#inner..nextrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`Iter<'a, K, V>`][Iterator]next().() {
115 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(current) = &mut self.currentrust-analyzer cargo rangemap 1.7.1 dense/Iter#current. {
116 // We're already building a range. Can we extend it?
117 if current.0.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]end().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&u32`][`Add<u32>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&u32`][`Add<u32>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&u32`][`Add<u32>`]add().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().next_dense.0 && *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().current.1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().next_dense.1 {
118 // This immediately follows the last item and the value is the same;
119 // we can extend it.
120 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().current = (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().current.0.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]start().()..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().next_dense.0, current.1);
121 // Recurse until we find a way to flush it.
122 self.nextrust-analyzer cargo rangemap 1.7.1 dense/impl#[`Iter<'a, V>`][Iterator]next().()
123 } else {
124 // There's a gap or the value differs; flush the one we were working on and start a new one.
125 let item_to_yield = current.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().();
126 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().current = (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().next_dense.0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().next_dense.0, next_dense.1);
127 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(item_to_yield)
128 }
129 } else {
130 // We're not building a range yet; start a new one.
131 self.currentrust-analyzer cargo rangemap 1.7.1 dense/Iter#current. = 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 ops/deref/impl#[`&T`][Deref]deref().next_dense.0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().next_dense.0, next_dense.1));
132 // Recurse until we find a way to flush it.
133 self.nextrust-analyzer cargo rangemap 1.7.1 dense/impl#[`Iter<'a, V>`][Iterator]next().()
134 }
135 } else {
136 // We reached the end of the underlying dense map.
137 // Flush the item we were building, if any.
138 self.currentrust-analyzer cargo rangemap 1.7.1 dense/Iter#current..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().()
139 }
140 }
141 }
142
143 pub struct EndExclusiveIterrust-analyzer cargo rangemap 1.7.1 dense/EndExclusiveIter#<'a, V> {
144 innerrust-analyzer cargo rangemap 1.7.1 dense/EndExclusiveIter#inner.: Iterrust-analyzer cargo rangemap 1.7.1 dense/Iter#<'a, V>,
145 }
146
147 impl<'a, V> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for EndExclusiveIterrust-analyzer cargo rangemap 1.7.1 dense/EndExclusiveIter#<'a, V>
148 where
149 V: 'a + PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#,
150 {
151 type Itemrust-analyzer cargo rangemap 1.7.1 dense/impl#[`EndExclusiveIter<'a, V>`][Iterator]Item# = (Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<u32>, &'a V);
152
153 fn nextrust-analyzer cargo rangemap 1.7.1 dense/impl#[`EndExclusiveIter<'a, V>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<u32>, &'a V)> {
154 self.innerrust-analyzer cargo rangemap 1.7.1 dense/EndExclusiveIter#inner.
155 .nextrust-analyzer cargo rangemap 1.7.1 dense/impl#[`Iter<'a, V>`][Iterator]next().()
156 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(range, value)| ((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().range.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]start().())..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().range.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]end().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().1), value))
157 }
158 }