Add some mutable variants of vector functions to the standard library
This commit is contained in:
parent
8b82a549bf
commit
368eb4bab6
2 changed files with 31 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ native "rust" mod rustrt {
|
|||
* want to invoke this as vec_alloc[vec[U], U].
|
||||
*/
|
||||
fn vec_alloc[T, U](uint n_elts) -> vec[U];
|
||||
fn vec_alloc_mut[T, U](uint n_elts) -> vec[mutable U];
|
||||
|
||||
fn refcount[T](vec[T] v) -> uint;
|
||||
|
||||
|
|
@ -30,6 +31,10 @@ fn alloc[T](uint n_elts) -> vec[T] {
|
|||
ret rustrt.vec_alloc[vec[T], T](n_elts);
|
||||
}
|
||||
|
||||
fn alloc_mut[T](uint n_elts) -> vec[mutable T] {
|
||||
ret rustrt.vec_alloc_mut[vec[mutable T], T](n_elts);
|
||||
}
|
||||
|
||||
fn refcount[T](vec[T] v) -> uint {
|
||||
auto r = rustrt.refcount[T](v);
|
||||
if (r == dbg.const_refcount) {
|
||||
|
|
@ -52,6 +57,16 @@ fn init_fn[T](&init_op[T] op, uint n_elts) -> vec[T] {
|
|||
ret v;
|
||||
}
|
||||
|
||||
fn init_fn_mut[T](&init_op[T] op, uint n_elts) -> vec[mutable T] {
|
||||
let vec[mutable T] v = alloc_mut[T](n_elts);
|
||||
let uint i = 0u;
|
||||
while (i < n_elts) {
|
||||
v += vec(mutable op(i));
|
||||
i += 1u;
|
||||
}
|
||||
ret v;
|
||||
}
|
||||
|
||||
fn init_elt[T](&T t, uint n_elts) -> vec[T] {
|
||||
/**
|
||||
* FIXME (issue #81): should be:
|
||||
|
|
@ -69,6 +84,16 @@ fn init_elt[T](&T t, uint n_elts) -> vec[T] {
|
|||
ret v;
|
||||
}
|
||||
|
||||
fn init_elt_mut[T](&T t, uint n_elts) -> vec[mutable T] {
|
||||
let vec[mutable T] v = alloc_mut[T](n_elts);
|
||||
let uint i = n_elts;
|
||||
while (i > 0u) {
|
||||
i -= 1u;
|
||||
v += vec(mutable t);
|
||||
}
|
||||
ret v;
|
||||
}
|
||||
|
||||
fn buf[T](vec[T] v) -> vbuf {
|
||||
ret rustrt.vec_buf[T](v, 0u);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue