diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2011-06-18 16:29:45 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2011-06-18 16:29:45 -0700 |
| commit | 5d90b1df4b9933adc20736a39a2b9a747760e0ab (patch) | |
| tree | f27f0ac912917319aa427369e928af7f8dad6f54 /src/lib | |
| parent | ef65542b1d9b80272e1f8c49db47b45622c10ef8 (diff) | |
| download | rust-5d90b1df4b9933adc20736a39a2b9a747760e0ab.tar.gz rust-5d90b1df4b9933adc20736a39a2b9a747760e0ab.zip | |
stdlib: Add ivec::grow() and ivec::grow_fn()
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/ivec.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/ivec.rs b/src/lib/ivec.rs index 7e50d3170a0..93c6896d9b7 100644 --- a/src/lib/ivec.rs +++ b/src/lib/ivec.rs @@ -106,6 +106,28 @@ fn slice_mut[T](&T[mutable?] v, uint start, uint end) -> T[mutable] { // TODO +// Appending + +/// Expands the given vector in-place by appending `n` copies of `initval`. +fn grow[T](&mutable T[] v, uint n, &T initval) { + let uint i = 0u; + while (i < n) { + v += ~[initval]; + i += 1u; + } +} + +/// Calls `f` `n` times and appends the results of these calls to the given +/// vector. +fn grow_fn[T](&mutable T[] v, uint n, fn(uint)->T init_fn) { + let uint i = 0u; + while (i < n) { + v += ~[init_fn(i)]; + i += 1u; + } +} + + mod unsafe { fn copy_from_buf[T](&mutable T[] v, *T ptr, uint count) { ret rustrt::ivec_copy_from_buf(v, ptr, count); |
