/// slice. Equivalently, rotates the slice `mid` places to the left
/// or `k = self.len() - mid` places to the right.
///
- /// Rotation by `mid` and rotation by `k` are inverse operations.
- /// The method returns `k`, which is also the new location of
- /// the formerly-first element.
- ///
/// This is a "k-rotation", a permutation in which item `i` moves to
/// position `i + k`, modulo the length of the slice. See _Elements
/// of Programming_ [ยง10.4][eop].
///
+ /// Rotation by `mid` and rotation by `k` are inverse operations.
+ ///
/// [eop]: https://books.google.com/books?id=CO9ULZGINlsC&pg=PA178&q=k-rotation
///
/// # Panics
/// #![feature(slice_rotate)]
///
/// let mut a = [1, 2, 3, 4, 5, 6, 7];
- /// let k = a.rotate(2);
+ /// let mid = 2;
+ /// a.rotate(mid);
/// assert_eq!(&a, &[3, 4, 5, 6, 7, 1, 2]);
+ /// let k = a.len() - mid;
/// a.rotate(k);
/// assert_eq!(&a, &[1, 2, 3, 4, 5, 6, 7]);
///
/// assert_eq!(&v, &[0, 3, 7, 4, 5, 6, 1, 2, 8, 9]);
/// ```
#[unstable(feature = "slice_rotate", issue = "41891")]
- pub fn rotate(&mut self, mid: usize) -> usize {
- core_slice::SliceExt::rotate(self, mid)
+ pub fn rotate(&mut self, mid: usize) {
+ core_slice::SliceExt::rotate(self, mid);
}
/// Copies the elements from `src` into `self`.
fn ends_with(&self, needle: &[Self::Item]) -> bool where Self::Item: PartialEq;
#[unstable(feature = "slice_rotate", issue = "41891")]
- fn rotate(&mut self, mid: usize) -> usize;
+ fn rotate(&mut self, mid: usize);
#[stable(feature = "clone_from_slice", since = "1.7.0")]
fn clone_from_slice(&mut self, src: &[Self::Item]) where Self::Item: Clone;
self.binary_search_by(|p| p.borrow().cmp(x))
}
- fn rotate(&mut self, mid: usize) -> usize {
+ fn rotate(&mut self, mid: usize) {
assert!(mid <= self.len());
let k = self.len() - mid;
let p = self.as_mut_ptr();
rotate::ptr_rotate(mid, p.offset(mid as isize), k);
}
-
- k
}
#[inline]