Vectors

Struct UnboxedVecRepr

pub struct UnboxedVecRepr {
    fill: uint,
    alloc: uint,
    data: u8,
}

The internal 'unboxed' representation of a vector

Struct VecIterator

pub struct VecIterator<'self, T> {
    priv ptr: *T,
    priv end: *T,
    priv lifetime: &'self T,
}

An iterator for iterating over a vector

Struct VecMutIterator

pub struct VecMutIterator<'self, T> {
    priv ptr: *mut T,
    priv end: *mut T,
    priv lifetime: &'self mut T,
}

An iterator for mutating the elements of a vector

Struct VecMutRevIterator

pub struct VecMutRevIterator<'self, T> {
    priv ptr: *mut T,
    priv end: *mut T,
    priv lifetime: &'self mut T,
}

An iterator for mutating the elements of a vector in reverse

Struct VecRevIterator

pub struct VecRevIterator<'self, T> {
    priv ptr: *T,
    priv end: *T,
    priv lifetime: &'self T,
}

An iterator for iterating over a vector in reverse

Trait CopyableVector

Method to_owned

fn to_owned(&self) -> ~[T]

Trait ImmutableCopyableVector

Method filtered

fn filtered(&self, f: &fn(&T) -> bool) -> ~[T]

Method partitioned

fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T])

Method unsafe_get

unsafe fn unsafe_get(&self, elem: uint) -> T

Trait ImmutableEqVector

Method position_elem

fn position_elem(&self, t: &T) -> Option<uint>

Method rposition_elem

fn rposition_elem(&self, t: &T) -> Option<uint>

Method contains

fn contains(&self, x: &T) -> bool

Trait ImmutableTotalOrdVector

Method bsearch_elem

fn bsearch_elem(&self, x: &T) -> Option<uint>

Trait ImmutableVector

Method slice

fn slice(&self, start: uint, end: uint) -> &'self [T]

Method iter

fn iter(self) -> VecIterator<'self, T>

Method rev_iter

fn rev_iter(self) -> VecRevIterator<'self, T>

Method head

fn head(&self) -> &'self T

Method head_opt

fn head_opt(&self) -> Option<&'self T>

Method tail

fn tail(&self) -> &'self [T]

Method tailn

fn tailn(&self, n: uint) -> &'self [T]

Method init

fn init(&self) -> &'self [T]

Method initn

fn initn(&self, n: uint) -> &'self [T]

Method last

fn last(&self) -> &'self T

Method last_opt

fn last_opt(&self) -> Option<&'self T>

Method rposition

fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint>

Method flat_map

fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U]

Method filter_mapped

fn filter_mapped<U: Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U]

Method unsafe_ref

unsafe fn unsafe_ref(&self, index: uint) -> *T

Method bsearch

fn bsearch(&self, f: &fn(&T) -> Ordering) -> Option<uint>

Method map

fn map<U>(&self, &fn(t: &T) -> U) -> ~[U]

Trait MutableCloneableVector

Trait for ~[T] where T is Cloneable

Method copy_from

fn copy_from(self, &[T]) -> uint

Copies as many elements from src as it can into self (the shorter of self.len() and src.len()). Returns the number of elements copied.

Trait MutableVector

Method mut_slice

fn mut_slice(self, start: uint, end: uint) -> &'self mut [T]

Method mut_iter

fn mut_iter(self) -> VecMutIterator<'self, T>

Method mut_rev_iter

fn mut_rev_iter(self) -> VecMutRevIterator<'self, T>

Method swap

fn swap(self, a: uint, b: uint)

Method reverse

fn reverse(self)

Method move_from

fn move_from(self, src: ~[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 src to start copying from
  • end - The index into str to stop copying from

Method unsafe_mut_ref

unsafe fn unsafe_mut_ref(&self, index: uint) -> *mut T

Method unsafe_set

unsafe fn unsafe_set(&self, index: uint, val: T)

Trait OwnedCopyableVector

Method push_all

fn push_all(&mut self, rhs: &[T])

Method grow

fn grow(&mut self, n: uint, initval: &T)

Method grow_set

fn grow_set(&mut self, index: uint, initval: &T, val: T)

Trait OwnedEqVector

Method dedup

fn dedup(&mut self)

Trait OwnedVector

Method reserve

fn reserve(&mut self, n: uint)

Method reserve_at_least

fn reserve_at_least(&mut self, n: uint)

Method capacity

fn capacity(&self) -> uint

Method push

fn push(&mut self, t: T)

Method push_fast

unsafe fn push_fast(&mut self, t: T)

Method push_all_move

fn push_all_move(&mut self, rhs: ~[T])

Method pop

fn pop(&mut self) -> T

Method shift

fn shift(&mut self) -> T

Method unshift

fn unshift(&mut self, x: T)

Method insert

fn insert(&mut self, i: uint, x: T)

Method remove

fn remove(&mut self, i: uint) -> T

Method swap_remove

fn swap_remove(&mut self, index: uint) -> T

Method truncate

fn truncate(&mut self, newlen: uint)

Method retain

fn retain(&mut self, f: &fn(t: &T) -> bool)

Method consume

fn consume(self, f: &fn(uint, v: T))

Method consume_reverse

fn consume_reverse(self, f: &fn(uint, v: T))

Method filter

fn filter(self, f: &fn(t: &T) -> bool) -> ~[T]

Method partition

fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T])

Method grow_fn

fn grow_fn(&mut self, n: uint, op: &fn(uint) -> T)

Trait VectorVector

Method concat_vec

fn concat_vec(&self) -> ~[T]

Method connect_vec

fn connect_vec(&self, sep: &T) -> ~[T]

Implementation of VectorVector<T> for &'self [~[T]] where <'self, T: Copy>

Method concat_vec

fn concat_vec(&self) -> ~[T]

Flattens a vector of slices of T into a single vector of T.

Method connect_vec

fn connect_vec(&self, sep: &T) -> ~[T]

Concatenate a vector of vectors, placing a given separator between each.

Implementation of VectorVector<T> for &'self [&'self [T]] where <'self, T: Copy>

Method concat_vec

fn concat_vec(&self) -> ~[T]

Flattens a vector of slices of T into a single vector of T.

Method connect_vec

fn connect_vec(&self, sep: &T) -> ~[T]

Concatenate a vector of slices, placing a given separator between each.

Implementation of Eq for &'self [T] where <'self, T: Eq>

Method eq

fn eq(&self, other: &&'self [T]) -> bool

Method ne

fn ne(&self, other: &&'self [T]) -> bool

Implementation of Eq for ~[T] where <T: Eq>

Method eq

fn eq(&self, other: &~[T]) -> bool

Method ne

fn ne(&self, other: &~[T]) -> bool

Implementation of Eq for @[T] where <T: Eq>

Method eq

fn eq(&self, other: &@[T]) -> bool

Method ne

fn ne(&self, other: &@[T]) -> bool

Implementation of TotalEq for &'self [T] where <'self, T: TotalEq>

Method equals

fn equals(&self, other: &&'self [T]) -> bool

Implementation of TotalEq for ~[T] where <T: TotalEq>

Method equals

fn equals(&self, other: &~[T]) -> bool

Implementation of TotalEq for @[T] where <T: TotalEq>

Method equals

fn equals(&self, other: &@[T]) -> bool

Implementation of Equiv<~[T]> for &'self [T] where <'self, T: Eq>

Method equiv

fn equiv(&self, other: &~[T]) -> bool

Implementation of TotalOrd for &'self [T] where <'self, T: TotalOrd>

Method cmp

fn cmp(&self, other: &&'self [T]) -> Ordering

Implementation of TotalOrd for ~[T] where <T: TotalOrd>

Method cmp

fn cmp(&self, other: &~[T]) -> Ordering

Implementation of TotalOrd for @[T] where <T: TotalOrd>

Method cmp

fn cmp(&self, other: &@[T]) -> Ordering

Implementation of Ord for &'self [T] where <'self, T: Ord>

Method lt

fn lt(&self, other: &&'self [T]) -> bool

Method le

fn le(&self, other: &&'self [T]) -> bool

Method ge

fn ge(&self, other: &&'self [T]) -> bool

Method gt

fn gt(&self, other: &&'self [T]) -> bool

Implementation of Ord for ~[T] where <T: Ord>

Method lt

fn lt(&self, other: &~[T]) -> bool

Method le

fn le(&self, other: &~[T]) -> bool

Method ge

fn ge(&self, other: &~[T]) -> bool

Method gt

fn gt(&self, other: &~[T]) -> bool

Implementation of Ord for @[T] where <T: Ord>

Method lt

fn lt(&self, other: &@[T]) -> bool

Method le

fn le(&self, other: &@[T]) -> bool

Method ge

fn ge(&self, other: &@[T]) -> bool

Method gt

fn gt(&self, other: &@[T]) -> bool

Implementation of Add<&'self [T], ~[T]> for ~[T] where <'self, T: Copy>

Method add

fn add(&self, rhs: &&'self [T]) -> ~[T]

Implementation of Container for &'self [T] where <'self, T>

Method is_empty

fn is_empty(&self) -> bool

Returns true if a vector contains no elements

Method len

fn len(&self) -> uint

Returns the length of a vector

Implementation of Container for ~[T] where <T>

Method is_empty

fn is_empty(&self) -> bool

Returns true if a vector contains no elements

Method len

fn len(&self) -> uint

Returns the length of a vector

Implementation of CopyableVector<T> for &'self [T] where <'self, T: Copy>

Extension methods for vectors

Method to_owned

fn to_owned(&self) -> ~[T]

Returns a copy of v.

Implementation of ImmutableVector<'self, T> for &'self [T] where <'self, T>

Extension methods for vectors

Method slice

fn slice(&self, start: uint, end: uint) -> &'self [T]

Return a slice that points into another slice.

Method iter

fn iter(self) -> VecIterator<'self, T>

Method rev_iter

fn rev_iter(self) -> VecRevIterator<'self, T>

Method head

fn head(&self) -> &'self T

Returns the first element of a vector, failing if the vector is empty.

Method head_opt

fn head_opt(&self) -> Option<&'self T>

Returns the first element of a vector, or None if it is empty

Method tail

fn tail(&self) -> &'self [T]

Returns all but the first element of a vector

Method tailn

fn tailn(&self, n: uint) -> &'self [T]

Returns all but the first `n' elements of a vector

Method init

fn init(&self) -> &'self [T]

Returns all but the last element of a vector

Method initn

fn initn(&self, n: uint) -> &'self [T]

Returns all but the last `n' elemnts of a vector

Method last

fn last(&self) -> &'self T

Returns the last element of a vector, failing if the vector is empty.

Method last_opt

fn last_opt(&self) -> Option<&'self T>

Returns the last element of a vector, or None if it is empty.

Method rposition

fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint>

Find the last index matching some predicate

Apply function f to each element of v in reverse order. When function f returns true then an option containing the index is returned. If f matches no elements then None is returned.

Method flat_map

fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U]

Apply a function to each element of a vector and return a concatenation of each result vector

Method filter_mapped

fn filter_mapped<U: Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U]

Apply a function to each element of a vector and return the results

If function f returns none then that element is excluded from the resulting vector.

Method unsafe_ref

unsafe fn unsafe_ref(&self, index: uint) -> *T

Returns a pointer to the element at the given index, without doing bounds checking.

Method bsearch

fn bsearch(&self, f: &fn(&T) -> Ordering) -> Option<uint>

Binary search a sorted vector with a comparator function.

The comparator should implement an order consistent with the sort order of the underlying vector, returning an order code that indicates whether its argument is Less, Equal or Greater the desired target.

Returns the index where the comparator returned Equal, or None if not found.

Method map

fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U]

Deprecated, use iterators where possible (self.iter().transform(f)). Apply a function to each element of a vector and return the results.

Implementation of ImmutableEqVector<T> for &'self [T] where <'self, T: Eq>

Method position_elem

fn position_elem(&self, x: &T) -> Option<uint>

Find the first index containing a matching value

Method rposition_elem

fn rposition_elem(&self, t: &T) -> Option<uint>

Find the last index containing a matching value

Method contains

fn contains(&self, x: &T) -> bool

Return true if a vector contains an element with the given value

Implementation of ImmutableTotalOrdVector<T> for &'self [T] where <'self, T: TotalOrd>

Method bsearch_elem

fn bsearch_elem(&self, x: &T) -> Option<uint>

Binary search a sorted vector for a given element.

Returns the index of the element or None if not found.

Implementation of ImmutableCopyableVector<T> for &'self [T] where <'self, T: Copy>

Extension methods for vectors

Method filtered

fn filtered(&self, f: &fn(t: &T) -> bool) -> ~[T]

Construct a new vector from the elements of a vector for which some predicate holds.

Apply function f to each element of v and return a vector containing only those elements for which f returned true.

Method partitioned

fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T])

Partitions the vector into those that satisfies the predicate, and those that do not.

Method unsafe_get

unsafe fn unsafe_get(&self, index: uint) -> T

Returns the element at the given index, without doing bounds checking.

Implementation of OwnedVector<T> for ~[T] where <T>

Method reserve

fn reserve(&mut self, n: uint)

Reserves capacity for exactly n elements in the given vector.

If the capacity for self is already equal to or greater than the requested capacity, then no action is taken.

Arguments

  • n - The number of elements to reserve space for

Method reserve_at_least

fn reserve_at_least(&mut self, n: uint)

Reserves capacity for at least n elements in the given vector.

This function will over-allocate in order to amortize the allocation costs in scenarios where the caller may need to repeatedly reserve additional space.

If the capacity for self is already equal to or greater than the requested capacity, then no action is taken.

Arguments

  • n - The number of elements to reserve space for

Method capacity

fn capacity(&self) -> uint

Returns the number of elements the vector can hold without reallocating.

Method push

fn push(&mut self, t: T)

Append an element to a vector

Method push_fast

unsafe fn push_fast(&mut self, t: T)

Method push_all_move

fn push_all_move(&mut self, mut rhs: ~[T])

Takes ownership of the vector rhs, moving all elements into the current vector. This does not copy any elements, and it is illegal to use the rhs vector after calling this method (because it is moved here).

Example

let mut a = ~[~1];
a.push_all_move(~[~2, ~3, ~4]);
assert!(a == ~[~1, ~2, ~3, ~4]);

Method pop

fn pop(&mut self) -> T

Remove the last element from a vector and return it

Method shift

fn shift(&mut self) -> T

Removes the first element from a vector and return it

Method unshift

fn unshift(&mut self, x: T)

Prepend an element to the vector

Method insert

fn insert(&mut self, i: uint, x: T)

Insert an element at position i within v, shifting all elements after position i one position to the right.

Method remove

fn remove(&mut self, i: uint) -> T

Remove and return the element at position i within v, shifting all elements after position i one position to the left.

Method swap_remove

fn swap_remove(&mut self, index: uint) -> T

Remove an element from anywhere in the vector and return it, replacing it with the last element. This does not preserve ordering, but is O(1).

Fails if index >= length.

Method truncate

fn truncate(&mut self, newlen: uint)

Shorten a vector, dropping excess elements.

Method retain

fn retain(&mut self, f: &fn(t: &T) -> bool)

Like filter(), but in place. Preserves order of v. Linear time.

Method consume

fn consume(self, f: &fn(uint, v: T))

Method consume_reverse

fn consume_reverse(self, f: &fn(uint, v: T))

Method filter

fn filter(self, f: &fn(&T) -> bool) -> ~[T]

Method partition

fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T])

Partitions the vector into those that satisfies the predicate, and those that do not.

Method grow_fn

fn grow_fn(&mut self, n: uint, op: &fn(uint) -> T)

Expands a vector in place, initializing the new elements to the result of a function

Function init_op is called n times with the values [0..n)

Arguments

  • n - The number of elements to add
  • init_op - A function to call to retreive each appended element's value

Implementation of Mutable for ~[T] where <T>

Method clear

fn clear(&mut self)

Clear the vector, removing all values.

Implementation of OwnedCopyableVector<T> for ~[T] where <T: Copy>

Method push_all

fn push_all(&mut self, rhs: &[T])

Iterates over the slice rhs, copies each element, and then appends it to the vector provided v. The rhs vector is traversed in-order.

Example

let mut a = ~[1];
a.push_all([2, 3, 4]);
assert!(a == ~[1, 2, 3, 4]);

Method grow

fn grow(&mut self, n: uint, initval: &T)

Expands a vector in place, initializing the new elements to a given value

Arguments

  • n - The number of elements to add
  • initval - The value for the new elements

Method grow_set

fn grow_set(&mut self, index: uint, initval: &T, val: T)

Sets the value of a vector element at a given index, growing the vector as needed

Sets the element at position index to val. If index is past the end of the vector, expands the vector by replicating initval to fill the intervening space.

Implementation of OwnedEqVector<T> for ~[T] where <T: Eq>

Method dedup

fn dedup(&mut self)

Remove consecutive repeated elements from a vector; if the vector is sorted, this removes all duplicates.

Implementation of MutableVector<'self, T> for &'self mut [T] where <'self, T>

Method mut_slice

fn mut_slice(self, start: uint, end: uint) -> &'self mut [T]

Return a slice that points into another slice.

Method mut_iter

fn mut_iter(self) -> VecMutIterator<'self, T>

Method mut_rev_iter

fn mut_rev_iter(self) -> VecMutRevIterator<'self, T>

Method swap

fn swap(self, a: uint, b: uint)

Swaps two elements in a vector

Arguments

  • a - The index of the first element
  • b - The index of the second element

Method reverse

fn reverse(self)

Reverse the order of elements in a vector, in place

Method move_from

fn move_from(self, mut src: ~[T], start: uint, end: uint) -> uint

Method unsafe_mut_ref

unsafe fn unsafe_mut_ref(&self, index: uint) -> *mut T

Method unsafe_set

unsafe fn unsafe_set(&self, index: uint, val: T)

Implementation of MutableCloneableVector<T> for &'self mut [T] where <'self, T: Clone>

Method copy_from

fn copy_from(self, src: &[T]) -> uint

Implementation of Clone for ~[A] where <A: Clone>

Method clone

fn clone(&self) -> ~[A]

Implementation of Zero for &'self [A] where <'self, A>

Method zero

fn zero() -> &'self [A]

Method is_zero

fn is_zero(&self) -> bool

Implementation of Zero for ~[A] where <A>

Method zero

fn zero() -> ~[A]

Method is_zero

fn is_zero(&self) -> bool

Implementation of Zero for @[A] where <A>

Method zero

fn zero() -> @[A]

Method is_zero

fn is_zero(&self) -> bool

Implementation of Iterator<&'self T> for VecIterator<'self, T> where <'self, T>

Method next

fn next(&mut self) -> Option<&'self T>

Method size_hint

fn size_hint(&self) -> (Option<uint>, Option<uint>)

Implementation of Iterator<&'self T> for VecRevIterator<'self, T> where <'self, T>

Method next

fn next(&mut self) -> Option<&'self T>

Method size_hint

fn size_hint(&self) -> (Option<uint>, Option<uint>)

Implementation of Iterator<&'self mut T> for VecMutIterator<'self, T> where <'self, T>

Method next

fn next(&mut self) -> Option<&'self mut T>

Method size_hint

fn size_hint(&self) -> (Option<uint>, Option<uint>)

Implementation of Iterator<&'self mut T> for VecMutRevIterator<'self, T> where <'self, T>

Method next

fn next(&mut self) -> Option<&'self mut T>

Method size_hint

fn size_hint(&self) -> (Option<uint>, Option<uint>)

Implementation of FromIter<T> for ~[T] where <T>

Method from_iter

fn from_iter(iter: &fn(f: &fn(T) -> bool) -> bool) -> ~[T]

Implementation of FromIterator<A, T> for ~[A] where <A, T: Iterator<A>>

Method from_iterator

fn from_iterator(iterator: &mut T) -> ~[A]

Function append

fn append<T: Copy>(lhs: ~[T], rhs: &[T]) -> ~[T]

Iterates over the rhs vector, copying each element and appending it to the lhs. Afterwards, the lhs is then returned for use again.

Function append_one

fn append_one<T>(lhs: ~[T], x: T) -> ~[T]

Appends one element to the vector provided. The vector itself is then returned for use again.

Function as_imm_buf

fn as_imm_buf<T, U>(s: &[T], f: &fn(*T, uint) -> U) -> U

Work with the buffer of a vector.

Allows for unsafe manipulation of vector contents, which is useful for foreign interop.

Function as_mut_buf

fn as_mut_buf<T, U>(s: &mut [T], f: &fn(*mut T, uint) -> U) -> U

Similar to as_imm_buf but passing a *mut T

Function build

fn build<A>(builder: &fn(push: &fn(v: A))) -> ~[A]

Builds a vector by calling a provided function with an argument function that pushes an element to the back of a vector.

Arguments

Function build_sized

fn build_sized<A>(size: uint, builder: &fn(push: &fn(v: A))) -> ~[A]

Builds a vector by calling a provided function with an argument function that pushes an element to the back of a vector. This version takes an initial capacity for the vector.

Arguments

Function build_sized_opt

fn build_sized_opt<A>(size: Option<uint>, builder: &fn(push: &fn(v: A))) ->
 ~[A]

Builds a vector by calling a provided function with an argument function that pushes an element to the back of a vector. This version takes an initial size for the vector.

Arguments

Function concat

fn concat<T: Copy>(v: &[~[T]]) -> ~[T]

Flattens a vector of vectors of T into a single vector of T.

Function concat_slices

fn concat_slices<T: Copy>(v: &[&[T]]) -> ~[T]

Flattens a vector of vectors of T into a single vector of T.

Function connect

fn connect<T: Copy>(v: &[~[T]], sep: &T) -> ~[T]

Concatenate a vector of vectors, placing a given separator between each

Function connect_slices

fn connect_slices<T: Copy>(v: &[&[T]], sep: &T) -> ~[T]

Concatenate a vector of vectors, placing a given separator between each

Function consume

fn consume<T>(mut v: ~[T], f: &fn(uint, v: T))

Consumes all elements, in a vector, moving them out into the / closure provided. The vector is traversed from the start to the end.

This method does not impose any requirements on the type of the vector being consumed, but it prevents any usage of the vector after this function is called.

Examples

let v = ~[~"a", ~"b"];
do vec::consume(v) |i, s| {
  // s has type ~str, not &~str
  io::println(s + fmt!(" %d", i));
}

Function consume_reverse

fn consume_reverse<T>(mut v: ~[T], f: &fn(uint, v: T))

Consumes all elements, in a vector, moving them out into the / closure provided. The vectors is traversed in reverse order (from end to start).

This method does not impose any requirements on the type of the vector being consumed, but it prevents any usage of the vector after this function is called.

Function each_permutation

fn each_permutation<T: Copy>(values: &[T], fun: &fn(perm: &[T]) -> bool) ->
 bool

Iterate over all permutations of vector v.

Permutations are produced in lexicographic order with respect to the order of elements in v (so if v is sorted then the permutations are lexicographically sorted).

The total number of permutations produced is v.len()!. If v contains repeated elements, then some permutations are repeated.

See Algorithms to generate permutations.

# Arguments

Function filter

fn filter<T>(v: ~[T], f: &fn(t: &T) -> bool) -> ~[T]

Construct a new vector from the elements of a vector for which some predicate holds.

Apply function f to each element of v and return a vector containing only those elements for which f returned true.

Function filter_map

fn filter_map<T, U>(v: ~[T], f: &fn(t: T) -> Option<U>) -> ~[U]

Apply a function to each element of a vector and return the results. Consumes the input vector. If function f returns None then that element is excluded from the resulting vector.

Function filter_mapped

fn filter_mapped<T, U: Copy>(v: &[T], f: &fn(t: &T) -> Option<U>) -> ~[U]

Like filter_map(), but operates on a borrowed slice and does not consume the input.

Function filtered

fn filtered<T: Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[T]

Construct a new vector from the elements of a vector for which some predicate holds.

Apply function f to each element of v and return a vector containing only those elements for which f returned true.

Function flat_map

fn flat_map<T, U>(v: &[T], f: &fn(t: &T) -> ~[U]) -> ~[U]

Apply a function to each element of a vector and return a concatenation of each result vector

Function from_buf

unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T]

Constructs a vector from an unsafe pointer to a buffer

Arguments

Function from_elem

fn from_elem<T: Copy>(n_elts: uint, t: T) -> ~[T]

Creates and initializes an owned vector.

Creates an owned vector of size n_elts and initializes the elements to the value t.

Function from_fn

fn from_fn<T>(n_elts: uint, op: &fn(uint) -> T) -> ~[T]

Creates and initializes an owned vector.

Creates an owned vector of size n_elts and initializes the elements to the value returned by the function op.

Function map_consume

fn map_consume<T, U>(v: ~[T], f: &fn(v: T) -> U) -> ~[U]

Consumes a vector, mapping it into a different vector. This function takes ownership of the supplied vector v, moving each element into the closure provided to generate a new element. The vector of new elements is then returned.

The original vector v cannot be used after this function call (it is moved inside), but there are no restrictions on the type of the vector.

Function reversed

fn reversed<T: Copy>(v: &[T]) -> ~[T]

Returns a vector with the order of elements reversed

Function rsplit

fn rsplit<T: Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]]

Reverse split the vector v by applying each element against the predicate f.

Function rsplitn

fn rsplitn<T: Copy>(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]]

Reverse split the vector v by applying each element against the predicate f up to `n times.

Function same_length

fn same_length<T, U>(xs: &[T], ys: &[U]) -> bool

Returns true if two vectors have the same length

Function split

fn split<T: Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]]

Copies Split the vector v by applying each element against the predicate f.

Function splitn

fn splitn<T: Copy>(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]]

Split the vector v by applying each element against the predicate f up to n times.

Function to_owned

fn to_owned<T: Copy>(t: &[T]) -> ~[T]

Creates a new unique vector with the same contents as the slice

Function unzip

fn unzip<T, U>(v: ~[(T, U)]) -> (~[T], ~[U])

Convert a vector of pairs into a pair of vectors.

Returns a tuple containing two vectors where the i-th element of the first vector contains the first element of the i-th tuple of the input vector, and the i-th element of the second vector contains the second element of the i-th tuple of the input vector.

Function unzip_slice

fn unzip_slice<T: Copy, U: Copy>(v: &[(T, U)]) -> (~[T], ~[U])

Convert a vector of pairs into a pair of vectors, by reference. As unzip().

Function windowed

fn windowed<'r, T>(n: uint, v: &'r [T], it: &fn(&'r [T]) -> bool) -> bool

Iterate over all contiguous windows of length n of the vector v.

Example

Print the adjacent pairs of a vector (i.e. [1,2], [2,3], [3,4])

for windowed(2, &[1,2,3,4]) |v| {
    io::println(fmt!("%?", v));
}

Function with_capacity

fn with_capacity<T>(capacity: uint) -> ~[T]

Creates a new vector with a capacity of capacity

Function zip

fn zip<T, U>(mut v: ~[T], mut u: ~[U]) -> ~[(T, U)]

Convert two vectors to a vector of pairs.

Returns a vector of tuples, where the i-th tuple contains the i-th elements from each of the input vectors.

Function zip_slice

fn zip_slice<T: Copy, U: Copy>(v: &[T], u: &[U]) -> ~[(T, U)]

Convert two vectors to a vector of pairs, by reference. As zip().