orx_concurrent_iter/implementations/jagged_arrays/indexer.rs
1use super::{Slices, as_raw_slice::AsRawSlice, index::JaggedIndex};
2use orx_pseudo_default::PseudoDefault;
3
4/// An indexer for the raw jagged arrays.
5pub trait JaggedIndexer: Clone + PseudoDefault + Send + Sync {
6 /// Returns the jagged index of the element `flat_index`-th position if the raw jagged array
7 /// defined by the `arrays` collection would have been flattened.
8 ///
9 /// Unlike `jagged_index`, this method expects `flat_index <= arrays.iter().map(|x| x.len()).sum()`,
10 /// and omits bounds checks.
11 ///
12 /// # SAFETY
13 ///
14 /// Calling this method with an index greater than the total length of the jagged array might
15 /// possibly lead to undefined behavior.
16 unsafe fn jagged_index_unchecked<'a, T: 'a>(
17 &self,
18 arrays: &impl Slices<'a, T>,
19 flat_index: usize,
20 ) -> JaggedIndex;
21
22 /// Returns the jagged index of the element `flat_index`-th position if the raw jagged array
23 /// defined by the `arrays` collection would have been flattened.
24 ///
25 /// Unlike `jagged_index`, this method expects `flat_index <= arrays.iter().map(|x| x.len()).sum()`,
26 /// and omits bounds checks.
27 ///
28 /// # SAFETY
29 ///
30 /// Calling this method with an index greater than the total length of the jagged array might
31 /// possibly lead to undefined behavior.
32 unsafe fn jagged_index_unchecked_from_slice<'a, T: 'a>(
33 &self,
34 arrays: &[impl AsRawSlice<T>],
35 flat_index: usize,
36 ) -> JaggedIndex;
37}