about summary refs log tree commit diff
path: root/src/libstd/vec.rs
AgeCommit message (Collapse)AuthorLines
2013-09-30std: Remove usage of fmt!Alex Crichton-18/+18
2013-09-29Add get_opt to std::vecHarry Marr-0/+18
2013-09-28auto merge of #9583 : blake2-ppc/rust/connect-vec, r=huonwbors-46/+38
std::vec: Sane implementations for connect_vec and concat_vec Avoid unnecessary copying of subvectors, and calculate the needed space beforehand. These implementations are simple but better than the previous. Also only implement it once, for all `Vector<T>` using: impl<'self, T: Clone, V: Vector<T>> VectorVector<T> for &'self [V] Closes #9581
2013-09-28std::vec: Remove functions concat, connectblake2-ppc-20/+5
std::vec::{concat, connect, concat_slices, connect_slices} are replaced by the already existing trait methods .concat_vec() and .connect_vec().
2013-09-28std::vec: Sane implementations for connect_vec and concat_vecblake2-ppc-26/+15
Avoid unnecessary copying of subvectors, and calculate the needed space beforehand. These implementations are simple but better than the previous. Also only implement it once, for all `Vector<T>` using: impl<'self, T: Clone, V: Vector<T>> VectorVector<T> for &'self [V] performance improved according to the bench test: before test vec::bench::concat ... bench: 74818 ns/iter (+/- 408) test vec::bench::connect ... bench: 87066 ns/iter (+/- 376) after test vec::bench::concat ... bench: 17724 ns/iter (+/- 126) test vec::bench::connect ... bench: 18353 ns/iter (+/- 691) Closes #9581
2013-09-28std::vec: Add benchmark for .concat_vec and .connect_vecblake2-ppc-0/+18
2013-09-27auto merge of #9557 : blake2-ppc/rust/vec-lifetime-token, r=thestingerbors-6/+6
std::vec: Use a valid value as lifetime dummy in iterator The current implementation uses `&v[0]` for the lifetime struct field, but that is a dangling pointer for iterators derived from zero-length slices. Example: let v: [int, ..0] = []; println!("{:?}", v.iter()) std::vec::VecIterator<,int>{ptr: (0x7f3768626100 as *()), end: (0x7f3768626100 as *()), lifetime: &139875951207128} To replace this parameter, use a field of type `Option<&'self ()>` that is simply initialized with `None`, but still allows the iterator to have a lifetime parameter.
2013-09-27std::vec: Use a valid value as lifetime dummy in iteratorblake2-ppc-6/+6
The current implementation uses `&v[0]` for the lifetime struct field, but that is a dangling pointer for iterators derived from zero-length slices. Example: let v: [int, ..0] = []; println!("{:?}", v.iter()) std::vec::VecIterator<,int>{ptr: (0x7f3768626100 as *()), end: (0x7f3768626100 as *()), lifetime: &139875951207128} To replace this parameter, use a field of type `Option<&'self ()>` that is simply initialized with `None`, but still allows the iterator to have a lifetime parameter.
2013-09-26Update the compiler to not use printf/printflnAlex Crichton-2/+2
2013-09-25rustdoc: Change all code-blocks with a scriptAlex Crichton-18/+18
find src -name '*.rs' | xargs sed -i '' 's/~~~.*{\.rust}/```rust/g' find src -name '*.rs' | xargs sed -i '' 's/ ~~~$/ ```/g' find src -name '*.rs' | xargs sed -i '' 's/^~~~$/ ```/g'
2013-09-21Document a few undocumented methos in VectorLuis de Bethencourt-0/+6
Closes #9379
2013-09-17Document a few undocumented modules in libstdAlex Crichton-0/+2
Hopefull this will make our libstd docs appear a little more "full".
2013-09-17std::at_vec: Fix segfault on overflow when resizing ~[@T]blake2-ppc-0/+8
Easy to reproduce: let mut v = ~[@1]; v.resize(-1); // success a.k.a silent failure v.push(@2); // segfault
2013-09-16std::vec: Add function vec::bytes::push_bytesblake2-ppc-0/+17
`push_bytes` is implemented with `ptr::copy_memory` here since this function is intended to be used to implement `.push_str()` for str, so we want to avoid the overhead.
2013-09-16std::vec: Fix hazards with uint overflows in unsafe codeblake2-ppc-6/+29
Issue #8742 Add the method `.reserve_additional(n: uint)`: Check for overflow in self.len() + n, and reserve that many elements (rounded up to next power of two). Does nothing if self.len() + n < self.capacity() already.
2013-09-12std: Remove Zero impl from vecErick Tryzelaar-21/+4
Vecs are not numeric types, so it doesn't make sense for them to implement Zero.
2013-09-12std: Add Default implementation for vecsErick Tryzelaar-0/+14
2013-09-12std: rename Option::unwrap_or_default() to unwrap_or()Erick Tryzelaar-1/+1
2013-09-09auto merge of #9062 : blake2-ppc/rust/vec-iterator, r=alexcrichtonbors-207/+239
Visit the free functions of std::vec and reimplement or remove some. Most prominently, remove `each_permutation` and replace with two iterators, ElementSwaps and Permutations. Replace unzip, unzip_slice with an updated `unzip` that works with an iterator argument. Replace each_permutation with a Permutation iterator. The new permutation iterator is more efficient since it uses an algorithm that produces permutations in an order where each is only one element swap apart, including swapping back to the original state with one swap at the end. Unify the seldomly used functions `build`, `build_sized`, `build_sized_opt` into just one function `build`. Remove `equal_sizes`
2013-09-10std::at_vec and vec: Unify build_sized, build_sized_opt into buildblake2-ppc-37/+5
These functions have very few users since they are mostly replaced by iterator-based constructions. Convert a few remaining users in-tree, and reduce the number of functions by basically renaming build_sized_opt to build, and removing the other two. This for both the vec and the at_vec versions.
2013-09-10std::vec: Remove the function same_lengthblake2-ppc-5/+0
The basic construct x.len() == y.len() is just as simple. This function used to be a precondition (not sure about the terminology), so it had to be a function. This is not relevant any more.
2013-09-10std::vec: Update module doc textblake2-ppc-19/+60
Update for a lot of changes (not many free functions left), add examples of the important methods `slice` and `push`, and write a short bit about iteration.
2013-09-10std::vec: Replace each_permutation with a new Permutations iteratorblake2-ppc-119/+165
Introduce ElementSwaps and Permutations. ElementSwaps is an iterator that for a given sequence length yields the element swaps needed to visit each possible permutation of the sequence in turn. We use an algorithm that generates a sequence such that each permutation is only one swap apart. let mut v = [1, 2, 3]; for perm in v.permutations_iter() { // yields 1 2 3 | 1 3 2 | 3 1 2 | 3 2 1 | 2 3 1 | 2 1 3 } The `.permutations_iter()` yields clones of the input vector for each permutation. If a copyless traversal is needed, it can be constructed with `ElementSwaps`: for (a, b) in ElementSwaps::new(3) { // yields (2, 1), (1, 0), (2, 1) ... v.swap(a, b); // .. }
2013-09-10std::vec: Change fn unzip to take an iterator argumentblake2-ppc-27/+9
Remove unzip_slice since it's redundant. Old unzip is equivalent to the `|x| unzip(x.move_iter())`
2013-09-09rename `std::iterator` to `std::iter`Daniel Micay-10/+10
The trait will keep the `Iterator` naming, but a more concise module name makes using the free functions less verbose. The module will define iterables in addition to iterators, as it deals with iteration in general.
2013-09-05std: Remove push_fast from OwnedVector. Closes #8769Brian Anderson-22/+21
This is an unsafe implementation detail of `push`.
2013-09-03auto merge of #8884 : blake2-ppc/rust/exact-size-hint, r=huonwbors-42/+5
The message of the first commit explains (edited for changed trait name): The trait `ExactSize` is introduced to solve a few small niggles: * We can't reverse (`.invert()`) an enumeration iterator * for a vector, we have `v.iter().position(f)` but `v.rposition(f)`. * We can't reverse `Zip` even if both iterators are from vectors `ExactSize` is an empty trait that is intended to indicate that an iterator, for example `VecIterator`, knows its exact finite size and reports it correctly using `.size_hint()`. Only adaptors that preserve this at all times, can expose this trait further. (Where here we say finite for fitting in uint). --- It may seem complicated just to solve these small "niggles", (It's really the reversible enumerate case that's the most interesting) but only a few core iterators need to implement this trait. While we gain more capabilities generically for some iterators, it becomes a tad more complicated to figure out if a type has the right trait impls for it.
2013-09-01std::iterator: Use ExactSize, inheriting DoubleEndedIteratorblake2-ppc-2/+2
Address discussion with acrichto; inherit DoubleEndedIterator so that `.rposition()` can be a default method, and that the nische of the trait is clear. Use assertions when using `.size_hint()` in reverse enumerate and `.rposition()`
2013-09-01std::iterator: Add back .rposition() testblake2-ppc-10/+0
2013-08-31repr: remove trailing {} from unit-like structsDaniel Micay-2/+2
2013-08-31repr: print the name of structsDaniel Micay-2/+4
2013-08-30std: Implement .rposition() on double-ended iterators with known sizeblake2-ppc-34/+4
This is a generalization of the vector .rposition() method, to all double-ended iterators that have the ExactSizeHint trait. This resolves the slight asymmetry around `position` and `rposition` * position from front is `vec.iter().position()` * position from the back was, `vec.rposition()` is now `vec.iter().rposition()` Additionally, other indexed sequences (only `extra::ringbuf` I think), will have the same method available once it implements ExactSizeHint.
2013-08-30std::iterator: Introduce trait ExactSizeHintblake2-ppc-0/+3
The trait `ExactSizeHint` is introduced to solve a few small niggles: * We can't reverse (`.invert()`) an enumeration iterator * for a vector, we have `v.iter().position(f)` but `v.rposition(f)`. * We can't reverse `Zip` even if both iterators are from vectors `ExactSizeHint` is an empty trait that is intended to indicate that an iterator, for example `VecIterator`, knows its exact finite size and reports it correctly using `.size_hint()`. Only adaptors that preserve this at all times, can expose this trait further. (Where here we say finite for fitting in uint).
2013-08-27Remove offset_inbounds for an unsafe offset functionAlex Crichton-4/+4
2013-08-27librustc: Remove `&const` and `*const` from the language.Patrick Walton-8/+1
They are still present as part of the borrow check.
2013-08-27vec: implement `DeepClone`Daniel Micay-2/+9
2013-08-26std: Make vec::from_elem failure-safeBrian Anderson-4/+30
2013-08-26std: Make vec::from_fn failure-safeBrian Anderson-4/+8
2013-08-24auto merge of #8701 : brson/rust/issue-8698, r=thestingerbors-8/+4
2013-08-24std: Make vec::push_all_move call reserve_at_leastBrian Anderson-1/+1
vec::unshift uses this to add elements, scheduler queues use unshift, and this was causing a lot of reallocation
2013-08-23Fix some vector function failure tests. Closes #8698Brian Anderson-8/+4
2013-08-22Disabled broken tests in std::vec.Vadim Chugunov-0/+4
2013-08-22Enabled unit tests in std and extra.Vadim Chugunov-20/+0
2013-08-21auto merge of #8604 : kballard/rust/iter-size-hint, r=graydonbors-1/+69
Implement `size_hint()` on the new std::vec Iterators. Add or update `size_hint()` on std::iterator Iterators where appropriate. r? @thestinger
2013-08-20vec: add `shrink_to_fit`Daniel Micay-0/+26
Closes #4960
2013-08-18Implement .size_hint() on new vec iteratorsKevin Ballard-1/+69
2013-08-16doc: correct spelling in documentation.Huon Wilson-2/+2
2013-08-15vec: rm redundant is_empty implementationsDaniel Micay-12/+0
2013-08-15vec: rm obsolete zip and zip_sliceDaniel Micay-41/+1
These are obsoleted by the generic iterator `zip` adaptor. Unlike these, it does not clone the elements or allocate a new vector by default.
2013-08-15auto merge of #8490 : huonw/rust/fromiterator-extendable, r=catamorphismbors-4/+4
If they are on the trait then it is extremely annoying to use them as generic parameters to a function, e.g. with the iterator param on the trait itself, if one was to pass an Extendable<int> to a function that filled it either from a Range or a Map<VecIterator>, one needs to write something like: fn foo<E: Extendable<int, Range<int>> + Extendable<int, Map<&'self int, int, VecIterator<int>>> (e: &mut E, ...) { ... } since using a generic, i.e. `foo<E: Extendable<int, I>, I: Iterator<int>>` means that `foo` takes 2 type parameters, and the caller has to specify them (which doesn't work anyway, as they'll mismatch with the iterators used in `foo` itself). This patch changes it to: fn foo<E: Extendable<int>>(e: &mut E, ...) { ... }