diff options
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/vec_ng.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/libstd/vec_ng.rs b/src/libstd/vec_ng.rs index 6cc3ccc3452..9b6acdd9b9e 100644 --- a/src/libstd/vec_ng.rs +++ b/src/libstd/vec_ng.rs @@ -16,6 +16,7 @@ use clone::Clone; use cmp::{Eq, Ordering, TotalEq, TotalOrd}; use container::Container; use default::Default; +use fmt; use iter::{DoubleEndedIterator, FromIterator, Iterator}; use libc::{free, c_void}; use mem::{size_of, move_val_init}; @@ -82,6 +83,26 @@ impl<T: Clone> Vec<T> { self.push((*element).clone()) } } + + + pub fn grow(&mut self, n: uint, initval: &T) { + let new_len = self.len() + n; + self.reserve(new_len); + let mut i: uint = 0u; + + while i < n { + self.push((*initval).clone()); + i += 1u; + } + } + + pub fn grow_set(&mut self, index: uint, initval: &T, val: T) { + let l = self.len(); + if index >= l { + self.grow(index - l + 1u, initval); + } + *self.get_mut(index) = val; + } } impl<T:Clone> Clone for Vec<T> { @@ -388,6 +409,12 @@ impl<T> Default for Vec<T> { } } +impl<T:fmt::Show> fmt::Show for Vec<T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.as_slice().fmt(f) + } +} + pub struct MoveItems<T> { priv allocation: *mut c_void, // the block of memory allocated for the vector priv iter: Items<'static, T> |
