Trait std::slice::SliceAllocPreludeExperimental
[-]
[+]
[src]
pub trait SliceAllocPrelude<T> {
fn sort_by(&mut self, compare: |&T, &T| -> Ordering);
fn move_from(&mut self, src: Vec<T>, start: uint, end: uint) -> uint;
}Allocating extension methods for slices.
Required Methods
fn sort_by(&mut self, compare: |&T, &T| -> Ordering)
Sorts the slice, 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(&mut 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
srcto stop copying from
Example
fn main() { let mut a = [1i, 2, 3, 4, 5]; let b = vec![6i, 7, 8]; let num_moved = a.move_from(b, 0, 3); assert_eq!(num_moved, 3); assert!(a == [6i, 7, 8, 4, 5]); }let mut a = [1i, 2, 3, 4, 5]; let b = vec![6i, 7, 8]; let num_moved = a.move_from(b, 0, 3); assert_eq!(num_moved, 3); assert!(a == [6i, 7, 8, 4, 5]);
Implementors
impl<T> SliceAllocPrelude<T> for [T]