Vectors
init_op
- A function used to initialize the elements of a vectorextensions for ~[T]
extensions for ~[mut T]
extensions for & [const T]
- Extension methods for vectorsextensions for & [const T]
- Extension methods for vectorsextensions for & [T]
- Extension methods for vectorsextensions for & [T]
- Extension methods for vectorsextensions of iter::base_iter<A> for & [const A]
extensions for & [const A]
all
- Return true if a predicate matches all elementsall2
- Return true if a predicate matches all elements in both vectors.alli
- Return true if a predicate matches all elementsany
- Return true if a predicate matches any elementsany2
- Return true if a predicate matches any elements in both vectors.append
append_one
as_buf
- Work with the buffer of a vector.as_mut_buf
capacity
- Returns the number of elements the vector can hold without reallocatingconcat
- Concatenate a vector of vectors.connect
- Concatenate a vector of vectors, placing a given separator between eachconsume
contains
- Return true if a vector contains an element with the given valuecount
- Returns the number of elements that are equal to a given valueeach
- Iterates over a vector, with option to breakeachi
- Iterates over a vector's elements and indicesfilter
- Construct a new vector from the elements of a vector for which some predicate holds.filter_map
- Apply a function to each element of a vector and return the resultsfind
- Search for the first element that matches a given predicatefind_between
- Search for the first element that matches a given predicate within a rangeflat_map
- Apply a function to each element of a vector and return a concatenation of each result vectorfoldl
- Reduce a vector from left to rightfoldr
- Reduce a vector from right to leftfrom_elem
- Creates and initializes an immutable vector.from_fn
- Creates and initializes an immutable vector.from_mut
- Produces an immutable vector from a mut vector.grow
- Expands a vector in place, initializing the new elements to a given valuegrow_fn
- Expands a vector in place, initializing the new elements to the result of a functiongrow_set
- Sets the value of a vector element at a given index, growing the vector as neededhead
- Returns the first element of a vectorinit
- Returns a vector containing all but the last element of a sliceis_empty
- Returns true if a vector contains no elementsis_not_empty
- Returns true if a vector contains some elementsiter
- Iterates over a sliceiter2
- Iterates over two vectors simultaneouslyiter_between
iteri
- Iterates over a vector's elements and indexeslast
- Returns the last element of the slice v
, failing if the slice is empty.last_opt
- Returns some(x)
where x
is the last element of the slice v
, or none
if the vector is empty.len
- Returns the length of a vectormap
- Apply a function to each element of a vector and return the resultsmap2
- Apply a function to each pair of elements and return the resultsmap_consume
mapi
- Apply a function to each element of a vector and return the resultspermute
- Iterate over all permutations of vector v
.pop
- Remove the last element from a vector and return itposition
- Find the first index matching some predicateposition_between
- Find the first index matching some predicate within a rangeposition_elem
- Find the first index containing a matching valuepush
- Append an element to a vectorpush_all
push_all_move
reserve
- Reserves capacity for exactly n
elements in the given vector.reserve_at_least
- Reserves capacity for at least n
elements in the given vector.reverse
- Reverse the order of elements in a vector, in placereversed
- Returns a vector with the order of elements reversedrfind
- Search for the last element that matches a given predicaterfind_between
- Search for the last element that matches a given predicate within a rangeriter
- Iterates over a vector in reverseriteri
- Iterates over a vector's elements and indexes in reverserposition
- Find the last index matching some predicaterposition_between
- Find the last index matching some predicate within a rangersplit
- Reverse split the vector v
by applying each element against the predicate f
.rsplitn
- Reverse split the vector v
by applying each element against the predicate f
up to `n times.same_length
- Returns true if two vectors have the same lengthshift
- Removes the first element from a vector and return itslice
- Returns a copy of the elements from [start
..end
) from v
.split
- Split the vector v
by applying each element against the predicate f
.splitn
- Split the vector v
by applying each element against the predicate f
up to n
times.swap
- Swaps two elements in a vectortail
- Returns a vector containing all but the first element of a slicetailn
- Returns a vector containing all but the first n
\ elements of a sliceto_mut
- Produces a mut vector from an immutable vector.unpack_const_slice
- Work with the buffer and length of a slice.unpack_slice
- Work with the buffer and length of a slice.unshift
- Prepend an element to the vectorunzip
- Convert a vector of pairs into a pair of vectorsview
- Return a slice that points into another slice.windowed
zip
- Convert two vectors to a vector of pairsvec::u8
- Operations on [u8]
vec::unsafe
- Unsafe operationsinit_op
type init_op<T> = fn(uint) -> T
A function used to initialize the elements of a vector
extensions for ~[T]
+
pure fn +(rhs: & [const T]) -> ~[T]
extensions for ~[mut T]
+
pure fn +(rhs: & [const T]) -> ~[mut T]
extensions for & [const T]
Extension methods for vectors
is_empty
pure fn is_empty() -> bool
Returns true if a vector contains no elements
is_not_empty
pure fn is_not_empty() -> bool
Returns true if a vector contains some elements
len
pure fn len() -> uint
Returns the length of a vector
extensions for & [const T]
Extension methods for vectors
head
pure fn head() -> T
Returns the first element of a vector
init
pure fn init() -> ~[T]
Returns all but the last elemnt of a vector
last
pure fn last() -> T
Returns the last element of a v
, failing if the vector is empty.
slice
pure fn slice(start: uint, end: uint) -> ~[T]
Returns a copy of the elements from [start
..end
) from v
.
tail
pure fn tail() -> ~[T]
Returns all but the first element of a vector
extensions for & [T]
Extension methods for vectors
foldr
pure fn foldr<U: copy>(z: U, p: fn(T, U) -> U) -> U
Reduce a vector from right to left
iter
pure fn iter(f: fn(T))
Iterates over a vector
Iterates over vector v
and, for each element, calls function f
with the element's value.
iteri
pure fn iteri(f: fn(uint, T))
Iterates over a vector's elements and indexes
Iterates over vector v
and, for each element, calls function f
with the element's value and index.
position
pure fn position(f: fn(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.
position_elem
pure fn position_elem(x: T) -> option<uint>
Find the first index containing a matching value
riter
pure fn riter(f: fn(T))
Iterates over a vector in reverse
Iterates over vector v
and, for each element, calls function f
with the element's value.
riteri
pure fn riteri(f: fn(uint, T))
Iterates over a vector's elements and indexes in reverse
Iterates over vector v
and, for each element, calls function f
with the element's value and index.
rposition
pure fn rposition(f: fn(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.
rposition_elem
pure fn rposition_elem(x: T) -> option<uint>
Find the last index containing a matching value
map
pure fn map<U>(f: fn(T) -> U) -> ~[U]
Apply a function to each element of a vector and return the results
mapi
pure fn mapi<U>(f: fn(uint, T) -> U) -> ~[U]
Apply a function to the index and value of each element in the vector and return the results
map_r
fn map_r<U>(f: fn(x: &self .T) -> U) -> ~[U]
alli
pure fn alli(f: fn(uint, T) -> bool) -> bool
Returns true if the function returns true for all elements.
If the vector is empty, true is returned.
flat_map
pure fn flat_map<U>(f: fn(T) -> ~[U]) -> ~[U]
Apply a function to each element of a vector and return a concatenation of each result vector
filter_map
pure fn filter_map<U: copy>(f: fn(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.
extensions for & [T]
Extension methods for vectors
filter
pure fn filter(f: fn(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.
find
pure fn find(f: fn(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.
rfind
pure fn rfind(f: fn(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.
extensions of iter::base_iter<A> for & [const A]
each
fn each(blk: fn(A) -> bool)
size_hint
fn size_hint() -> option<uint>
eachi
fn eachi(blk: fn(uint, A) -> bool)
all
fn all(blk: fn(A) -> bool) -> bool
any
fn any(blk: fn(A) -> bool) -> bool
foldl
fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B
contains
fn contains(x: A) -> bool
count
fn count(x: A) -> uint
extensions for & [const A]
filter_to_vec
fn filter_to_vec(pred: fn(A) -> bool) -> ~[A]
map_to_vec
fn map_to_vec<B>(op: fn(A) -> B) -> ~[B]
to_vec
fn to_vec() -> ~[A]
min
fn min() -> A
max
fn max() -> A
all
pure fn all<T>(v: & [T], f: fn(T) -> bool) -> bool
Return true if a predicate matches all elements
If the vector contains no elements then true is returned.
all2
pure fn all2<T, U>(v0: & [T], v1: & [U], f: fn(T, 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.
alli
pure fn alli<T>(v: & [T], f: fn(uint, T) -> bool) -> bool
Return true if a predicate matches all elements
If the vector contains no elements then true is returned.
any
pure fn any<T>(v: & [T], f: fn(T) -> bool) -> bool
Return true if a predicate matches any elements
If the vector contains no elements then false is returned.
any2
pure fn any2<T, U>(v0: & [T], v1: & [U], f: fn(T, U) -> bool) -> bool
Return true if a predicate matches any elements in both vectors.
If the vectors contains no elements then false is returned.
append
pure fn append<T: copy>(+lhs: ~[T], rhs: & [const T]) -> ~[T]
append_one
pure fn append_one<T>(+lhs: ~[T], +x: T) -> ~[T]
as_buf
fn as_buf<E, T>(v: & [E], f: fn(*E) -> T) -> T
Work with the buffer of a vector.
Allows for unsafe manipulation of vector contents, which is useful for foreign interop.
as_mut_buf
fn as_mut_buf<E, T>(v: & [mut E], f: fn(*mut E) -> T) -> T
capacity
pure fn capacity<T>(&&v: ~[const T]) -> uint
Returns the number of elements the vector can hold without reallocating
concat
pure 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.
connect
pure fn connect<T: copy>(v: & [~[T]], sep: T) -> ~[T]
Concatenate a vector of vectors, placing a given separator between each
consume
fn consume<T>(+v: ~[T], f: fn(uint, +T))
contains
pure fn contains<T>(v: & [T], x: T) -> bool
Return true if a vector contains an element with the given value
count
pure fn count<T>(v: & [T], x: T) -> uint
Returns the number of elements that are equal to a given value
each
pure fn each<T>(v: & [const T], f: fn(T) -> bool)
Iterates over a vector, with option to break
Return true to continue, false to break.
eachi
pure fn eachi<T>(v: & [const T], f: fn(uint, T) -> bool)
Iterates over a vector's elements and indices
Return true to continue, false to break.
filter
pure fn filter<T: copy>(v: & [T], f: fn(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.
filter_map
pure fn filter_map<T, U: copy>(v: & [T], f: fn(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.
find
pure fn find<T: copy>(v: & [T], f: fn(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.
find_between
pure fn find_between<T: copy>(v: & [T], start: uint, end: uint,
f: fn(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.
flat_map
pure fn flat_map<T, U>(v: & [T], f: fn(T) -> ~[U]) -> ~[U]
Apply a function to each element of a vector and return a concatenation of each result vector
foldl
pure fn foldl<T: copy, U>(z: T, v: & [U], p: fn(T, U) -> T) -> T
Reduce a vector from left to right
foldr
pure fn foldr<T, U: copy>(v: & [T], z: U, p: fn(T, U) -> U) -> U
Reduce a vector from right to left
from_elem
pure 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
.
from_fn
pure fn from_fn<T>(n_elts: uint, op: init_op<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
.
from_mut
fn from_mut<T>(+v: ~[mut T]) -> ~[T]
Produces an immutable vector from a mut vector.
grow
fn grow<T: copy>(&v: ~[const T], n: uint, initval: T)
Expands a vector in place, initializing the new elements to a given value
grow_fn
fn grow_fn<T>(&v: ~[const T], n: uint, op: init_op<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
)
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.
head
pure fn head<T: copy>(v: & [const T]) -> T
Returns the first element of a vector
init
pure fn init<T: copy>(v: & [const T]) -> ~[T]
Returns a vector containing all but the last element of a slice
is_empty
pure fn is_empty<T>(v: & [const T]) -> bool
Returns true if a vector contains no elements
is_not_empty
pure fn is_not_empty<T>(v: & [const T]) -> bool
Returns true if a vector contains some elements
iter
pure fn iter<T>(v: & [T], f: fn(T))
Iterates over a slice
Iterates over slice v
and, for each element, calls function f
with the element's value.
iter2
fn iter2<U, T>(v1: & [U], v2: & [T], f: fn(U, T))
Iterates over two vectors simultaneously
Both vectors must have the same length
iter_between
pure fn iter_between<T>(v: & [T], start: uint, end: uint, f: fn(T))
iteri
pure fn iteri<T>(v: & [T], f: fn(uint, T))
Iterates over a vector's elements and indexes
Iterates over vector v
and, for each element, calls function f
with the element's value and index.
last
pure fn last<T: copy>(v: & [const T]) -> T
Returns the last element of the slice v
, failing if the slice is empty.
last_opt
pure fn last_opt<T: copy>(v: & [const T]) -> option<T>
Returns some(x)
where x
is the last element of the slice v
, or none
if the vector is empty.
len
pure fn len<T>(&&v: & [const T]) -> uint
Returns the length of a vector
map
pure fn map<T, U>(v: & [T], f: fn(T) -> U) -> ~[U]
Apply a function to each element of a vector and return the results
map2
pure fn map2<T: copy, U: copy, V>(v0: & [T], v1: & [U], f: fn(T, U) -> V) ->
~[V]
Apply a function to each pair of elements and return the results
map_consume
fn map_consume<T, U>(+v: ~[T], f: fn(+T) -> U) -> ~[U]
mapi
pure fn mapi<T, U>(v: & [T], f: fn(uint, T) -> U) -> ~[U]
Apply a function to each element of a vector and return the results
permute
pure fn permute<T: copy>(v: & [T], put: fn(~[T]))
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.
pop
fn pop<T>(&v: ~[const T]) -> T
Remove the last element from a vector and return it
position
pure fn position<T>(v: & [T], f: fn(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.
position_between
pure fn position_between<T>(v: & [T], start: uint, end: uint,
f: fn(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.
position_elem
pure fn position_elem<T>(v: & [T], x: T) -> option<uint>
Find the first index containing a matching value
push
fn push<T>(&v: ~[const T], +initval: T)
Append an element to a vector
push_all
fn push_all<T: copy>(&v: ~[const T], rhs: & [const T])
push_all_move
fn push_all_move<T>(&v: ~[const T], -rhs: ~[const T])
reserve
fn reserve<T>(&v: ~[const 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.
reserve_at_least
fn reserve_at_least<T>(&v: ~[const 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.
reverse
fn reverse<T>(v: ~[mut T])
Reverse the order of elements in a vector, in place
reversed
pure fn reversed<T: copy>(v: & [const T]) -> ~[T]
Returns a vector with the order of elements reversed
rfind
pure fn rfind<T: copy>(v: & [T], f: fn(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.
rfind_between
pure fn rfind_between<T: copy>(v: & [T], start: uint, end: uint,
f: fn(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 returned.
riter
pure fn riter<T>(v: & [T], f: fn(T))
Iterates over a vector in reverse
Iterates over vector v
and, for each element, calls function f
with the element's value.
riteri
pure fn riteri<T>(v: & [T], f: fn(uint, T))
Iterates over a vector's elements and indexes in reverse
Iterates over vector v
and, for each element, calls function f
with the element's value and index.
rposition
pure fn rposition<T>(v: & [T], f: fn(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.
rposition_between
pure fn rposition_between<T>(v: & [T], start: uint, end: uint,
f: fn(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.
rsplit
fn rsplit<T: copy>(v: & [T], f: fn(T) -> bool) -> ~[~[T]]
Reverse split the vector v
by applying each element against the predicate f
.
rsplitn
fn rsplitn<T: copy>(v: & [T], n: uint, f: fn(T) -> bool) -> ~[~[T]]
Reverse split the vector v
by applying each element against the predicate f
up to `n times.
same_length
pure fn same_length<T, U>(xs: & [const T], ys: & [const U]) -> bool
Returns true if two vectors have the same length
shift
fn shift<T>(&v: ~[T]) -> T
Removes the first element from a vector and return it
slice
pure fn slice<T: copy>(v: & [const T], start: uint, end: uint) -> ~[T]
Returns a copy of the elements from [start
..end
) from v
.
split
fn split<T: copy>(v: & [T], f: fn(T) -> bool) -> ~[~[T]]
Split the vector v
by applying each element against the predicate f
.
splitn
fn splitn<T: copy>(v: & [T], n: uint, f: fn(T) -> bool) -> ~[~[T]]
Split the vector v
by applying each element against the predicate f
up to n
times.
swap
fn swap<T>(&&v: ~[mut T], a: uint, b: uint)
Swaps two elements in a vector
tail
pure fn tail<T: copy>(v: & [const T]) -> ~[T]
Returns a vector containing all but the first element of a slice
tailn
pure fn tailn<T: copy>(v: & [const T], n: uint) -> ~[T]
Returns a vector containing all but the first n
\ elements of a slice
to_mut
fn to_mut<T>(+v: ~[T]) -> ~[mut T]
Produces a mut vector from an immutable vector.
unpack_const_slice
pure fn unpack_const_slice<T, U>(s: & [const T], f: fn(*const T, uint) -> U)
-> U
Work with the buffer and length of a slice.
unpack_slice
pure fn unpack_slice<T, U>(s: & [const T], f: fn(*T, uint) -> U) -> U
Work with the buffer and length of a slice.
unshift
fn unshift<T>(&v: ~[T], +x: T)
Prepend an element to the vector
unzip
pure fn unzip<T: copy, U: copy>(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.
view
pure fn view<T>(v: & [const T], start: uint, end: uint) -> &a [T]
Return a slice that points into another slice.
windowed
pure fn windowed<TT: copy>(nn: uint, xx: & [TT]) -> ~[~[TT]]
zip
pure fn zip<T: copy, U: copy>(v: & [const T], u: & [const 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.