| 1 | //! This is code responsible for possibly-chunked data. |
| 2 | |
| 3 | #[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:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 4 | struct DataChunkrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#<T> { |
| 5 | /// The start offset of this chunk, should correspond to the time vector |
| 6 | /// indices. If that updates, this MUST also update. |
| 7 | start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset.: usize, |
| 8 | |
| 9 | /// The actual value data! |
| 10 | datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<T>, |
| 11 | } |
| 12 | |
| 13 | impl<T> DataChunkrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#<T> { |
| 14 | fn pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`DataChunk<T>`]push().(&mut self, item: T) { |
| 15 | self.datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(item) |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | /// An iterator created from a [`ChunkedData`]. |
| 20 | pub struct ChunkedDataIterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#<I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#> { |
| 21 | iterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#iter.: I, |
| 22 | sizerust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#size.: usize, // TODO: We can probably store this as a `OnceCell` instead to avoid computing it if we don't need it. |
| 23 | } |
| 24 | |
| 25 | impl<T, I: 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# = T>> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for ChunkedDataIterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#<I> { |
| 26 | type Itemrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedDataIter<I>`][Iterator]Item# = T; |
| 27 | |
| 28 | fn nextrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedDataIter<I>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedDataIter<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 29 | self.iterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() |
| 30 | } |
| 31 | |
| 32 | fn size_hintrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedDataIter<I>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 33 | (self.sizerust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#size., Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.sizerust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#size.)) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | impl<T, I: 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# = T>> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for ChunkedDataIterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#<I> {} |
| 38 | |
| 39 | impl<T, I: 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# = T> + DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator#> DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator# for ChunkedDataIterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#<I> { |
| 40 | fn next_backrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedDataIter<I>`][DoubleEndedIterator]next_back().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedDataIter<I>`][DoubleEndedIterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 41 | self.iterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#iter..next_backrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator#next_back().() |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | /// A struct representing data that may potentially have breaks. |
| 46 | /// If you expect that you may want to store time values but _not_ |
| 47 | /// data values, use this to avoid storing blanks. |
| 48 | #[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:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 49 | pub struct ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#<D> { |
| 50 | next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index.: usize, |
| 51 | is_activerust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#is_active.: bool, |
| 52 | chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<DataChunkrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#<D>>, |
| 53 | } |
| 54 | |
| 55 | impl<D> ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#<D> { |
| 56 | /// Returns an iterator of items alongside the associated indices for each item. |
| 57 | pub fn iter_with_indexrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]iter_with_index().(&self) -> ChunkedDataIterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#<impl DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (usize, &D)>> { |
| 58 | let size = self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..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().(|dc| dc.datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()).sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().(); |
| 59 | let iter = self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|dc| { |
| 60 | let start = dc.start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset.; |
| 61 | |
| 62 | dc.datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data. |
| 63 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 64 | .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() |
| 65 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(move |(offset, datum)| (start 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().offset, datum)) |
| 66 | }); |
| 67 | |
| 68 | ChunkedDataIterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter# { iterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#iter., sizerust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#size. } |
| 69 | } |
| 70 | |
| 71 | /// Returns an iterator of items. |
| 72 | pub fn iterrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]iter().(&self) -> ChunkedDataIterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#<impl DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &D>> { |
| 73 | let size = self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..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().(|dc| dc.datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()).sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().(); |
| 74 | let iter = self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|dc| dc.datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()); |
| 75 | |
| 76 | ChunkedDataIterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter# { iterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#iter., sizerust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#size. } |
| 77 | } |
| 78 | |
| 79 | /// Returns an iterator of owned items. This consumes the [`ChunkedData`]. |
| 80 | /// |
| 81 | /// Note this is currently not just `into_iter` due to how it's implemented, this is subject to change. |
| 82 | pub fn into_owned_iterrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]into_owned_iter().(self) -> ChunkedDataIterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#<impl DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = D>> { |
| 83 | let size = self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..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().(|dc| dc.datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()).sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().(); |
| 84 | let iter = self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|dc| dc.datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data..into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()); |
| 85 | |
| 86 | ChunkedDataIterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter# { iterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#iter., sizerust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#size. } |
| 87 | } |
| 88 | |
| 89 | /// Given a slice that serves as the "base" yielding items `T`, return an iterator of `(T, D)`, where each `D` from |
| 90 | /// the [`ChunkedData`] has its index associated with that of `base_slice`. |
| 91 | /// |
| 92 | /// This is meant to be used alongside a slice of time values. |
| 93 | /// |
| 94 | /// Note this will return the minimum of the number of elements in either the base slice or the [`ChunkedData`]. |
| 95 | pub fn iter_along_baserust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]iter_along_base().<'a, T>( |
| 96 | &'a self, base_slice: &'a [T], |
| 97 | ) -> ChunkedDataIterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#<impl DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (&'a T, &'a D)>> { |
| 98 | let size = if base_slice.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().self.lengthrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]length().() { |
| 99 | // Happy path. We return at most the number of stored elements! |
| 100 | self.num_elementsrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]num_elements().() |
| 101 | } else { |
| 102 | // Uh oh. We need a bit more logic around this step. |
| 103 | |
| 104 | let mut num_returned_elements = 0; |
| 105 | |
| 106 | for dc in self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 107 | let start = dc.start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset.; |
| 108 | let end = dc.start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset. 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().dc.datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 109 | |
| 110 | if base_slice.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().end { |
| 111 | num_returned_elements rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().dc.datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 112 | } else if base_slice.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]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().start { |
| 113 | break; |
| 114 | } else { |
| 115 | // It's somewhere in the middle. |
| 116 | num_returned_elements rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().base_slice.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().start; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | num_returned_elements |
| 121 | }; |
| 122 | |
| 123 | let iter = self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(move |dc| { |
| 124 | let start = dc.start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset.; |
| 125 | let to_take = base_slice.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().().saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(start); // Take at most all the values in the chunk, or up to the number of base element indices. |
| 126 | |
| 127 | dc.datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data. |
| 128 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 129 | .takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(to_take) |
| 130 | .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() |
| 131 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(move |(offset, datum)| { |
| 132 | let actual_index = start 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().offset; |
| 133 | let base = &base_slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().actual_index]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 134 | |
| 135 | (base, datum) |
| 136 | }) |
| 137 | }); |
| 138 | |
| 139 | ChunkedDataIterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter# { iterrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#iter., sizerust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedDataIter#size. } |
| 140 | } |
| 141 | |
| 142 | /// Return how many elements actually are stored in the [`ChunkedData`]. |
| 143 | pub fn num_elementsrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]num_elements().(&self) -> usize { |
| 144 | self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..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().(|dc| dc.datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()).sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().() |
| 145 | } |
| 146 | |
| 147 | /// Return the "length" of the [`ChunkedData`], _including_ skipped |
| 148 | /// elements. |
| 149 | pub fn lengthrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]length().(&self) -> usize { |
| 150 | self.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index. |
| 151 | } |
| 152 | |
| 153 | /// Push an element. |
| 154 | pub fn pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]push().(&mut self, item: D) { |
| 155 | if self.is_activerust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#is_active. { |
| 156 | let current_chunk = self |
| 157 | .chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks. |
| 158 | .last_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last_mut().() |
| 159 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("chunks must be initialized with at least a value if is_active is set"); |
| 160 | current_chunk.pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`DataChunk<T>`]push().(item); |
| 161 | } else { |
| 162 | // Start a new chunk. |
| 163 | self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(DataChunkrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk# { |
| 164 | start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset.: self.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index., |
| 165 | datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![item], |
| 166 | }); |
| 167 | self.is_activerust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#is_active. = true; |
| 168 | } |
| 169 | |
| 170 | self.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 171 | } |
| 172 | |
| 173 | /// Manually mark that a break is needed in the chunk. |
| 174 | pub fn insert_breakrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]insert_break().(&mut self) { |
| 175 | // "Seal" the latest chunk. |
| 176 | self.is_activerust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#is_active. = false; |
| 177 | } |
| 178 | |
| 179 | /// Push an element. If `item` is [`None`], then it will automatically |
| 180 | /// insert a break in the chunk if needed. |
| 181 | pub fn try_pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]try_push().(&mut self, item: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<D>) { |
| 182 | match item { |
| 183 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(item) => { |
| 184 | self.pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]push().(item); |
| 185 | } |
| 186 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 187 | self.insert_breakrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]insert_break().(); |
| 188 | self.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | /// Remove all elements up to (and including) `index`, including "skipped" |
| 194 | /// elements. This will result in the effective length becoming |
| 195 | /// `prev_length - index - 1`. |
| 196 | /// |
| 197 | /// If `index` goes past the number of elements, this function will return |
| 198 | /// an error containing the stored index in the [`ChunkedData`]. |
| 199 | pub fn prunerust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]prune().(&mut self, index: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), usize> { |
| 200 | if self.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index. 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().0 || self.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1 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().index || self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 201 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(self.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index.); |
| 202 | } |
| 203 | |
| 204 | self.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().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; |
| 205 | |
| 206 | let dc_index = match self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..binary_search_byrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]binary_search_by().(|c| c.start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset..cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][Ord]cmp().(&index)) { |
| 207 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(result) => result, |
| 208 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(result) => { |
| 209 | if result rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 210 | result rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1 |
| 211 | } else { |
| 212 | // Nothing to prune. We still need to change the offsets though. |
| 213 | for chunk in &mut self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks. { |
| 214 | chunk.start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().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; |
| 215 | } |
| 216 | |
| 217 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 218 | } |
| 219 | } |
| 220 | }; |
| 221 | |
| 222 | // SAFETY: This index must be valid since it was returned from the binary search. |
| 223 | let curr = unsafe { self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..get_unchecked_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked_mut().(dc_index) }; |
| 224 | let to_remove = index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().curr.start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset. 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; |
| 225 | |
| 226 | if to_remove rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().curr.datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() { |
| 227 | curr.datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data..drainrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]drain().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#to_remove); |
| 228 | curr.start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset. = 0; |
| 229 | |
| 230 | // Remove all previous chunks. |
| 231 | self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..drainrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]drain().(0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#dc_index); |
| 232 | |
| 233 | // Update offsets for all following chunks. |
| 234 | for chunk in self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(1) { |
| 235 | chunk.start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().to_remove; |
| 236 | } |
| 237 | } else { |
| 238 | // Drain this chunk too. |
| 239 | self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..drainrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]drain().(0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#dc_index); |
| 240 | |
| 241 | for chunk in &mut self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks. { |
| 242 | chunk.start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().to_remove; |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 247 | } |
| 248 | |
| 249 | /// Shrink the [`ChunkedData`] after. |
| 250 | pub fn shrink_to_fitrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]shrink_to_fit().(&mut self) { |
| 251 | for chunk in &mut self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks. { |
| 252 | chunk.datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data..shrink_to_fitrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]shrink_to_fit().(); |
| 253 | } |
| 254 | |
| 255 | self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..shrink_to_fitrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]shrink_to_fit().(); |
| 256 | } |
| 257 | |
| 258 | /// Convenience function to prune _and_ shrink the [`ChunkedData`] after. |
| 259 | pub fn prune_and_shrink_to_fitrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]prune_and_shrink_to_fit().(&mut self, index: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), usize> { |
| 260 | self.prunerust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]prune().(index)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 261 | self.shrink_to_fitrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]shrink_to_fit().(); |
| 262 | |
| 263 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 264 | } |
| 265 | |
| 266 | /// Try and return the first element. |
| 267 | pub fn firstrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]first().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&D> { |
| 268 | self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|chunk| chunk.datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data..firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().()) |
| 269 | } |
| 270 | |
| 271 | /// Try and return the last element. |
| 272 | pub fn lastrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]last().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&D> { |
| 273 | self.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|chunk| chunk.datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().()) |
| 274 | } |
| 275 | |
| 276 | /// Return whether there are zero elements left stored internally. |
| 277 | pub fn no_elementsrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]no_elements().(&self) -> bool { |
| 278 | self.num_elementsrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]num_elements().() 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().0 |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | #[cfg(test)] |
| 283 | mod testsrust-analyzer cargo timeless 0.1.0 data/chunked/tests/ { |
| 284 | use superrust-analyzer cargo timeless 0.1.0 data/chunked/::*; |
| 285 | |
| 286 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 287 | fn chunked_pushrust-analyzer cargo timeless 0.1.0 data/chunked/tests/chunked_push().() { |
| 288 | let mut data = ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#::defaultrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`][Default]default().(); |
| 289 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.no_elementsrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]no_elements().()); |
| 290 | |
| 291 | data.try_pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]try_push().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1)); |
| 292 | |
| 293 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().data.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 294 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.is_activerust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#is_active.); |
| 295 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data., vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1]); |
| 296 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index., 1); |
| 297 | |
| 298 | data.try_pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]try_push().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2)); |
| 299 | data.try_pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]try_push().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 300 | |
| 301 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().data.is_activerust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#is_active.); |
| 302 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 303 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data., vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1, 2]); |
| 304 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index., 3); |
| 305 | |
| 306 | data.try_pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]try_push().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 307 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().data.is_activerust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#is_active.); |
| 308 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index., 4); |
| 309 | |
| 310 | data.try_pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]try_push().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3)); |
| 311 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.is_activerust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#is_active.); |
| 312 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data., vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![3]); |
| 313 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index., 5); |
| 314 | |
| 315 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.lengthrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]length().(), 5); |
| 316 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.num_elementsrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]num_elements().(), 3); |
| 317 | } |
| 318 | |
| 319 | /// Ensure that if we push nothing at first, we don't incorrectly try and |
| 320 | /// seal nothing. |
| 321 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 322 | fn chunked_empty_initial_pushrust-analyzer cargo timeless 0.1.0 data/chunked/tests/chunked_empty_initial_push().() { |
| 323 | let mut data: ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#<u64> = ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#::defaultrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`][Default]default().(); |
| 324 | |
| 325 | data.try_pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]try_push().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 326 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().data.is_activerust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#is_active.); |
| 327 | |
| 328 | data.try_pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]try_push().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1)); |
| 329 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.is_activerust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#is_active.); |
| 330 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index., 2); |
| 331 | } |
| 332 | |
| 333 | const POPULATIONrust-analyzer cargo timeless 0.1.0 data/chunked/tests/POPULATION.: [Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u64>; 10] = [ |
| 334 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1), |
| 335 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2), |
| 336 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3), |
| 337 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 338 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 339 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 340 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(7), |
| 341 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(8), |
| 342 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(9), |
| 343 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(10), |
| 344 | ]; |
| 345 | |
| 346 | fn test_populaterust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_populate().(data: &mut ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#<u64>) { |
| 347 | for p in POPULATIONrust-analyzer cargo timeless 0.1.0 data/chunked/tests/POPULATION. { |
| 348 | data.try_pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]try_push().(p); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | /// Initialize data, prune, and insert. |
| 353 | #[track_caller] |
| 354 | fn test_pruningrust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_pruning().(to_prune_index: usize) { |
| 355 | // println!("Trying to prune up to index {to_prune_index}..."); |
| 356 | |
| 357 | let mut data = ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#::defaultrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`][Default]default().(); |
| 358 | test_populaterust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_populate().(&mut data); |
| 359 | |
| 360 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.prunerust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]prune().(to_prune_index).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 361 | |
| 362 | let removed = to_prune_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; |
| 363 | let result = data |
| 364 | .iter_with_indexrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]iter_with_index().() |
| 365 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(a, b)| (a, *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().b)) |
| 366 | .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#<_>>(); |
| 367 | |
| 368 | let expected = POPULATIONrust-analyzer cargo timeless 0.1.0 data/chunked/tests/POPULATION. |
| 369 | .into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`[T; N]`][IntoIterator]into_iter().() |
| 370 | .skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(removed) |
| 371 | .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() |
| 372 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|(a, b)| b.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|b| (a, b))) |
| 373 | .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#<_>>(); |
| 374 | |
| 375 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, expected); |
| 376 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index., POPULATIONrust-analyzer cargo timeless 0.1.0 data/chunked/tests/POPULATION..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). (to_prune_index +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 1)); |
| 377 | } |
| 378 | |
| 379 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 380 | fn chunked_prunerust-analyzer cargo timeless 0.1.0 data/chunked/tests/chunked_prune().() { |
| 381 | test_pruningrust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_pruning().(0); |
| 382 | test_pruningrust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_pruning().(1); |
| 383 | test_pruningrust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_pruning().(2); |
| 384 | test_pruningrust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_pruning().(3); |
| 385 | test_pruningrust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_pruning().(4); |
| 386 | test_pruningrust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_pruning().(5); |
| 387 | test_pruningrust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_pruning().(6); |
| 388 | test_pruningrust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_pruning().(7); |
| 389 | test_pruningrust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_pruning().(8); |
| 390 | test_pruningrust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_pruning().(9); |
| 391 | } |
| 392 | |
| 393 | /// Handle if we try and prune something empty. |
| 394 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 395 | fn chunked_prune_emptyrust-analyzer cargo timeless 0.1.0 data/chunked/tests/chunked_prune_empty().() { |
| 396 | let mut data: ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#<u64> = ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#::defaultrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`][Default]default().(); |
| 397 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.prunerust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]prune().(0).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 398 | } |
| 399 | |
| 400 | /// Handle if we try to clear an index past the index stored. |
| 401 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 402 | fn chunked_prune_past_indexrust-analyzer cargo timeless 0.1.0 data/chunked/tests/chunked_prune_past_index().() { |
| 403 | let mut data = ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#::defaultrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`][Default]default().(); |
| 404 | test_populaterust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_populate().(&mut data); |
| 405 | |
| 406 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.prunerust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]prune().(10).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 407 | } |
| 408 | |
| 409 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 410 | fn chunked_prune_without_currrust-analyzer cargo timeless 0.1.0 data/chunked/tests/chunked_prune_without_curr().() { |
| 411 | let mut data = ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#::defaultrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`][Default]default().(); |
| 412 | test_populaterust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_populate().(&mut data); |
| 413 | data.try_pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]try_push().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 414 | |
| 415 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.prunerust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]prune().(10).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 416 | } |
| 417 | |
| 418 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 419 | fn prune_zero_when_nonerust-analyzer cargo timeless 0.1.0 data/chunked/tests/prune_zero_when_none().() { |
| 420 | let mut data = ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#::defaultrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`][Default]default().(); |
| 421 | data.try_pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]try_push().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 422 | data.try_pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]try_push().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 423 | data.try_pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]try_push().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 424 | test_populaterust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_populate().(&mut data); |
| 425 | |
| 426 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.prunerust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]prune().(0).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 427 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset., 2); |
| 428 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset., 8); |
| 429 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index., POPULATIONrust-analyzer cargo timeless 0.1.0 data/chunked/tests/POPULATION..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 3 -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 1); |
| 430 | |
| 431 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.prunerust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]prune().(0).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 432 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset., 1); |
| 433 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset., 7); |
| 434 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index., POPULATIONrust-analyzer cargo timeless 0.1.0 data/chunked/tests/POPULATION..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 3 -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 2); |
| 435 | |
| 436 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.prunerust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]prune().(0).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 437 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset., 0); |
| 438 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset., 6); |
| 439 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index., POPULATIONrust-analyzer cargo timeless 0.1.0 data/chunked/tests/POPULATION..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 3 -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 3); |
| 440 | |
| 441 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.prunerust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]prune().(0).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 442 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset., 0); |
| 443 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..datarust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#data..as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().(), &[2, 3]); |
| 444 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.chunksrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#chunks.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..start_offsetrust-analyzer cargo timeless 0.1.0 data/chunked/DataChunk#start_offset., 5); |
| 445 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.next_indexrust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#next_index., POPULATIONrust-analyzer cargo timeless 0.1.0 data/chunked/tests/POPULATION..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 3 -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 4); |
| 446 | } |
| 447 | |
| 448 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 449 | fn first_lastrust-analyzer cargo timeless 0.1.0 data/chunked/tests/first_last().() { |
| 450 | let mut data = ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#::defaultrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`][Default]default().(); |
| 451 | test_populaterust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_populate().(&mut data); |
| 452 | |
| 453 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.firstrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]first().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&1)); |
| 454 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data.lastrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]last().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&10)); |
| 455 | } |
| 456 | |
| 457 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 458 | fn iterrust-analyzer cargo timeless 0.1.0 data/chunked/tests/iter().() { |
| 459 | let mut data = ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#::defaultrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`][Default]default().(); |
| 460 | test_populaterust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_populate().(&mut data); |
| 461 | |
| 462 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 463 | data.into_owned_iterrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]into_owned_iter().().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#<_>>(), |
| 464 | POPULATIONrust-analyzer cargo timeless 0.1.0 data/chunked/tests/POPULATION..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|v| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().v).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#<_>>(), |
| 465 | ); |
| 466 | } |
| 467 | |
| 468 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 469 | fn reverse_iterrust-analyzer cargo timeless 0.1.0 data/chunked/tests/reverse_iter().() { |
| 470 | let mut data = ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#::defaultrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`][Default]default().(); |
| 471 | test_populaterust-analyzer cargo timeless 0.1.0 data/chunked/tests/test_populate().(&mut data); |
| 472 | |
| 473 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 474 | data.into_owned_iterrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]into_owned_iter().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().().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#<_>>(), |
| 475 | POPULATIONrust-analyzer cargo timeless 0.1.0 data/chunked/tests/POPULATION. |
| 476 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 477 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|v| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().v) |
| 478 | .revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().() |
| 479 | .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#<_>>(), |
| 480 | ); |
| 481 | } |
| 482 | |
| 483 | #[track_caller] |
| 484 | fn base_slice_testrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_test().( |
| 485 | data: &ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#<u32>, base_slice: &[u32], expected: &[(u32, u32)], |
| 486 | base_slice_index: usize, expected_slice_index: usize, |
| 487 | ) { |
| 488 | let base_slice = &base_slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#base_slice_index]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 489 | |
| 490 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 491 | data.iter_along_baserust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]iter_along_base().(base_slice).lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#len().(), |
| 492 | expected_slice_index, |
| 493 | "the returned size of the iterator should match" |
| 494 | ); |
| 495 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 496 | data.iter_along_baserust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]iter_along_base().(base_slice) |
| 497 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(a, b)| (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().a, *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().b)) |
| 498 | .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#<_>>(), |
| 499 | expected[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0..expected_slice_index]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 500 | "the actual generated values should match" |
| 501 | ); |
| 502 | } |
| 503 | |
| 504 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 505 | fn base_slice_simplerust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_simple().() { |
| 506 | let mut data = ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#::defaultrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`][Default]default().(); |
| 507 | data.pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]push().(1); |
| 508 | data.pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]push().(2); |
| 509 | data.pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]push().(3); |
| 510 | |
| 511 | let base_slice = [1, 2, 3, 4, 5]; |
| 512 | let expected = [(1, 1), (2, 2), (3, 3)]; |
| 513 | |
| 514 | // Test with a larger base slice |
| 515 | base_slice_testrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_test().(&data, &base_slice, &expected, 5, 3); |
| 516 | |
| 517 | // Test with an exact base slice |
| 518 | base_slice_testrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_test().(&data, &base_slice, &expected, 3, 3); |
| 519 | |
| 520 | // Test with a smaller base slice |
| 521 | base_slice_testrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_test().(&data, &base_slice, &expected, 2, 2); |
| 522 | base_slice_testrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_test().(&data, &base_slice, &expected, 1, 1); |
| 523 | base_slice_testrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_test().(&data, &base_slice, &expected, 0, 0); |
| 524 | } |
| 525 | |
| 526 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 527 | fn base_slice_chunkedrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_chunked().() { |
| 528 | let mut data = ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#::defaultrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`][Default]default().(); |
| 529 | data.pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]push().(1); |
| 530 | data.pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]push().(2); |
| 531 | data.pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]push().(3); |
| 532 | data.try_pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]try_push().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 533 | data.try_pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]try_push().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 534 | data.try_pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]try_push().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 535 | data.pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]push().(7); |
| 536 | data.pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]push().(8); |
| 537 | data.pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]push().(9); |
| 538 | |
| 539 | let base_slice = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
| 540 | let expected = [(1, 1), (2, 2), (3, 3), (7, 7), (8, 8), (9, 9)]; |
| 541 | |
| 542 | // Test with a larger base slice |
| 543 | base_slice_testrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_test().(&data, &base_slice, &expected, 10, 6); |
| 544 | |
| 545 | // Test with an exact base slice |
| 546 | base_slice_testrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_test().(&data, &base_slice, &expected, 9, 6); |
| 547 | |
| 548 | // Test with a smaller base slice |
| 549 | base_slice_testrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_test().(&data, &base_slice, &expected, 8, 5); |
| 550 | base_slice_testrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_test().(&data, &base_slice, &expected, 7, 4); |
| 551 | base_slice_testrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_test().(&data, &base_slice, &expected, 6, 3); |
| 552 | base_slice_testrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_test().(&data, &base_slice, &expected, 5, 3); |
| 553 | base_slice_testrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_test().(&data, &base_slice, &expected, 4, 3); |
| 554 | base_slice_testrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_test().(&data, &base_slice, &expected, 3, 3); |
| 555 | base_slice_testrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_test().(&data, &base_slice, &expected, 2, 2); |
| 556 | base_slice_testrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_test().(&data, &base_slice, &expected, 1, 1); |
| 557 | base_slice_testrust-analyzer cargo timeless 0.1.0 data/chunked/tests/base_slice_test().(&data, &base_slice, &expected, 0, 0); |
| 558 | } |
| 559 | } |