competitive/tools/
slice.rs1#[codesnip::entry("GetDistinctMut")]
2pub trait GetDistinctMut<I> {
3 type Output;
4 fn get_distinct_mut(self, index: I) -> Self::Output;
5}
6#[codesnip::entry("GetDistinctMut")]
7impl<'a, T> GetDistinctMut<(usize, usize)> for &'a mut [T] {
8 type Output = (&'a mut T, &'a mut T);
9 fn get_distinct_mut(self, (i0, i1): (usize, usize)) -> Self::Output {
10 assert_ne!(i0, i1);
11 assert!(i0 < self.len());
12 assert!(i1 < self.len());
13 let ptr = self.as_mut_ptr();
14 unsafe { (&mut *ptr.add(i0), &mut *ptr.add(i1)) }
15 }
16}
17#[codesnip::entry("GetDistinctMut")]
18impl<'a, T> GetDistinctMut<(usize, usize, usize)> for &'a mut [T] {
19 type Output = (&'a mut T, &'a mut T, &'a mut T);
20 fn get_distinct_mut(self, (i0, i1, i2): (usize, usize, usize)) -> Self::Output {
21 assert_ne!(i0, i1);
22 assert_ne!(i0, i2);
23 assert!(i0 < self.len());
24 assert!(i1 < self.len());
25 assert!(i2 < self.len());
26 let ptr = self.as_mut_ptr();
27 unsafe { (&mut *ptr.add(i0), &mut *ptr.add(i1), &mut *ptr.add(i2)) }
28 }
29}