Vectors
UnboxedVecRepr
- The internal 'unboxed' representation of a vectorCopyableVector
ImmutableCopyableVector
ImmutableEqVector
ImmutableVector
OwnedCopyableVector
OwnedVector
of Eq for &'self [T] where <'self, T: Eq>
of Eq for ~[T] where <T: Eq>
of Eq for @[T] where <T: Eq>
of TotalEq for &'self [T] where <'self, T: TotalEq>
of TotalEq for ~[T] where <T: TotalEq>
of TotalEq for @[T] where <T: TotalEq>
of Equiv<~[T]> for &'self [T] where <'self, T: Eq>
of TotalOrd for &'self [T] where <'self, T: TotalOrd>
of TotalOrd for ~[T] where <T: TotalOrd>
of TotalOrd for @[T] where <T: TotalOrd>
of Ord for &'self [T] where <'self, T: Ord>
of Ord for ~[T] where <T: Ord>
of Ord for @[T] where <T: Ord>
of Container for &'self const [T] where <'self, T>
of CopyableVector<T> for &'self const [T] where <'self, T: Copy>
- Extension methods for vectorsof ImmutableVector<T> for &'self [T] where <'self, T>
- Extension methods for vectorsof ImmutableEqVector<T> for &'self [T] where <'self, T: Eq>
of ImmutableCopyableVector<T> for &'self [T] where <'self, T: Copy>
- Extension methods for vectorsof OwnedVector<T> for ~[T] where <T>
of Mutable for ~[T] where <T>
of OwnedCopyableVector<T> for ~[T] where <T: Copy>
of OwnedEqVector<T> for ~[T] where <T: Eq>
of iter::BaseIter<A> for &'self [A] where <'self, A>
of iter::BaseIter<A> for ~[A] where <A>
of iter::BaseIter<A> for @[A] where <A>
of iter::MutableIter<A> for &'self mut [A] where <'self, A>
of iter::MutableIter<A> for ~[A] where <A>
of iter::MutableIter<A> for @mut [A] where <A>
of iter::ExtendedIter<A> for &'self [A] where <'self, A>
of iter::ExtendedIter<A> for ~[A] where <A>
of iter::ExtendedIter<A> for @[A] where <A>
of iter::EqIter<A> for &'self [A] where <'self, A: Eq>
of iter::EqIter<A> for ~[A] where <A: Eq>
of iter::EqIter<A> for @[A] where <A: Eq>
of iter::CopyableIter<A> for &'self [A] where <'self, A: Copy>
of iter::CopyableIter<A> for ~[A] where <A: Copy>
of iter::CopyableIter<A> for @[A] where <A: Copy>
of iter::CopyableOrderedIter<A> for &'self [A] where <'self, A: Copy + Ord>
of iter::CopyableOrderedIter<A> for ~[A] where <A: Copy + Ord>
of iter::CopyableOrderedIter<A> for @[A] where <A: Copy + Ord>
of iter::CopyableNonstrictIter<A> for &'self [A] where <'self, A: Copy>
of iter::CopyableNonstrictIter<A> for ~[A] where <A: Copy>
of iter::CopyableNonstrictIter<A> for @[A] where <A: Copy>
of Clone for ~[A] where <A: Clone>
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_const_buf
- Similar to as_imm_buf
but passing a *const T
as_imm_buf
- Work with the buffer of a vector.as_mut_buf
- Similar to as_imm_buf
but passing a *mut T
build
- Builds a vector by calling a provided function with an argument function that pushes an element to the back of a vector.build_sized
- Builds a vector by calling a provided function with an argument function that pushes an element to the back of a vectorbuild_sized_opt
- Builds a vector by calling a provided function with an argument function that pushes an element to the back of a vectorcapacity
- 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 eachconst_slice
- Return a slice that points into another slice.consume
consume_reverse
contains
- Return true if a vector contains an element with the given valuecount
- Returns the number of elements that are equal to a given valuededup
- Remove consecutive repeated elements from a vector; if the vector is sorted, this removes all duplicates.each
- Iterates over a vector, yielding each element to a closure.each2
- Iterates over two vectors simultaneouslyeach_const
- Like each()
, but for the case where you have a vector that may or may not have mutable contents.each_mut
each_permutation
- Iterate over all permutations of vector v
.each_reverse
- Iterates over a vector's elements in reverseeachi
- Iterates over a vector's elements and indiceseachi_reverse
- Iterates over a vector's elements and indices in reversefilter
- 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 resultsfilter_mapped
- Like filter_map()
, but operates on a borrowed slice and does not consume the input.filtered
- Construct a new vector from the elements of a vector for which some predicate holds.find
- 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
- Reduces a vector from left to right.foldr
- Reduces a vector from right to leftfrom_buf
- Constructs a vector from an unsafe pointer to a bufferfrom_elem
- Creates and initializes an immutable vector.from_fn
- Creates and initializes an immutable vector.from_slice
- Creates a new unique vector with the same contents as the slicegrow
- 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 vectorhead_opt
- Returns Some(x)
where x
is the first element of the slice v
, or None
if the vector is empty.init
- Returns a vector containing all but the last element of a sliceinitn
- Returns a vector containing all but the last `n' elements of a sliceinsert
- Insert an element at position i within v, shifting all elements after position i one position to the right.is_empty
- Returns true if a vector contains no elementslast
- 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 resultsmut_slice
- Return a slice that points into another slice.partition
- Partitions a vector into two new vectors: those that satisfies the predicate, and those that do not.partitioned
- Partitions a vector into two new vectors: those that satisfies the predicate, and those that do not.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
remove
- Remove and return the element at position i within v, shifting all elements after position i one position to the left.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.retain
- Like filter()
, but in placereverse
- 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 rangerposition
- Find the last index matching some predicaterposition_between
- Find the last index matching some predicate within a rangerposition_elem
- Find the last index containing a matching valuersplit
- 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
- Return a slice that points into another slice.split
- Copies 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 vectorswap_remove
- Remove an element from anywhere in the vector and return it, replacing it with the last elementtail
- Returns a vector containing all but the first element of a slicetailn
- Returns a vector containing all but the first n
elements of a slicetruncate
- Shorten a vector, dropping excess elements.uniq_len
unshift
- Prepend an element to the vectorunzip
- Convert a vector of pairs into a pair of vectors.unzip_slice
- Convert a vector of pairs into a pair of vectors, by referencewindowed
with_capacity
zip
- Convert two vectors to a vector of pairs.zip_slice
- Convert two vectors to a vector of pairs, by referencevec::bytes
- Operations on [u8]
vec::raw
- Unsafe operationsvec::rustrt
vec::traits
UnboxedVecRepr
pub struct UnboxedVecRepr {
mut fill: uint,
mut alloc: uint,
data: u8,
}
The internal 'unboxed' representation of a vector
CopyableVector
to_owned
fn to_owned(&self) -> ~[T]
ImmutableCopyableVector
filtered
fn filtered(&self, f: &fn(&T) -> bool) -> ~[T]
rfind
fn rfind(&self, f: &fn(t: &T) -> bool) -> Option<T>
partitioned
fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T])
ImmutableEqVector
position
fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint>
position_elem
fn position_elem(&self, t: &T) -> Option<uint>
rposition
fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint>
rposition_elem
fn rposition_elem(&self, t: &T) -> Option<uint>
ImmutableVector
slice
fn slice(&self, start: uint, end: uint) -> &'self [T]
head
fn head(&self) -> &'self T
head_opt
fn head_opt(&self) -> Option<&'self T>
tail
fn tail(&self) -> &'self [T]
tailn
fn tailn(&self, n: uint) -> &'self [T]
init
fn init(&self) -> &'self [T]
initn
fn initn(&self, n: uint) -> &'self [T]
last
fn last(&self) -> &'self T
last_opt
fn last_opt(&self) -> Option<&'self T>
each_reverse
fn each_reverse(&self, blk: &fn(&T) -> bool)
eachi_reverse
fn eachi_reverse(&self, blk: &fn(uint, &T) -> bool)
foldr
fn foldr<U: Copy>(&self, z: U, p: &fn(t: &T, u: U) -> U) -> U
map
fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U]
mapi
fn mapi<U>(&self, f: &fn(uint, t: &T) -> U) -> ~[U]
map_r
fn map_r<U>(&self, f: &fn(x: &T) -> U) -> ~[U]
alli
fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool
flat_map
fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U]
filter_mapped
fn filter_mapped<U: Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U]
OwnedCopyableVector
push_all
fn push_all(&mut self, rhs: &const [T])
grow
fn grow(&mut self, n: uint, initval: &T)
grow_set
fn grow_set(&mut self, index: uint, initval: &T, val: T)
OwnedVector
push
fn push(&mut self, t: T)
push_all_move
fn push_all_move(&mut self, rhs: ~[T])
pop
fn pop(&mut self) -> T
shift
fn shift(&mut self) -> T
unshift
fn unshift(&mut self, x: T)
insert
fn insert(&mut self, i: uint, x: T)
remove
fn remove(&mut self, i: uint) -> T
swap_remove
fn swap_remove(&mut self, index: uint) -> T
truncate
fn truncate(&mut self, newlen: uint)
retain
fn retain(&mut self, f: &fn(t: &T) -> bool)
consume
fn consume(self, f: &fn(uint, v: T))
consume_reverse
fn consume_reverse(self, f: &fn(uint, v: T))
filter
fn filter(self, f: &fn(t: &T) -> bool) -> ~[T]
partition
fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T])
grow_fn
fn grow_fn(&mut self, n: uint, op: iter::InitOp<T>)
Eq
for &'self [T]
where <'self, T: Eq>
eq
fn eq(&self, other: &&'self [T]) -> bool
ne
fn ne(&self, other: &&'self [T]) -> bool
Eq
for ~[T]
where <T: Eq>
eq
fn eq(&self, other: &~[T]) -> bool
ne
fn ne(&self, other: &~[T]) -> bool
Eq
for @[T]
where <T: Eq>
eq
fn eq(&self, other: &@[T]) -> bool
ne
fn ne(&self, other: &@[T]) -> bool
TotalEq
for &'self [T]
where <'self, T: TotalEq>
equals
fn equals(&self, other: &&'self [T]) -> bool
TotalEq
for ~[T]
where <T: TotalEq>
equals
fn equals(&self, other: &~[T]) -> bool
TotalEq
for @[T]
where <T: TotalEq>
equals
fn equals(&self, other: &@[T]) -> bool
Equiv<~[T]>
for &'self [T]
where <'self, T: Eq>
equiv
fn equiv(&self, other: &~[T]) -> bool
TotalOrd
for &'self [T]
where <'self, T: TotalOrd>
cmp
fn cmp(&self, other: &&'self [T]) -> Ordering
TotalOrd
for ~[T]
where <T: TotalOrd>
cmp
fn cmp(&self, other: &~[T]) -> Ordering
TotalOrd
for @[T]
where <T: TotalOrd>
cmp
fn cmp(&self, other: &@[T]) -> Ordering
Ord
for &'self [T]
where <'self, T: Ord>
lt
fn lt(&self, other: &&'self [T]) -> bool
le
fn le(&self, other: &&'self [T]) -> bool
ge
fn ge(&self, other: &&'self [T]) -> bool
gt
fn gt(&self, other: &&'self [T]) -> bool
Ord
for ~[T]
where <T: Ord>
lt
fn lt(&self, other: &~[T]) -> bool
le
fn le(&self, other: &~[T]) -> bool
ge
fn ge(&self, other: &~[T]) -> bool
gt
fn gt(&self, other: &~[T]) -> bool
Ord
for @[T]
where <T: Ord>
lt
fn lt(&self, other: &@[T]) -> bool
le
fn le(&self, other: &@[T]) -> bool
ge
fn ge(&self, other: &@[T]) -> bool
gt
fn gt(&self, other: &@[T]) -> bool
Container
for &'self const [T]
where <'self, T>
is_empty
fn is_empty(&const self) -> bool
Returns true if a vector contains no elements
len
fn len(&const self) -> uint
Returns the length of a vector
CopyableVector<T>
for &'self const [T]
where <'self, T: Copy>
Extension methods for vectors
to_owned
fn to_owned(&self) -> ~[T]
Returns a copy of v
.
ImmutableVector<T>
for &'self [T]
where <'self, T>
Extension methods for vectors
slice
fn slice(&self, start: uint, end: uint) -> &'self [T]
Return a slice that points into another slice.
head
fn head(&self) -> &'self T
Returns the first element of a vector, failing if the vector is empty.
head_opt
fn head_opt(&self) -> Option<&'self T>
Returns the first element of a vector
tail
fn tail(&self) -> &'self [T]
Returns all but the first element of a vector
tailn
fn tailn(&self, n: uint) -> &'self [T]
Returns all but the first `n' elements of a vector
init
fn init(&self) -> &'self [T]
Returns all but the last elemnt of a vector
initn
fn initn(&self, n: uint) -> &'self [T]
Returns all but the last `n' elemnts of a vector
last
fn last(&self) -> &'self T
Returns the last element of a v
, failing if the vector is empty.
last_opt
fn last_opt(&self) -> Option<&'self T>
Returns the last element of a v
, failing if the vector is empty.
each_reverse
fn each_reverse(&self, blk: &fn(&T) -> bool)
Iterates over a vector's elements in reverse.
eachi_reverse
fn eachi_reverse(&self, blk: &fn(uint, &T) -> bool)
Iterates over a vector's elements and indices in reverse.
foldr
fn foldr<U: Copy>(&self, z: U, p: &fn(t: &T, u: U) -> U) -> U
Reduce a vector from right to left
map
fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U]
Apply a function to each element of a vector and return the results
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
map_r
fn map_r<U>(&self, f: &fn(x: &T) -> U) -> ~[U]
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.
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
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.
ImmutableEqVector<T>
for &'self [T]
where <'self, T: Eq>
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.
position_elem
fn position_elem(&self, x: &T) -> Option<uint>
Find the first index containing a matching value
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.
rposition_elem
fn rposition_elem(&self, t: &T) -> Option<uint>
Find the last index containing a matching value
ImmutableCopyableVector<T>
for &'self [T]
where <'self, T: Copy>
Extension methods for vectors
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.
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.
partitioned
fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T])
Partitions the vector into those that satisfies the predicate, and those that do not.
OwnedVector<T>
for ~[T]
where <T>
push
fn push(&mut self, t: T)
push_all_move
fn push_all_move(&mut self, rhs: ~[T])
pop
fn pop(&mut self) -> T
shift
fn shift(&mut self) -> T
unshift
fn unshift(&mut self, x: T)
insert
fn insert(&mut self, i: uint, x: T)
remove
fn remove(&mut self, i: uint) -> T
swap_remove
fn swap_remove(&mut self, index: uint) -> T
truncate
fn truncate(&mut self, newlen: uint)
retain
fn retain(&mut self, f: &fn(t: &T) -> bool)
consume
fn consume(self, f: &fn(uint, v: T))
consume_reverse
fn consume_reverse(self, f: &fn(uint, v: T))
filter
fn filter(self, f: &fn(&T) -> bool) -> ~[T]
partition
fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T])
Partitions the vector into those that satisfies the predicate, and those that do not.
grow_fn
fn grow_fn(&mut self, n: uint, op: iter::InitOp<T>)
Mutable
for ~[T]
where <T>
clear
fn clear(&mut self)
Clear the vector, removing all values.
OwnedCopyableVector<T>
for ~[T]
where <T: Copy>
push_all
fn push_all(&mut self, rhs: &const [T])
grow
fn grow(&mut self, n: uint, initval: &T)
grow_set
fn grow_set(&mut self, index: uint, initval: &T, val: T)
OwnedEqVector<T>
for ~[T]
where <T: Eq>
dedup
fn dedup(&mut self)
iter::BaseIter<A>
for &'self [A]
where <'self, A>
each
fn each(&self, blk: &fn(v: &'self A) -> bool)
size_hint
fn size_hint(&self) -> Option<uint>
iter::BaseIter<A>
for ~[A]
where <A>
each
fn each(&self, blk: &fn(v: &'self A) -> bool)
size_hint
fn size_hint(&self) -> Option<uint>
iter::BaseIter<A>
for @[A]
where <A>
each
fn each(&self, blk: &fn(v: &'self A) -> bool)
size_hint
fn size_hint(&self) -> Option<uint>
iter::MutableIter<A>
for &'self mut [A]
where <'self, A>
each_mut
fn each_mut(&mut self, blk: &fn(v: &'self mut A) -> bool)
iter::MutableIter<A>
for ~[A]
where <A>
each_mut
fn each_mut(&mut self, blk: &fn(v: &'self mut A) -> bool)
iter::MutableIter<A>
for @mut [A]
where <A>
each_mut
fn each_mut(&mut self, blk: &fn(v: &mut A) -> bool)
iter::ExtendedIter<A>
for &'self [A]
where <'self, A>
eachi
fn eachi(&self, blk: &fn(uint, v: &A) -> bool)
all
fn all(&self, blk: &fn(&A) -> bool) -> bool
any
fn any(&self, blk: &fn(&A) -> bool) -> bool
foldl
fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B
position
fn position(&self, f: &fn(&A) -> bool) -> Option<uint>
map_to_vec
fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B]
flat_map_to_vec
fn flat_map_to_vec<B, IB: BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B]
iter::ExtendedIter<A>
for ~[A]
where <A>
eachi
fn eachi(&self, blk: &fn(uint, v: &A) -> bool)
all
fn all(&self, blk: &fn(&A) -> bool) -> bool
any
fn any(&self, blk: &fn(&A) -> bool) -> bool
foldl
fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B
position
fn position(&self, f: &fn(&A) -> bool) -> Option<uint>
map_to_vec
fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B]
flat_map_to_vec
fn flat_map_to_vec<B, IB: BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B]
iter::ExtendedIter<A>
for @[A]
where <A>
eachi
fn eachi(&self, blk: &fn(uint, v: &A) -> bool)
all
fn all(&self, blk: &fn(&A) -> bool) -> bool
any
fn any(&self, blk: &fn(&A) -> bool) -> bool
foldl
fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B
position
fn position(&self, f: &fn(&A) -> bool) -> Option<uint>
map_to_vec
fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B]
flat_map_to_vec
fn flat_map_to_vec<B, IB: BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B]
iter::EqIter<A>
for &'self [A]
where <'self, A: Eq>
contains
fn contains(&self, x: &A) -> bool
count
fn count(&self, x: &A) -> uint
iter::EqIter<A>
for ~[A]
where <A: Eq>
contains
fn contains(&self, x: &A) -> bool
count
fn count(&self, x: &A) -> uint
iter::EqIter<A>
for @[A]
where <A: Eq>
contains
fn contains(&self, x: &A) -> bool
count
fn count(&self, x: &A) -> uint
iter::CopyableIter<A>
for &'self [A]
where <'self, A: Copy>
filter_to_vec
fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A]
to_vec
fn to_vec(&self) -> ~[A]
find
fn find(&self, f: &fn(&A) -> bool) -> Option<A>
iter::CopyableIter<A>
for ~[A]
where <A: Copy>
filter_to_vec
fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A]
to_vec
fn to_vec(&self) -> ~[A]
find
fn find(&self, f: &fn(&A) -> bool) -> Option<A>
iter::CopyableIter<A>
for @[A]
where <A: Copy>
filter_to_vec
fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A]
to_vec
fn to_vec(&self) -> ~[A]
find
fn find(&self, f: &fn(&A) -> bool) -> Option<A>
iter::CopyableOrderedIter<A>
for &'self [A]
where <'self, A: Copy + Ord>
min
fn min(&self) -> A
max
fn max(&self) -> A
iter::CopyableOrderedIter<A>
for ~[A]
where <A: Copy + Ord>
min
fn min(&self) -> A
max
fn max(&self) -> A
iter::CopyableOrderedIter<A>
for @[A]
where <A: Copy + Ord>
min
fn min(&self) -> A
max
fn max(&self) -> A
iter::CopyableNonstrictIter<A>
for &'self [A]
where <'self, A: Copy>
each_val
fn each_val(&const self, f: &fn(A) -> bool)
iter::CopyableNonstrictIter<A>
for ~[A]
where <A: Copy>
each_val
fn each_val(&const self, f: &fn(A) -> bool)
iter::CopyableNonstrictIter<A>
for @[A]
where <A: Copy>
each_val
fn each_val(&const self, f: &fn(A) -> bool)
Clone
for ~[A]
where <A: Clone>
clone
fn clone(&self) -> ~[A]
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.
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.
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.
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.
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.
append
fn append<T: Copy>(lhs: ~[T], rhs: &const [T]) -> ~[T]
append_one
fn append_one<T>(lhs: ~[T], x: T) -> ~[T]
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
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.
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
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.
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.
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.
capacity
fn capacity<T>(v: &const ~[T]) -> uint
Returns the number of elements the vector can hold without reallocating
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.
connect
fn connect<T: Copy>(v: &[~[T]], sep: &T) -> ~[T]
Concatenate a vector of vectors, placing a given separator between each
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.
consume
fn consume<T>(mut v: ~[T], f: &fn(uint, v: T))
consume_reverse
fn consume_reverse<T>(mut v: ~[T], f: &fn(uint, v: T))
contains
fn contains<T: Eq>(v: &[T], x: &T) -> bool
Return true if a vector contains an element with the given value
count
fn count<T: Eq>(v: &[T], x: &T) -> uint
Returns the number of elements that are equal to a given value
dedup
fn dedup<T: Eq>(v: &mut ~[T])
Remove consecutive repeated elements from a vector; if the vector is sorted, this removes all duplicates.
each
fn each<'r, T>(v: &'r [T], f: &fn(&'r T) -> bool)
Iterates over a vector, yielding each element to a closure.
v
- A vector, to be iterated overf
- A closure to do the iterating. Within this closure, return true to[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));
}
each2
fn each2<U, T>(v1: &[U], v2: &[T], f: &fn(u: &U, t: &T) -> bool)
Iterates over two vectors simultaneously
Both vectors must have the same length
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
foldl
fn foldl<T, U>(z: T, v: &[U], p: &fn(t: T, u: &U) -> T) -> T
Reduces a vector from left to right.
z
- initial accumulator valuev
- vector to iterate overp
- a closure to operate on vector elementsSum all values in the vector [1, 2, 3]:
vec::foldl(0, [1, 2, 3], |a, b| a + *b);
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.
v
- vector to iterate overz
- initial accumulator valuep
- a closure to do operate on vector elementsSum all values in the vector [1, 2, 3]:
vec::foldr([1, 2, 3], 0, |a, b| a + *b);
from_buf
unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T]
Constructs a vector from an unsafe pointer to a buffer
T
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
.
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
.
from_slice
fn from_slice<T: Copy>(t: &[T]) -> ~[T]
Creates a new unique vector with the same contents as the slice
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
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
)
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
fn head<'r, T>(v: &'r [T]) -> &'r T
Returns the first element of a vector
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.
init
fn init<'r, T>(v: &'r [T]) -> &'r [T]
Returns a vector containing all but the last element of a slice
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
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.
is_empty
fn is_empty<T>(v: &const [T]) -> bool
Returns true if a vector contains no elements
last
fn last<'r, T>(v: &'r [T]) -> &'r T
Returns the last element of the slice v
, failing if the slice is empty.
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.
len
fn len<T>(v: &const [T]) -> uint
Returns the length of a vector
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
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
map_consume
fn map_consume<T, U>(v: ~[T], f: &fn(v: T) -> U) -> ~[U]
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
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.
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.
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.
pop
fn pop<T>(v: &mut ~[T]) -> T
Remove the last element from a vector and return it
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.
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.
position_elem
fn position_elem<T: Eq>(v: &[T], x: &T) -> Option<uint>
Find the first index containing a matching value
push
fn push<T>(v: &mut ~[T], initval: T)
Append an element to a vector
push_all
fn push_all<T: Copy>(v: &mut ~[T], rhs: &const [T])
push_all_move
fn push_all_move<T>(v: &mut ~[T], mut rhs: ~[T])
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.
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.
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.
retain
fn retain<T>(v: &mut ~[T], f: &fn(t: &T) -> bool)
Like filter()
, but in place. Preserves order of v
. Linear time.
reverse
fn reverse<T>(v: &mut [T])
Reverse the order of elements in a vector, in place
reversed
fn reversed<T: Copy>(v: &const [T]) -> ~[T]
Returns a vector with the order of elements reversed
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.
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.
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.
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.
rposition_elem
fn rposition_elem<T: Eq>(v: &[T], x: &T) -> Option<uint>
Find the last index containing a matching value
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
.
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.
same_length
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: &mut ~[T]) -> T
Removes the first element from a vector and return it
slice
fn slice<'r, T>(v: &'r [T], start: uint, end: uint) -> &'r [T]
Return a slice that points into another slice.
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
.
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.
swap
fn swap<T>(v: &mut [T], a: uint, b: uint)
Swaps two elements in a vector
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.
tail
fn tail<'r, T>(v: &'r [T]) -> &'r [T]
Returns a vector containing all but the first element of a slice
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
truncate
fn truncate<T>(v: &mut ~[T], newlen: uint)
Shorten a vector, dropping excess elements.
uniq_len
fn uniq_len<T>(v: &const ~[T]) -> uint
unshift
fn unshift<T>(v: &mut ~[T], x: T)
Prepend an element to the vector
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.
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().
windowed
fn windowed<TT: Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]]
with_capacity
fn with_capacity<T>(capacity: uint) -> ~[T]
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.
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().