Trait std::slice::MutableVectorAllocating[src]
pub trait MutableVectorAllocating<'a, T> {
fn sort_by<T>(self, compare: |&T, &T| -> Ordering);
fn move_from<T>(self, src: Vec<T>, start: uint, end: uint) -> uint;
}Extension methods for vectors such that their elements are mutable.
Required Methods
fn sort_by<T>(self, compare: |&T, &T| -> Ordering)
Sort the vector, in place, using compare to compare
elements.
This sort is O(n log n) worst-case and stable, but allocates
approximately 2 * n, where n is the length of self.
Example
fn main() { let mut v = [5i, 4, 1, 3, 2]; v.sort_by(|a, b| a.cmp(b)); assert!(v == [1, 2, 3, 4, 5]); // reverse sorting v.sort_by(|a, b| b.cmp(a)); assert!(v == [5, 4, 3, 2, 1]); }let mut v = [5i, 4, 1, 3, 2]; v.sort_by(|a, b| a.cmp(b)); assert!(v == [1, 2, 3, 4, 5]); // reverse sorting v.sort_by(|a, b| b.cmp(a)); assert!(v == [5, 4, 3, 2, 1]);
fn move_from<T>(self, src: Vec<T>, start: uint, end: uint) -> uint
Consumes src and moves as many elements as it can into self
from the range [start,end).
Returns the number of elements copied (the shorter of self.len() and end - start).
Arguments
- src - A mutable vector of
T - start - The index into
srcto start copying from - end - The index into
strto stop copying from
Implementors
impl<'a, T> MutableVectorAllocating<'a, T> for &'a mut [T]