1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
pub fn get_both_ranges<T>(
vector: &mut Vec<T>,
i: usize,
j: usize,
len: usize,
) -> (&mut [T], &mut [T]) {
debug_assert_ne!(i, j);
debug_assert!(i + len <= vector.len());
debug_assert!(j + len <= vector.len());
if i < j {
debug_assert!(i + len <= j);
let (first, last) = vector.split_at_mut(j);
return (&mut first[i..(i + len)], &mut last[0..len]);
} else {
debug_assert!(j + len <= i);
let (first, last) = vector.split_at_mut(i);
return (&mut last[0..len], &mut first[j..(j + len)]);
}
}
pub fn get_both_indices<T>(vector: &mut Vec<T>, i: usize, j: usize) -> (&mut T, &mut T) {
debug_assert_ne!(i, j);
debug_assert!(i < vector.len());
debug_assert!(j < vector.len());
if i < j {
let (first, last) = vector.split_at_mut(j);
return (&mut first[i], &mut last[0]);
} else {
let (first, last) = vector.split_at_mut(i);
return (&mut last[0], &mut first[j]);
}
}