Vectors
UnboxedVecRepr
- The internal 'unboxed' representation of a vectorVecIterator
- An iterator for iterating over a vectorVecMutIterator
- An iterator for mutating the elements of a vectorVecMutRevIterator
- An iterator for mutating the elements of a vector in reverseVecRevIterator
- An iterator for iterating over a vector in reverseCopyableVector
ImmutableCopyableVector
ImmutableEqVector
ImmutableTotalOrdVector
ImmutableVector
MutableCloneableVector
- Trait for ~[T] where T is CloneableMutableVector
OwnedCopyableVector
OwnedEqVector
OwnedVector
VectorVector
of VectorVector<T> for &'self [~[T]] where <'self, T: Copy>
of VectorVector<T> for &'self [&'self [T]] where <'self, T: Copy>
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 Add<&'self [T], ~[T]> for ~[T] where <'self, T: Copy>
of Container for &'self [T] where <'self, T>
of Container for ~[T] where <T>
of CopyableVector<T> for &'self [T] where <'self, T: Copy>
- Extension methods for vectorsof ImmutableVector<'self, T> for &'self [T] where <'self, T>
- Extension methods for vectorsof ImmutableEqVector<T> for &'self [T] where <'self, T: Eq>
of ImmutableTotalOrdVector<T> for &'self [T] where <'self, T: TotalOrd>
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 MutableVector<'self, T> for &'self mut [T] where <'self, T>
of MutableCloneableVector<T> for &'self mut [T] where <'self, T: Clone>
of Clone for ~[A] where <A: Clone>
of Zero for &'self [A] where <'self, A>
of Zero for ~[A] where <A>
of Zero for @[A] where <A>
of Iterator<&'self T> for VecIterator<'self, T> where <'self, T>
of Iterator<&'self T> for VecRevIterator<'self, T> where <'self, T>
of Iterator<&'self mut T> for VecMutIterator<'self, T> where <'self, T>
of Iterator<&'self mut T> for VecMutRevIterator<'self, T> where <'self, T>
of FromIter<T> for ~[T] where <T>
of FromIterator<A, T> for ~[A] where <A, T: Iterator<A>>
append
- Iterates over the rhs
vector, copying each element and appending it to the lhs
append_one
- Appends one element to the vector providedas_imm_buf
- Work with the buffer of a vector.as_mut_buf
- Similar to as_imm_buf
but passing a *mut T
build
build_sized
build_sized_opt
concat
- Flattens a vector of vectors of T into a single vector of T.concat_slices
- Flattens a vector of vectors of T into a single vector of T.connect
- Concatenate a vector of vectors, placing a given separator between eachconnect_slices
- Concatenate a vector of vectors, placing a given separator between eachconsume
- Consumes all elements, in a vector, moving them out into the / closure providedconsume_reverse
- Consumes all elements, in a vector, moving them out into the / closure providedeach_permutation
- Iterate over all permutations of vector v
.filter
- 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.flat_map
- Apply a function to each element of a vector and return a concatenation of each result vectorfrom_buf
- Constructs a vector from an unsafe pointer to a bufferfrom_elem
- Creates and initializes an owned vector.from_fn
- Creates and initializes an owned vector.map_consume
- Consumes a vector, mapping it into a different vectorreversed
- Returns a vector with the order of elements reversedrsplit
- 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 lengthsplit
- 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.to_owned
- Creates a new unique vector with the same contents as the sliceunzip
- Convert a vector of pairs into a pair of vectors.unzip_slice
- Convert a vector of pairs into a pair of vectors, by referencewindowed
- Iterate over all contiguous windows of length n
of the vector v
.with_capacity
- Creates a new vector with a capacity of 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 operationsUnboxedVecRepr
pub struct UnboxedVecRepr {
fill: uint,
alloc: uint,
data: u8,
}
The internal 'unboxed' representation of a vector
VecIterator
pub struct VecIterator<'self, T> {
priv ptr: *T,
priv end: *T,
priv lifetime: &'self T,
}
An iterator for iterating over a vector
VecMutIterator
pub struct VecMutIterator<'self, T> {
priv ptr: *mut T,
priv end: *mut T,
priv lifetime: &'self mut T,
}
An iterator for mutating the elements of a vector
VecMutRevIterator
pub struct VecMutRevIterator<'self, T> {
priv ptr: *mut T,
priv end: *mut T,
priv lifetime: &'self mut T,
}
An iterator for mutating the elements of a vector in reverse
VecRevIterator
pub struct VecRevIterator<'self, T> {
priv ptr: *T,
priv end: *T,
priv lifetime: &'self T,
}
An iterator for iterating over a vector in reverse
CopyableVector
to_owned
fn to_owned(&self) -> ~[T]
ImmutableCopyableVector
filtered
fn filtered(&self, f: &fn(&T) -> bool) -> ~[T]
partitioned
fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T])
unsafe_get
unsafe fn unsafe_get(&self, elem: uint) -> T
ImmutableEqVector
position_elem
fn position_elem(&self, t: &T) -> Option<uint>
rposition_elem
fn rposition_elem(&self, t: &T) -> Option<uint>
contains
fn contains(&self, x: &T) -> bool
ImmutableTotalOrdVector
bsearch_elem
fn bsearch_elem(&self, x: &T) -> Option<uint>
ImmutableVector
slice
fn slice(&self, start: uint, end: uint) -> &'self [T]
iter
fn iter(self) -> VecIterator<'self, T>
rev_iter
fn rev_iter(self) -> VecRevIterator<'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>
rposition
fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint>
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]
unsafe_ref
unsafe fn unsafe_ref(&self, index: uint) -> *T
bsearch
fn bsearch(&self, f: &fn(&T) -> Ordering) -> Option<uint>
map
fn map<U>(&self, &fn(t: &T) -> U) -> ~[U]
MutableCloneableVector
Trait for ~[T] where T is Cloneable
copy_from
fn copy_from(self, &[T]) -> uint
Copies as many elements from src
as it can into self
(the shorter of self.len() and src.len()). Returns the number of elements copied.
MutableVector
mut_slice
fn mut_slice(self, start: uint, end: uint) -> &'self mut [T]
mut_iter
fn mut_iter(self) -> VecMutIterator<'self, T>
mut_rev_iter
fn mut_rev_iter(self) -> VecMutRevIterator<'self, T>
swap
fn swap(self, a: uint, b: uint)
reverse
fn reverse(self)
move_from
fn move_from(self, src: ~[T], start: uint, end: uint) -> uint
Consumes src
and moves as many elements as it can into self
from the range [start,end).
Returns the number of elements copied (the shorter of self.len() and end - start).
T
src
to start copying fromstr
to stop copying fromunsafe_mut_ref
unsafe fn unsafe_mut_ref(&self, index: uint) -> *mut T
unsafe_set
unsafe fn unsafe_set(&self, index: uint, val: T)
OwnedCopyableVector
push_all
fn push_all(&mut self, rhs: &[T])
grow
fn grow(&mut self, n: uint, initval: &T)
grow_set
fn grow_set(&mut self, index: uint, initval: &T, val: T)
OwnedEqVector
dedup
fn dedup(&mut self)
OwnedVector
reserve
fn reserve(&mut self, n: uint)
reserve_at_least
fn reserve_at_least(&mut self, n: uint)
capacity
fn capacity(&self) -> uint
push
fn push(&mut self, t: T)
push_fast
unsafe fn push_fast(&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: &fn(uint) -> T)
VectorVector
concat_vec
fn concat_vec(&self) -> ~[T]
connect_vec
fn connect_vec(&self, sep: &T) -> ~[T]
VectorVector<T>
for &'self [~[T]]
where <'self, T: Copy>
concat_vec
fn concat_vec(&self) -> ~[T]
Flattens a vector of slices of T into a single vector of T.
connect_vec
fn connect_vec(&self, sep: &T) -> ~[T]
Concatenate a vector of vectors, placing a given separator between each.
VectorVector<T>
for &'self [&'self [T]]
where <'self, T: Copy>
concat_vec
fn concat_vec(&self) -> ~[T]
Flattens a vector of slices of T into a single vector of T.
connect_vec
fn connect_vec(&self, sep: &T) -> ~[T]
Concatenate a vector of slices, placing a given separator between each.
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
Add<&'self [T], ~[T]>
for ~[T]
where <'self, T: Copy>
add
fn add(&self, rhs: &&'self [T]) -> ~[T]
Container
for &'self [T]
where <'self, T>
is_empty
fn is_empty(&self) -> bool
Returns true if a vector contains no elements
len
fn len(&self) -> uint
Returns the length of a vector
Container
for ~[T]
where <T>
is_empty
fn is_empty(&self) -> bool
Returns true if a vector contains no elements
len
fn len(&self) -> uint
Returns the length of a vector
CopyableVector<T>
for &'self [T]
where <'self, T: Copy>
Extension methods for vectors
to_owned
fn to_owned(&self) -> ~[T]
Returns a copy of v
.
ImmutableVector<'self, 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.
iter
fn iter(self) -> VecIterator<'self, T>
rev_iter
fn rev_iter(self) -> VecRevIterator<'self, T>
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, or None
if it is empty
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 element 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 vector, failing if the vector is empty.
last_opt
fn last_opt(&self) -> Option<&'self T>
Returns the last element of a vector, or None
if it is empty.
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.
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.
unsafe_ref
unsafe fn unsafe_ref(&self, index: uint) -> *T
Returns a pointer to the element at the given index, without doing bounds checking.
bsearch
fn bsearch(&self, f: &fn(&T) -> Ordering) -> Option<uint>
Binary search a sorted vector with a comparator function.
The comparator should implement an order consistent with the sort order of the underlying vector, returning an order code that indicates whether its argument is Less
, Equal
or Greater
the desired target.
Returns the index where the comparator returned Equal
, or None
if not found.
map
fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U]
Deprecated, use iterators where possible (self.iter().transform(f)
). Apply a function to each element of a vector and return the results.
ImmutableEqVector<T>
for &'self [T]
where <'self, T: Eq>
position_elem
fn position_elem(&self, x: &T) -> Option<uint>
Find the first index containing a matching value
rposition_elem
fn rposition_elem(&self, t: &T) -> Option<uint>
Find the last index containing a matching value
contains
fn contains(&self, x: &T) -> bool
Return true if a vector contains an element with the given value
ImmutableTotalOrdVector<T>
for &'self [T]
where <'self, T: TotalOrd>
bsearch_elem
fn bsearch_elem(&self, x: &T) -> Option<uint>
Binary search a sorted vector for a given element.
Returns the index of the element or None if not found.
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.
partitioned
fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T])
Partitions the vector into those that satisfies the predicate, and those that do not.
unsafe_get
unsafe fn unsafe_get(&self, index: uint) -> T
Returns the element at the given index, without doing bounds checking.
OwnedVector<T>
for ~[T]
where <T>
reserve
fn reserve(&mut self, n: uint)
Reserves capacity for exactly n
elements in the given vector.
If the capacity for self
is already equal to or greater than the requested capacity, then no action is taken.
reserve_at_least
fn reserve_at_least(&mut self, n: uint)
Reserves capacity for at least n
elements in the given vector.
This function will over-allocate in order to amortize the allocation costs in scenarios where the caller may need to repeatedly reserve additional space.
If the capacity for self
is already equal to or greater than the requested capacity, then no action is taken.
capacity
fn capacity(&self) -> uint
Returns the number of elements the vector can hold without reallocating.
push
fn push(&mut self, t: T)
Append an element to a vector
push_fast
unsafe fn push_fast(&mut self, t: T)
push_all_move
fn push_all_move(&mut self, mut rhs: ~[T])
Takes ownership of the vector rhs
, moving all elements into the current vector. This does not copy any elements, and it is illegal to use the rhs
vector after calling this method (because it is moved here).
let mut a = ~[~1];
a.push_all_move(~[~2, ~3, ~4]);
assert!(a == ~[~1, ~2, ~3, ~4]);
pop
fn pop(&mut self) -> T
Remove the last element from a vector and return it
shift
fn shift(&mut self) -> T
Removes the first element from a vector and return it
unshift
fn unshift(&mut self, x: T)
Prepend an element to the vector
insert
fn insert(&mut self, i: uint, x: T)
Insert an element at position i within v, shifting all elements after position i one position to the right.
remove
fn remove(&mut self, i: uint) -> T
Remove and return the element at position i within v, shifting all elements after position i one position to the left.
swap_remove
fn swap_remove(&mut self, index: uint) -> T
Remove an element from anywhere in the vector and return it, replacing it with the last element. This does not preserve ordering, but is O(1).
Fails if index >= length.
truncate
fn truncate(&mut self, newlen: uint)
Shorten a vector, dropping excess elements.
retain
fn retain(&mut self, f: &fn(t: &T) -> bool)
Like filter()
, but in place. Preserves order of v
. Linear time.
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: &fn(uint) -> T)
Expands a vector in place, initializing the new elements to the result of a function
Function init_op
is called n
times with the values [0..n
)
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: &[T])
Iterates over the slice rhs
, copies each element, and then appends it to the vector provided v
. The rhs
vector is traversed in-order.
let mut a = ~[1];
a.push_all([2, 3, 4]);
assert!(a == ~[1, 2, 3, 4]);
grow
fn grow(&mut self, n: uint, initval: &T)
Expands a vector in place, initializing the new elements to a given value
grow_set
fn grow_set(&mut self, index: uint, initval: &T, val: T)
Sets the value of a vector element at a given index, growing the vector as needed
Sets the element at position index
to val
. If index
is past the end of the vector, expands the vector by replicating initval
to fill the intervening space.
OwnedEqVector<T>
for ~[T]
where <T: Eq>
dedup
fn dedup(&mut self)
Remove consecutive repeated elements from a vector; if the vector is sorted, this removes all duplicates.
MutableVector<'self, T>
for &'self mut [T]
where <'self, T>
mut_slice
fn mut_slice(self, start: uint, end: uint) -> &'self mut [T]
Return a slice that points into another slice.
mut_iter
fn mut_iter(self) -> VecMutIterator<'self, T>
mut_rev_iter
fn mut_rev_iter(self) -> VecMutRevIterator<'self, T>
swap
fn swap(self, a: uint, b: uint)
Swaps two elements in a vector
reverse
fn reverse(self)
Reverse the order of elements in a vector, in place
move_from
fn move_from(self, mut src: ~[T], start: uint, end: uint) -> uint
unsafe_mut_ref
unsafe fn unsafe_mut_ref(&self, index: uint) -> *mut T
unsafe_set
unsafe fn unsafe_set(&self, index: uint, val: T)
MutableCloneableVector<T>
for &'self mut [T]
where <'self, T: Clone>
copy_from
fn copy_from(self, src: &[T]) -> uint
Clone
for ~[A]
where <A: Clone>
clone
fn clone(&self) -> ~[A]
Zero
for &'self [A]
where <'self, A>
zero
fn zero() -> &'self [A]
is_zero
fn is_zero(&self) -> bool
Zero
for ~[A]
where <A>
zero
fn zero() -> ~[A]
is_zero
fn is_zero(&self) -> bool
Zero
for @[A]
where <A>
zero
fn zero() -> @[A]
is_zero
fn is_zero(&self) -> bool
Iterator<&'self T>
for VecIterator<'self, T>
where <'self, T>
next
fn next(&mut self) -> Option<&'self T>
size_hint
fn size_hint(&self) -> (Option<uint>, Option<uint>)
Iterator<&'self T>
for VecRevIterator<'self, T>
where <'self, T>
next
fn next(&mut self) -> Option<&'self T>
size_hint
fn size_hint(&self) -> (Option<uint>, Option<uint>)
Iterator<&'self mut T>
for VecMutIterator<'self, T>
where <'self, T>
next
fn next(&mut self) -> Option<&'self mut T>
size_hint
fn size_hint(&self) -> (Option<uint>, Option<uint>)
Iterator<&'self mut T>
for VecMutRevIterator<'self, T>
where <'self, T>
next
fn next(&mut self) -> Option<&'self mut T>
size_hint
fn size_hint(&self) -> (Option<uint>, Option<uint>)
FromIter<T>
for ~[T]
where <T>
from_iter
fn from_iter(iter: &fn(f: &fn(T) -> bool) -> bool) -> ~[T]
FromIterator<A, T>
for ~[A]
where <A, T: Iterator<A>>
from_iterator
fn from_iterator(iterator: &mut T) -> ~[A]
append
fn append<T: Copy>(lhs: ~[T], rhs: &[T]) -> ~[T]
Iterates over the rhs
vector, copying each element and appending it to the lhs
. Afterwards, the lhs
is then returned for use again.
append_one
fn append_one<T>(lhs: ~[T], x: T) -> ~[T]
Appends one element to the vector provided. The vector itself is then returned for use again.
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.
concat
fn concat<T: Copy>(v: &[~[T]]) -> ~[T]
Flattens a vector of vectors of T into a single vector of T.
concat_slices
fn concat_slices<T: Copy>(v: &[&[T]]) -> ~[T]
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
connect_slices
fn connect_slices<T: Copy>(v: &[&[T]], sep: &T) -> ~[T]
Concatenate a vector of vectors, placing a given separator between each
consume
fn consume<T>(mut v: ~[T], f: &fn(uint, v: T))
Consumes all elements, in a vector, moving them out into the / closure provided. The vector is traversed from the start to the end.
This method does not impose any requirements on the type of the vector being consumed, but it prevents any usage of the vector after this function is called.
let v = ~[~"a", ~"b"];
do vec::consume(v) |i, s| {
// s has type ~str, not &~str
io::println(s + fmt!(" %d", i));
}
consume_reverse
fn consume_reverse<T>(mut v: ~[T], f: &fn(uint, v: T))
Consumes all elements, in a vector, moving them out into the / closure provided. The vectors is traversed in reverse order (from end to start).
This method does not impose any requirements on the type of the vector being consumed, but it prevents any usage of the vector after this function is called.
each_permutation
fn each_permutation<T: Copy>(values: &[T], fun: &fn(perm: &[T]) -> bool) ->
bool
Iterate over all permutations of vector v
.
Permutations are produced in lexicographic order with respect to the order of elements in v
(so if v
is sorted then the permutations are lexicographically sorted).
The total number of permutations produced is v.len()!
. If v
contains repeated elements, then some permutations are repeated.
See Algorithms to generate permutations.
# Arguments
values
- A vector of values from which the permutations are chosen
fun
- The function to iterate over the combinations
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.
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
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 owned vector.
Creates an owned vector of size n_elts
and initializes the elements to the value t
.
from_fn
fn from_fn<T>(n_elts: uint, op: &fn(uint) -> T) -> ~[T]
Creates and initializes an owned vector.
Creates an owned vector of size n_elts
and initializes the elements to the value returned by the function op
.
map_consume
fn map_consume<T, U>(v: ~[T], f: &fn(v: T) -> U) -> ~[U]
Consumes a vector, mapping it into a different vector. This function takes ownership of the supplied vector v
, moving each element into the closure provided to generate a new element. The vector of new elements is then returned.
The original vector v
cannot be used after this function call (it is moved inside), but there are no restrictions on the type of the vector.
reversed
fn reversed<T: Copy>(v: &[T]) -> ~[T]
Returns a vector with the order of elements reversed
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: &[T], ys: &[U]) -> bool
Returns true if two vectors have the same length
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.
to_owned
fn to_owned<T: Copy>(t: &[T]) -> ~[T]
Creates a new unique vector with the same contents as the slice
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<'r, T>(n: uint, v: &'r [T], it: &fn(&'r [T]) -> bool) -> bool
Iterate over all contiguous windows of length n
of the vector v
.
Print the adjacent pairs of a vector (i.e. [1,2]
, [2,3]
, [3,4]
)
for windowed(2, &[1,2,3,4]) |v| {
io::println(fmt!("%?", v));
}
with_capacity
fn with_capacity<T>(capacity: uint) -> ~[T]
Creates a new vector with a capacity of capacity
zip
fn zip<T, U>(mut v: ~[T], mut u: ~[U]) -> ~[(T, U)]
Convert two vectors to a vector of pairs.
Returns a vector of tuples, where the i-th tuple contains the i-th elements from each of the input vectors.
zip_slice
fn zip_slice<T: Copy, U: Copy>(v: &[T], u: &[U]) -> ~[(T, U)]
Convert two vectors to a vector of pairs, by reference. As zip().