orx_concurrent_iter/implementations/jagged_arrays/
index.rs1use super::AsRawSlice;
2use core::cmp::Ordering;
3
4#[derive(Default, PartialEq, Debug, Clone)]
6pub struct JaggedIndex {
7 pub f: usize,
9 pub i: usize,
11}
12
13impl From<(usize, usize)> for JaggedIndex {
14 fn from((f, i): (usize, usize)) -> Self {
15 Self::new(f, i)
16 }
17}
18
19impl From<[usize; 2]> for JaggedIndex {
20 fn from([f, i]: [usize; 2]) -> Self {
21 Self::new(f, i)
22 }
23}
24
25impl JaggedIndex {
26 pub fn new(f: usize, i: usize) -> Self {
31 Self { f, i }
32 }
33
34 pub(super) fn is_in_exc_bounds_of<T>(&self, slices: &[impl AsRawSlice<T>]) -> bool {
35 match slices.is_empty() {
36 true => self.f == 0 && self.i == 0,
37 false => self.f < slices.len() && self.i <= slices[self.f].length(),
38 }
39 }
40}
41
42impl PartialOrd for JaggedIndex {
43 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
44 match self.f.partial_cmp(&other.f) {
45 Some(Ordering::Equal) => self.i.partial_cmp(&other.i),
46 ord => ord,
47 }
48 }
49}