Vectors

Struct UnboxedVecRepr

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

The internal 'unboxed' representation of a vector

Trait CopyableVector

Method to_owned

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

Trait ImmutableCopyableVector

Method filtered

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

Method rfind

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

Method partitioned

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

Trait ImmutableEqVector

Method position

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

Method position_elem

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

Method rposition

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

Method rposition_elem

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

Trait ImmutableVector

Method slice

fn slice(&self, start: uint, end: uint) -> &'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 each_reverse

fn each_reverse(&self, blk: &fn(&T) -> bool)

Method eachi_reverse

fn eachi_reverse(&self, blk: &fn(uint, &T) -> bool)

Method foldr

fn foldr<U: Copy>(&self, z: U, p: &fn(t: &T, u: U) -> U) -> U

Method map

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

Method mapi

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

Method map_r

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

Method alli

fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool

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]

Trait OwnedCopyableVector

Method push_all

fn push_all(&mut self, rhs: &const [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 OwnedVector

Method push

fn push(&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: iter::InitOp<T>)

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 Container for &'self const [T] where <'self, T>

Method is_empty

fn is_empty(&const self) -> bool

Returns true if a vector contains no elements

Method len

fn len(&const self) -> uint

Returns the length of a vector

Implementation of CopyableVector<T> for &'self const [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<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 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

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 elemnt 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 v, failing if the vector is empty.

Method last_opt

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

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

Method each_reverse

fn each_reverse(&self, blk: &fn(&T) -> bool)

Iterates over a vector's elements in reverse.

Method eachi_reverse

fn eachi_reverse(&self, blk: &fn(uint, &T) -> bool)

Iterates over a vector's elements and indices in reverse.

Method foldr

fn foldr<U: Copy>(&self, z: U, p: &fn(t: &T, u: U) -> U) -> U

Reduce a vector from right to left

Method map

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

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

Method mapi

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

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

Method map_r

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

Method alli

fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool

Returns true if the function returns true for all elements.

If the vector is empty, true 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.

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

Method position

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

Find the first index matching some predicate

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

Method position_elem

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

Find the first index containing a matching value

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 rposition_elem

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

Find the last index containing a matching value

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 rfind

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

Search for the last element that matches a given predicate

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

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.

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

Method push

fn push(&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) -> 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: iter::InitOp<T>)

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: &const [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)

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

Method dedup

fn dedup(&mut self)

Implementation of iter::BaseIter<A> for &'self [A] where <'self, A>

Method each

fn each(&self, blk: &fn(v: &'self A) -> bool)

Method size_hint

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

Implementation of iter::BaseIter<A> for ~[A] where <A>

Method each

fn each(&self, blk: &fn(v: &'self A) -> bool)

Method size_hint

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

Implementation of iter::BaseIter<A> for @[A] where <A>

Method each

fn each(&self, blk: &fn(v: &'self A) -> bool)

Method size_hint

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

Implementation of iter::MutableIter<A> for &'self mut [A] where <'self, A>

Method each_mut

fn each_mut(&mut self, blk: &fn(v: &'self mut A) -> bool)

Implementation of iter::MutableIter<A> for ~[A] where <A>

Method each_mut

fn each_mut(&mut self, blk: &fn(v: &'self mut A) -> bool)

Implementation of iter::MutableIter<A> for @mut [A] where <A>

Method each_mut

fn each_mut(&mut self, blk: &fn(v: &mut A) -> bool)

Implementation of iter::ExtendedIter<A> for &'self [A] where <'self, A>

Method eachi

fn eachi(&self, blk: &fn(uint, v: &A) -> bool)

Method all

fn all(&self, blk: &fn(&A) -> bool) -> bool

Method any

fn any(&self, blk: &fn(&A) -> bool) -> bool

Method foldl

fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B

Method position

fn position(&self, f: &fn(&A) -> bool) -> Option<uint>

Method map_to_vec

fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B]

Method flat_map_to_vec

fn flat_map_to_vec<B, IB: BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B]

Implementation of iter::ExtendedIter<A> for ~[A] where <A>

Method eachi

fn eachi(&self, blk: &fn(uint, v: &A) -> bool)

Method all

fn all(&self, blk: &fn(&A) -> bool) -> bool

Method any

fn any(&self, blk: &fn(&A) -> bool) -> bool

Method foldl

fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B

Method position

fn position(&self, f: &fn(&A) -> bool) -> Option<uint>

Method map_to_vec

fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B]

Method flat_map_to_vec

fn flat_map_to_vec<B, IB: BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B]

Implementation of iter::ExtendedIter<A> for @[A] where <A>

Method eachi

fn eachi(&self, blk: &fn(uint, v: &A) -> bool)

Method all

fn all(&self, blk: &fn(&A) -> bool) -> bool

Method any

fn any(&self, blk: &fn(&A) -> bool) -> bool

Method foldl

fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B

Method position

fn position(&self, f: &fn(&A) -> bool) -> Option<uint>

Method map_to_vec

fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B]

Method flat_map_to_vec

fn flat_map_to_vec<B, IB: BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B]

Implementation of iter::EqIter<A> for &'self [A] where <'self, A: Eq>

Method contains

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

Method count

fn count(&self, x: &A) -> uint

Implementation of iter::EqIter<A> for ~[A] where <A: Eq>

Method contains

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

Method count

fn count(&self, x: &A) -> uint

Implementation of iter::EqIter<A> for @[A] where <A: Eq>

Method contains

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

Method count

fn count(&self, x: &A) -> uint

Implementation of iter::CopyableIter<A> for &'self [A] where <'self, A: Copy>

Method filter_to_vec

fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A]

Method to_vec

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

Method find

fn find(&self, f: &fn(&A) -> bool) -> Option<A>

Implementation of iter::CopyableIter<A> for ~[A] where <A: Copy>

Method filter_to_vec

fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A]

Method to_vec

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

Method find

fn find(&self, f: &fn(&A) -> bool) -> Option<A>

Implementation of iter::CopyableIter<A> for @[A] where <A: Copy>

Method filter_to_vec

fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A]

Method to_vec

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

Method find

fn find(&self, f: &fn(&A) -> bool) -> Option<A>

Implementation of iter::CopyableOrderedIter<A> for &'self [A] where <'self, A: Copy + Ord>

Method min

fn min(&self) -> A

Method max

fn max(&self) -> A

Implementation of iter::CopyableOrderedIter<A> for ~[A] where <A: Copy + Ord>

Method min

fn min(&self) -> A

Method max

fn max(&self) -> A

Implementation of iter::CopyableOrderedIter<A> for @[A] where <A: Copy + Ord>

Method min

fn min(&self) -> A

Method max

fn max(&self) -> A

Implementation of iter::CopyableNonstrictIter<A> for &'self [A] where <'self, A: Copy>

Method each_val

fn each_val(&const self, f: &fn(A) -> bool)

Implementation of iter::CopyableNonstrictIter<A> for ~[A] where <A: Copy>

Method each_val

fn each_val(&const self, f: &fn(A) -> bool)

Implementation of iter::CopyableNonstrictIter<A> for @[A] where <A: Copy>

Method each_val

fn each_val(&const self, f: &fn(A) -> bool)

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

Method clone

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

Function all

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

Return true if a predicate matches all elements

If the vector contains no elements then true is returned.

Function all2

fn all2<T, U>(v0: &[T], v1: &[U], f: &fn(t: &T, u: &U) -> bool) -> bool

Return true if a predicate matches all elements in both vectors.

If the vectors are not the same size then false is returned.

Function alli

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

Return true if a predicate matches all elements

If the vector contains no elements then true is returned.

Function any

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

Return true if a predicate matches any elements

If the vector contains no elements then false is returned.

Function any2

fn any2<T, U>(v0: &[T], v1: &[U], f: &fn(a: &T, b: &U) -> bool) -> bool

Return true if a predicate matches any elements in both vectors.

If the vectors contains no elements then false is returned.

Function append

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

Function append_one

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

Function as_const_buf

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

Similar to as_imm_buf but passing a *const T

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 capacity

fn capacity<T>(v: &const ~[T]) -> uint

Returns the number of elements the vector can hold without reallocating

Function concat

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

Concatenate a vector of vectors.

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 const_slice

fn const_slice<'r, T>(v: &'r const [T], start: uint, end: uint) ->
 &'r const [T]

Return a slice that points into another slice.

Function consume

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

Function consume_reverse

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

Function contains

fn contains<T: Eq>(v: &[T], x: &T) -> bool

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

Function count

fn count<T: Eq>(v: &[T], x: &T) -> uint

Returns the number of elements that are equal to a given value

Function dedup

fn dedup<T: Eq>(v: &mut ~[T])

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

Function each

fn each<'r, T>(v: &'r [T], f: &fn(&'r T) -> bool)

Iterates over a vector, yielding each element to a closure.

Arguments

Examples

[1,2,3].each(|&i| {
    io::println(int::str(i));
    true
});
[1,2,3,4,5].each(|&i| {
    if i < 4 {
        io::println(int::str(i));
        true
    }
    else {
        false
    }
});

You probably will want to use each with a for/do expression, depending on your iteration needs:

for [1,2,3].each |&i| {
    io::println(int::str(i));
}

Function each2

fn each2<U, T>(v1: &[U], v2: &[T], f: &fn(u: &U, t: &T) -> bool)

Iterates over two vectors simultaneously

Failure

Both vectors must have the same length

Function each_const

fn each_const<T>(v: &const [T], f: &fn(elem: &const T) -> bool)

Like each(), but for the case where you have a vector that may or may not have mutable contents.

Function each_mut

fn each_mut<'r, T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool)

Like each(), but for the case where you have a vector with mutable contents and you would like to mutate the contents as you iterate.

Function each_permutation

fn each_permutation<T: Copy>(v: &[T], put: &fn(ts: &[T]) -> 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 len(v)!. If v contains repeated elements, then some permutations are repeated.

Function each_reverse

fn each_reverse<'r, T>(v: &'r [T], blk: &fn(v: &'r T) -> bool)

Iterates over a vector's elements in reverse

Return true to continue, false to break.

Function eachi

fn eachi<'r, T>(v: &'r [T], f: &fn(uint, v: &'r T) -> bool)

Iterates over a vector's elements and indices

Return true to continue, false to break.

Function eachi_reverse

fn eachi_reverse<'r, T>(v: &'r [T], blk: &fn(i: uint, v: &'r T) -> bool)

Iterates over a vector's elements and indices in reverse

Return true to continue, false to break.

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 find

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

Search for the first element that matches a given predicate

Apply function f to each element of v, starting from the first. When function f returns true then an option containing the element is returned. If f matches no elements then none is returned.

Function find_between

fn find_between<T: Copy>(v: &[T], start: uint, end: uint,
                         f: &fn(t: &T) -> bool) -> Option<T>

Search for the first element that matches a given predicate within a range

Apply function f to each element of v within the range [start, end). When function f returns true then an option containing the element is returned. If f matches no elements then none is returned.

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 foldl

fn foldl<T, U>(z: T, v: &[U], p: &fn(t: T, u: &U) -> T) -> T

Reduces a vector from left to right.

Arguments

Examples

Sum all values in the vector [1, 2, 3]:

vec::foldl(0, [1, 2, 3], |a, b| a + *b);

Function foldr

fn foldr<T, U: Copy>(v: &[T], z: U, p: &fn(t: &T, u: U) -> U) -> U

Reduces a vector from right to left. Note that the argument order is reversed compared to foldl to reflect the order they are provided to the closure.

Arguments

Examples

Sum all values in the vector [1, 2, 3]:

vec::foldr([1, 2, 3], 0, |a, b| a + *b);

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 immutable vector.

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

Function from_fn

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

Creates and initializes an immutable vector.

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

Function from_slice

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

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

Function grow

fn grow<T: Copy>(v: &mut ~[T], n: uint, initval: &T)

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

Arguments

Function grow_fn

fn grow_fn<T>(v: &mut ~[T], n: uint, op: iter::InitOp<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

Function grow_set

fn grow_set<T: Copy>(v: &mut ~[T], 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.

Function head

fn head<'r, T>(v: &'r [T]) -> &'r T

Returns the first element of a vector

Function head_opt

fn head_opt<'r, T>(v: &'r [T]) -> Option<&'r T>

Returns Some(x) where x is the first element of the slice v, or None if the vector is empty.

Function init

fn init<'r, T>(v: &'r [T]) -> &'r [T]

Returns a vector containing all but the last element of a slice

Function initn

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

Returns a vector containing all but the last `n' elements of a slice

Function insert

fn insert<T>(v: &mut ~[T], i: uint, x: T)

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

Function is_empty

fn is_empty<T>(v: &const [T]) -> bool

Returns true if a vector contains no elements

Function last

fn last<'r, T>(v: &'r [T]) -> &'r T

Returns the last element of the slice v, failing if the slice is empty.

Function last_opt

fn last_opt<'r, T>(v: &'r [T]) -> Option<&'r T>

Returns Some(x) where x is the last element of the slice v, or None if the vector is empty.

Function len

fn len<T>(v: &const [T]) -> uint

Returns the length of a vector

Function map

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

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

Function map2

fn map2<T: Copy, U: Copy, V>(v0: &[T], v1: &[U], f: &fn(t: &T, v: &U) -> V) ->
 ~[V]

Apply a function to each pair of elements and return the results

Function map_consume

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

Function mapi

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

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

Function mut_slice

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

Return a slice that points into another slice.

Function partition

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

Partitions a vector into two new vectors: those that satisfies the predicate, and those that do not.

Function partitioned

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

Partitions a vector into two new vectors: those that satisfies the predicate, and those that do not.

Function pop

fn pop<T>(v: &mut ~[T]) -> T

Remove the last element from a vector and return it

Function position

fn position<T>(v: &[T], f: &fn(t: &T) -> bool) -> Option<uint>

Find the first index matching some predicate

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

Function position_between

fn position_between<T>(v: &[T], start: uint, end: uint, f: &fn(t: &T) -> bool)
 -> Option<uint>

Find the first index matching some predicate within a range

Apply function f to each element of v between the range [start, end). When function f returns true then an option containing the index is returned. If f matches no elements then none is returned.

Function position_elem

fn position_elem<T: Eq>(v: &[T], x: &T) -> Option<uint>

Find the first index containing a matching value

Function push

fn push<T>(v: &mut ~[T], initval: T)

Append an element to a vector

Function push_all

fn push_all<T: Copy>(v: &mut ~[T], rhs: &const [T])

Function push_all_move

fn push_all_move<T>(v: &mut ~[T], mut rhs: ~[T])

Function remove

fn remove<T>(v: &mut ~[T], i: uint) -> T

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

Function reserve

fn reserve<T>(v: &mut ~[T], n: uint)

Reserves capacity for exactly n elements in the given vector.

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

Arguments

Function reserve_at_least

fn reserve_at_least<T>(v: &mut ~[T], 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 v is already equal to or greater than the requested capacity, then no action is taken.

Arguments

Function retain

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

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

Function reverse

fn reverse<T>(v: &mut [T])

Reverse the order of elements in a vector, in place

Function reversed

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

Returns a vector with the order of elements reversed

Function rfind

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

Search for the last element that matches a given predicate

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

Function rfind_between

fn rfind_between<T: Copy>(v: &[T], start: uint, end: uint,
                          f: &fn(t: &T) -> bool) -> Option<T>

Search for the last element that matches a given predicate within a range

Apply function f to each element of v in reverse order within the range [start, end). When function f returns true then an option containing the element is returned. If f matches no elements then none is return.

Function rposition

fn rposition<T>(v: &[T], 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.

Function rposition_between

fn rposition_between<T>(v: &[T], start: uint, end: uint,
                        f: &fn(t: &T) -> bool) -> Option<uint>

Find the last index matching some predicate within a range

Apply function f to each element of v in reverse order between the range [start, end). When function f returns true then an option containing the index is returned. If f matches no elements then none is returned.

Function rposition_elem

fn rposition_elem<T: Eq>(v: &[T], x: &T) -> Option<uint>

Find the last index containing a matching value

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: &const [T], ys: &const [U]) -> bool

Returns true if two vectors have the same length

Function shift

fn shift<T>(v: &mut ~[T]) -> T

Removes the first element from a vector and return it

Function slice

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

Return a slice that points into another slice.

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 swap

fn swap<T>(v: &mut [T], a: uint, b: uint)

Swaps two elements in a vector

Arguments

Function swap_remove

fn swap_remove<T>(v: &mut ~[T], 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.

Function tail

fn tail<'r, T>(v: &'r [T]) -> &'r [T]

Returns a vector containing all but the first element of a slice

Function tailn

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

Returns a vector containing all but the first n elements of a slice

Function truncate

fn truncate<T>(v: &mut ~[T], newlen: uint)

Shorten a vector, dropping excess elements.

Function uniq_len

fn uniq_len<T>(v: &const ~[T]) -> uint

Function unshift

fn unshift<T>(v: &mut ~[T], x: T)

Prepend an element to the vector

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<TT: Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]]

Function with_capacity

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

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 contains the i-th elements from each of the input vectors.

Function zip_slice

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

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