about summary refs log tree commit diff
path: root/src/libstd/vec.rs
AgeCommit message (Collapse)AuthorLines
2014-03-23Add Vec::mut_slice_from(), mut_slice_to(), and mut_split_at()Eunchong Yu-0/+122
2014-03-21auto merge of #13016 : huonw/rust/new-opt-vec, r=cmrbors-0/+13
Replace syntax::opt_vec with syntax::owned_slice The `owned_slice::OwnedSlice` is `(*T, uint)` (i.e. a direct equivalent to DSTs `~[T]`). This shaves two words off the old OptVec type; and also makes substituting in other implementations easy, by removing all the mutation methods. (And also everything that's very rarely/never used.)
2014-03-22Migrate all users of opt_vec to owned_slice, delete opt_vec.Huon Wilson-0/+13
syntax::opt_vec is now entirely unused, and so can go.
2014-03-21libstd: Add some methods to `Vec<T>`.Patrick Walton-17/+19
2014-03-20A couple of fixes to vec_ng docsSteven Fackler-14/+24
2014-03-20rename std::vec_ng -> std::vecDaniel Micay-0/+1353
Closes #12771
2014-03-20rename std::vec -> std::sliceDaniel Micay-4652/+0
Closes #12702
2014-03-08Removed DeepClone. Issue #12698.Michael Darakananda-19/+1
2014-03-07create a sensible comparison trait hierarchyDaniel Micay-2/+2
* `Ord` inherits from `Eq` * `TotalOrd` inherits from `TotalEq` * `TotalOrd` inherits from `Ord` * `TotalEq` inherits from `Eq` This is a partial implementation of #12517.
2014-03-04make `MutItems` iterator sound againDaniel Micay-9/+19
This become `Pod` when it was switched to using marker types.
2014-02-28std: Change assert_eq!() to use {} instead of {:?}Alex Crichton-43/+42
Formatting via reflection has been a little questionable for some time now, and it's a little unfortunate that one of the standard macros will silently use reflection when you weren't expecting it. This adds small bits of code bloat to libraries, as well as not always being necessary. In light of this information, this commit switches assert_eq!() to using {} in the error message instead of {:?}. In updating existing code, there were a few error cases that I encountered: * It's impossible to define Show for [T, ..N]. I think DST will alleviate this because we can define Show for [T]. * A few types here and there just needed a #[deriving(Show)] * Type parameters needed a Show bound, I often moved this to `assert!(a == b)` * `Path` doesn't implement `Show`, so assert_eq!() cannot be used on two paths. I don't think this is much of a regression though because {:?} on paths looks awful (it's a byte array). Concretely speaking, this shaved 10K off a 656K binary. Not a lot, but sometime significant for smaller binaries.
2014-02-28Improve vec `partition` and `partitioned` method doc.Felix S. Klock II-6/+5
Explicitly note in vec `partition` and `partitioned` that the left and right parts each map to satisfying and non-satisfying elements.
2014-02-27std: Small cleanup and test improvementAlex Crichton-1/+1
This weeds out a bunch of warnings building stdtest on windows, and it also adds a check! macro to the io::fs tests to help diagnose errors that are cropping up on windows platforms as well. cc #12516
2014-02-24std: make .swap_remove return Option<T>.Huon Wilson-20/+30
This is one of the last raw "indexing" method on vectors that returns `T` instead of the Option.
2014-02-23auto merge of #12311 : brson/rust/unstable, r=alexcrichtonbors-2/+2
With the stability attributes we can put public-but unstable modules next to others, so this moves `intrinsics` and `raw` out of the `unstable` module (and marks both as `#[experimental]`).
2014-02-23std: Move raw to std::rawBrian Anderson-2/+2
Issue #1457
2014-02-23Move std::{trie, hashmap} to libcollectionsAlex Crichton-6/+5
These two containers are indeed collections, so their place is in libcollections, not in libstd. There will always be a hash map as part of the standard distribution of Rust, but by moving it out of the standard library it makes libstd that much more portable to more platforms and environments. This conveniently also removes the stuttering of 'std::hashmap::HashMap', although 'collections::HashMap' is only one character shorter.
2014-02-22Move std::num::Integer to libnumBrendan Zabarauskas-3/+3
2014-02-20Mass rename if_ok! to try!Alex Crichton-3/+3
This "bubble up an error" macro was originally named if_ok! in order to get it landed, but after the fact it was discovered that this name is not exactly desirable. The name `if_ok!` isn't immediately clear that is has much to do with error handling, and it doesn't look fantastic in all contexts (if if_ok!(...) {}). In general, the agreed opinion about `if_ok!` is that is came in as subpar. The name `try!` is more invocative of error handling, it's shorter by 2 letters, and it looks fitting in almost all circumstances. One concern about the word `try!` is that it's too invocative of exceptions, but the belief is that this will be overcome with documentation and examples. Close #12037
2014-02-20move extra::test to libtestLiigo Zhuang-1/+2
2014-02-15auto merge of #12298 : alexcrichton/rust/rustdoc-testing, r=sfacklerbors-4/+4
It's too easy to forget the `rust` tag to test something. Closes #11698
2014-02-15auto merge of #12272 : alexcrichton/rust/snapshot, r=kballardbors-4/+2
This notably contains the `extern mod` => `extern crate` change. Closes #9880
2014-02-15std: clean up ptr a bitCorey Richardson-38/+38
2014-02-14Fix all code examplesAlex Crichton-4/+4
2014-02-14Register new snapshotsAlex Crichton-4/+2
This enables the parser error for `extern mod` => `extern crate` transitions.
2014-02-14return value/use extra::test::black_box in benchmarkslpy-8/+11
2014-02-13remove duplicate function from std::ptr (is_null, is_not_null, offset, ↵JeremyLetang-10/+11
mut_offset)
2014-02-13Add some missing Show implementations in libstdBrendan Zabarauskas-0/+42
2014-02-11vec -- introduce local var to make clear what subportion is being borrowedNiko Matsakis-2/+2
2014-02-11std -- replaces uses where const borrows would be requiredNiko Matsakis-18/+21
2014-02-11Move replace and swap to std::mem. Get rid of std::utilEdward Wang-10/+9
Also move Void to std::any, move drop to std::mem and reexport in prelude.
2014-02-09std: Stop parameterizing some memcpy functions over RawPtrBrian Anderson-8/+8
It unsafe assumptions that any impl of RawPtr is for actual pointers, that they can be copied by memcpy. Removing it is easy, so I don't think it's solving a real problem.
2014-02-09std: Add move_val_init to mem. Replace direct intrinsic usageBrian Anderson-6/+5
2014-02-07auto merge of #12029 : zkamsler/rust/merge-sort-allocations, r=huonwbors-5/+104
This pull request: 1) Changes the initial insertion sort to be in-place, and defers allocation of working set until merge is needed. 2) Increases the increases the maximum run length to use insertion sort for from 8 to 32 elements. This increases the size of vectors that will not allocate, and reduces the number of merge passes by two. It seemed to be the sweet spot in the benchmarks that I ran. Here are the results of some benchmarks. Note that they are sorting u64s, so types that are more expensive to compare or copy may have different behaviors. Before changes: ``` test vec::bench::sort_random_large bench: 719753 ns/iter (+/- 130173) = 111 MB/s test vec::bench::sort_random_medium bench: 4726 ns/iter (+/- 742) = 169 MB/s test vec::bench::sort_random_small bench: 344 ns/iter (+/- 76) = 116 MB/s test vec::bench::sort_sorted bench: 437244 ns/iter (+/- 70043) = 182 MB/s ``` Deferred allocation (8 element insertion sort): ``` test vec::bench::sort_random_large bench: 702630 ns/iter (+/- 88158) = 113 MB/s test vec::bench::sort_random_medium bench: 4529 ns/iter (+/- 497) = 176 MB/s test vec::bench::sort_random_small bench: 185 ns/iter (+/- 49) = 216 MB/s test vec::bench::sort_sorted bench: 425853 ns/iter (+/- 60907) = 187 MB/s ``` Deferred allocation (16 element insertion sort): ``` test vec::bench::sort_random_large bench: 692783 ns/iter (+/- 165837) = 115 MB/s test vec::bench::sort_random_medium bench: 4434 ns/iter (+/- 722) = 180 MB/s test vec::bench::sort_random_small bench: 187 ns/iter (+/- 38) = 213 MB/s test vec::bench::sort_sorted bench: 393783 ns/iter (+/- 85548) = 203 MB/s ``` Deferred allocation (32 element insertion sort): ``` test vec::bench::sort_random_large bench: 682556 ns/iter (+/- 131008) = 117 MB/s test vec::bench::sort_random_medium bench: 4370 ns/iter (+/- 1369) = 183 MB/s test vec::bench::sort_random_small bench: 179 ns/iter (+/- 32) = 223 MB/s test vec::bench::sort_sorted bench: 358353 ns/iter (+/- 65423) = 223 MB/s ``` Deferred allocation (64 element insertion sort): ``` test vec::bench::sort_random_large bench: 712040 ns/iter (+/- 132454) = 112 MB/s test vec::bench::sort_random_medium bench: 4425 ns/iter (+/- 784) = 180 MB/s test vec::bench::sort_random_small bench: 179 ns/iter (+/- 81) = 223 MB/s test vec::bench::sort_sorted bench: 317812 ns/iter (+/- 62675) = 251 MB/s ``` This is the best I could manage with the basic merge sort while keeping the invariant that the original vector must contain each element exactly once when the comparison function is called. If one is not married to a stable sort, an in-place n*log(n) sorting algorithm may have better performance in some cases. for #12011 cc @huonw
2014-02-07Reduced allocations in merge_sort for short vectorsZach Kamsler-5/+104
Added a seperate in-place insertion sort for short vectors. Increased threshold for insertion short for 8 to 32 elements for small types and 16 for larger types. Added benchmarks for sorting larger types.
2014-02-05Implement clone() for TCP/UDP/Unix socketsAlex Crichton-1/+1
This is part of the overall strategy I would like to take when approaching issue #11165. The only two I/O objects that reasonably want to be "split" are the network stream objects. Everything else can be "split" by just creating another version. The initial idea I had was the literally split the object into a reader and a writer half, but that would just introduce lots of clutter with extra interfaces that were a little unnnecssary, or it would return a ~Reader and a ~Writer which means you couldn't access things like the remote peer name or local socket name. The solution I found to be nicer was to just clone the stream itself. The clone is just a clone of the handle, nothing fancy going on at the kernel level. Conceptually I found this very easy to wrap my head around (everything else supports clone()), and it solved the "split" problem at the same time. The cloning support is pretty specific per platform/lib combination: * native/win32 - uses some specific WSA apis to clone the SOCKET handle * native/unix - uses dup() to get another file descriptor * green/all - This is where things get interesting. When we support full clones of a handle, this implies that we're allowing simultaneous writes and reads to happen. It turns out that libuv doesn't support two simultaneous reads or writes of the same object. It does support *one* read and *one* write at the same time, however. Some extra infrastructure was added to just block concurrent writers/readers until the previous read/write operation was completed. I've added tests to the tcp/unix modules to make sure that this functionality is supported everywhere.
2014-02-04auto merge of #11951 : dmanescu/rust/reserve-rename, r=huonwbors-14/+14
Changes in std::{str,vec,hashmap} and extra::{priority_queue,ringbuf}. Fixes #11949
2014-02-04Rename reserve to reserve_exact and reserve_at_least to reserveDavid Manescu-14/+14
Changes in std::{str,vec,hashmap} and extra::{priority_queue,ringbuf}. Fixes #11949
2014-02-01auto merge of #11974 : huonw/rust/no-at-vec, r=pcwaltonbors-60/+0
This removes @[] from the parser as well as much of the handling of it (and `@str`) from the compiler as I can find. I've just rebased @pcwalton's (already reviewed) `@str` removal (and fixed the problems in a separate commit); the only new work is the trailing commits with my authorship. Closes #11967
2014-02-02std,extra: remove use of & support for @[].Huon Wilson-60/+0
2014-02-01auto merge of #11944 : nathanielherman/rust/vec_opt, r=alexcrichtonbors-50/+52
Closes #11733
2014-02-01auto merge of #11930 : bjz/rust/next_power_of_two, r=huonwbors-2/+2
2014-01-31Fix minor doc typosVirgile Andreani-1/+1
2014-01-31Introduce marker types for indicating variance and for opting outNiko Matsakis-9/+10
of builtin bounds. Fixes #10834. Fixes #11385. cc #5922.
2014-02-01Make next_power_of_two generic for unsigned integersBrendan Zabarauskas-2/+2
Also rename `next_power_of_two_opt` to `checked_next_power_of_two`.
2014-01-30Make mut_last return Option instead of failing on empty vector (and add a ↵Nathaniel Herman-4/+14
test for mut_last)
2014-01-30Make pop_ref and mut_pop_ref return Option instead of failing on empty vectorsNathaniel Herman-24/+20
2014-01-30Make shift_ref and mut_shift_ref return Option instead of failingNathaniel Herman-24/+20
2014-01-28Rename ImmutableCopyableVector to ImmutableCloneableVectorVirgile Andreani-2/+2
2014-01-28Rename OwnedCopyableVector to OwnedCloneableVectorVirgile Andreani-2/+2