error in mem::swap
@@ -43,6 +43,8 @@ pub fn consolidate_slice<T: Ord, R: Monoid>(slice: &mut [(T, R)]) -> usize {
// using run-time tests.
unsafe {
+ assert!(offset < index);
+
// LOOP INVARIANT: offset < index
let ptr1 = slice.as_mut_ptr().offset(offset as isize);
let ptr2 = slice.as_mut_ptr().offset(index as isize);
@@ -54,9 +56,21 @@ pub fn consolidate_slice<T: Ord, R: Monoid>(slice: &mut [(T, R)]) -> usize {
if !(*ptr1).1.is_zero() {
offset += 1;
}
+ let ptr1 = slice.as_mut_ptr().offset(offset as isize);
std::mem::swap(&mut *ptr1, &mut *ptr2);
}
+ // if slice[offset].0 == slice[index].0 {
+ // let (lo, hi) = slice.split_at_mut(index);
+ // lo[offset].1 += &hi[0].1;
+ // }
+ // else {
+ // if slice[offset].1.is_zero() {
+ // offset += 1;
+ // }
+
+ // }
+
}
}
if !slice[offset].1.is_zero() {
@@ -118,6 +132,7 @@ pub fn consolidate_updates_slice<D: Ord, T: Ord, R: Monoid>(slice: &mut [(D, T,
if !(*ptr1).2.is_zero() {
offset += 1;
}
+ let ptr1 = slice.as_mut_ptr().offset(offset as isize);
std::mem::swap(&mut *ptr1, &mut *ptr2);
}
