about summary refs log tree commit diff
path: root/src/libcollections/slice.rs
AgeCommit message (Collapse)AuthorLines
2017-06-13Merge crate `collections` into `alloc`Murarth-1943/+0
2017-06-02Rollup merge of #42370 - mbrubeck:docs, r=frewsxcvMark Simulacrum-0/+2
Add [[T]] -> [T] examples to SliceConcatExt docs None
2017-06-02Auto merge of #41670 - scottmcm:slice-rotate, r=alexcrichtonbors-0/+55
Add an in-place rotate method for slices to libcore A helpful primitive for moving chunks of data around inside a slice. For example, if you have a range selected and are drag-and-dropping it somewhere else (Example from [Sean Parent's talk](https://youtu.be/qH6sSOr-yk8?t=560)). (If this should be an RFC instead of a PR, please let me know.) Edit: changed example
2017-06-01Add [[T]] -> [T] examples to SliceConcatExt docsMatt Brubeck-0/+2
2017-05-26Update documentation for indexing/slicing methodsMichael Kohl-2/+12
See #39911
2017-05-22Slice::into_vec: Don't link to Vec::into_boxed_sliceColin Wallace-3/+1
The documentation for this method appears on multiple different pages, which causes the relative links to not always work.
2017-05-22Mention Vec::into_boxed_slice in docs for [T]::into_vec.Colin Wallace-0/+5
`Vec::into_boxed_slice` and `[T]::into_vec` are inverses, so it makes sense to mention the other in their respective documentation for visibility. `Vec::into_boxed_slice` already mentions `[T]::into_vec`, but not the other way around until now.
2017-05-21Stop returning k from [T]::rotateScott McMurray-7/+7
2017-05-21Tweak comment wordingScott McMurray-2/+2
2017-05-21Update slice_rotate to a real tracking numberScott McMurray-1/+1
2017-05-21Change the doctest example to slideScott McMurray-9/+12
Batch-insert is better done with Vec::splice
2017-05-21Add an in-place rotate method for slices to libcoreScott McMurray-0/+52
A helpful primitive for moving chunks of data around inside a slice. In particular, adding elements to the end of a Vec then moving them somewhere else, as a way to do efficient multiple-insert. (There's drain for efficient block-remove, but no easy way to block-insert.) Talk with another example: <https://youtu.be/qH6sSOr-yk8?t=560>
2017-05-06Add links between `slice::{copy,clone}_from_slice` in docs.Corey Farwell-0/+9
2017-04-23Add Vec::splice and String::spliceSimon Sapin-5/+1
2017-04-13Auto merge of #41009 - scottmcm:toowned-clone-into, r=alexcrichtonbors-0/+13
Add a resource-reusing method to `ToOwned` `ToOwned::to_owned` generalizes `Clone::clone`, but `ToOwned` doesn't have an equivalent to `Clone::clone_from`. This PR adds such a method as `clone_into` under a new unstable feature `toowned_clone_into`. Analogous to `clone_from`, this has the obvious default implementation in terms of `to_owned`. I've updated the `libcollections` impls: for `T:Clone` it uses `clone_from`, for `[T]` I moved the code from `Vec::clone_from` and implemented that in terms of this, and for `str` it's a predictable implementation in terms of `[u8]`. Used it in `Cow::clone_from` to reuse resources when both are `Cow::Owned`, and added a test that `Cow<str>` thus keeps capacity in `clone_from` in that situation. The obvious question: is this the right place for the method? - It's here so it lives next to `to_owned`, making the default implementation reasonable, and avoiding another trait. But allowing method syntax forces a name like `clone_into`, rather than something more consistent like `owned_from`. - Another trait would allow `owned_from` and could support multiple owning types per borrow type. But it'd be another single-method trait that generalizes `Clone`, and I don't know how to give it a default impl in terms of `ToOwned::to_owned`, since a blanket would mean overlapping impls problems. I did it this way as it's simpler and many of the `Borrow`s/`AsRef`s don't make sense with `owned_from` anyway (`[T;1]:Borrow<[T]>`, `Arc<T>:Borrow<T>`, `String:AsRef<OsStr>`...). I'd be happy to re-do it the other way, though, if someone has a good solution for the default handling. (I can also update with `CStr`, `OsStr`, and `Path` once a direction is decided.)
2017-04-12Add ToOwned::clone_into (unstable as toowned_clone_into)Scott McMurray-0/+13
to_owned generalizes clone; this generalizes clone_from. Use to_owned to give it a default impl. Customize the impl for [T], str, and T:Clone. Use it in Cow::clone_from to reuse resources when cloning Owned into Owned.
2017-04-09Move away from the ad-hoc NoDrop unionsSimonas Kazlauskas-9/+3
2017-04-04add [T]::rsplit() and rsplit_mut() #41020Jason Orendorff-0/+68
2017-03-31Auto merge of #40737 - nagisa:safe-slicing-strs, r=BurntSushibors-4/+4
Checked slicing for strings cc https://github.com/rust-lang/rust/issues/39932
2017-03-23Fix markdown links to pdqsortStjepan Glavina-3/+3
2017-03-22Checked (and unchecked) slicing for strings?Simonas Kazlauskas-4/+4
What is this magic‽
2017-03-22Various fixes to wording consistency in the docsStjepan Glavina-19/+18
2017-03-21Tweak the constants a bitStjepan Glavina-2/+2
2017-03-21Fix a doctestStjepan Glavina-1/+1
2017-03-21Address Alex's PR commentsStjepan Glavina-0/+6
2017-03-21Implement feature sort_unstableStjepan Glavina-28/+128
2017-03-19Rollup merge of #40646 - russmack:issue-40435-mention-none, r=frewsxcvCorey Farwell-4/+4
Add mention of None as possible return. Closes #40435. This commit adds a small mention to some methods that None is returned when the slice is empty.
2017-03-19Rollup merge of #40603 - QuietMisdreavus:slice-ptr-docs, r=GuillaumeGomezCorey Farwell-4/+4
minor wording tweak to slice::{as_ptr, as_mut_ptr} Per #37334, the slice-as-pointer methods mentioned that "modifying the slice may cause its buffer to be reallocated", when in fact modifying the *slice* itself would cause no such change. (It is a borrow, after all!) This is a tweak to the wording of that line to stress it's the *collection* that could cause the buffer to be reallocated. r? @steveklabnik
2017-03-19Add mention of None as possible return. Closes #40435.Russell Mackenzie-4/+4
2017-03-17minor wording tweak to slice::{as_ptr, as_mut_ptr}QuietMisdreavus-4/+4
2017-03-13Remove function invokation parens from documentation links.Corey Farwell-11/+11
This was never established as a convention we should follow in the 'More API Documentation Conventions' RFC: https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md
2017-02-04Slightly optimize slice::sortStjepan Glavina-32/+36
First, get rid of some bound checks. Second, instead of comparing by ternary `compare` function, use a binary function testing whether an element is less than some other element. This apparently makes it easier for the compiler to reason about the code. Benchmark: ``` name before ns/iter after ns/iter diff ns/iter diff % slice::bench::sort_large_ascending 8,969 (8919 MB/s) 7,410 (10796 MB/s) -1,559 -17.38% slice::bench::sort_large_big_ascending 355,640 (3599 MB/s) 359,137 (3564 MB/s) 3,497 0.98% slice::bench::sort_large_big_descending 427,112 (2996 MB/s) 424,721 (3013 MB/s) -2,391 -0.56% slice::bench::sort_large_big_random 2,207,799 (579 MB/s) 2,138,804 (598 MB/s) -68,995 -3.13% slice::bench::sort_large_descending 13,694 (5841 MB/s) 13,514 (5919 MB/s) -180 -1.31% slice::bench::sort_large_mostly_ascending 239,697 (333 MB/s) 203,542 (393 MB/s) -36,155 -15.08% slice::bench::sort_large_mostly_descending 270,102 (296 MB/s) 234,263 (341 MB/s) -35,839 -13.27% slice::bench::sort_large_random 513,406 (155 MB/s) 470,084 (170 MB/s) -43,322 -8.44% slice::bench::sort_large_random_expensive 23,650,321 (3 MB/s) 23,675,098 (3 MB/s) 24,777 0.10% slice::bench::sort_medium_ascending 143 (5594 MB/s) 132 (6060 MB/s) -11 -7.69% slice::bench::sort_medium_descending 197 (4060 MB/s) 188 (4255 MB/s) -9 -4.57% slice::bench::sort_medium_random 3,358 (238 MB/s) 3,271 (244 MB/s) -87 -2.59% slice::bench::sort_small_ascending 32 (2500 MB/s) 32 (2500 MB/s) 0 0.00% slice::bench::sort_small_big_ascending 97 (13195 MB/s) 97 (13195 MB/s) 0 0.00% slice::bench::sort_small_big_descending 247 (5182 MB/s) 249 (5140 MB/s) 2 0.81% slice::bench::sort_small_big_random 502 (2549 MB/s) 498 (2570 MB/s) -4 -0.80% slice::bench::sort_small_descending 55 (1454 MB/s) 61 (1311 MB/s) 6 10.91% slice::bench::sort_small_random 358 (223 MB/s) 356 (224 MB/s) -2 -0.56% ```
2017-01-26Rewrite the first sentence in slice::sortStjepan Glavina-2/+2
For every method, the first sentence should consisely explain what it does, not how. This sentence usually starts with a verb. It's really weird for `sort` to be explained in terms of another function, namely `sort_by`. There's no need for that because it's obvious how `sort` sorts elements: there is `T: Ord`. If `sort_by_key` does not have to explicitly state how it's implemented, then `sort` doesn't either.
2017-01-25Remove trailing whitespaceStjepan Glavina-1/+1
2017-01-25Fix: insertion_len -> max_insertionStjepan Glavina-1/+1
2017-01-25Expand the sort docsStjepan Glavina-11/+33
2017-01-25Fix wording around sort guaranteesSteve Klabnik-2/+5
Fixes #38524
2017-01-19Rollup merge of #39165 - frewsxcv:slice, r=GuillaumeGomezGuillaume Gomez-10/+24
A few improvements to the slice docs. * Simplify `Option::iter_mut` doc example. * Document 'empty' corner-cases for `slice::{starts_with, ends_with}`. * Indicate 'true' as code-like.
2017-01-18A few improvements to the slice docs.Corey Farwell-10/+24
* Simplify `Option::iter_mut` doc example. * Document 'empty' corner-cases for `slice::{starts_with, ends_with}`. * Indicate 'true' as code-like.
2017-01-18collections: update docs of slice get() and friendsGeorg Brandl-8/+17
for the new SliceIndex trait. Also made the docs of the unchecked versions a bit clearer; they return a reference, not an "unsafe pointer".
2017-01-12[libcollections] [doc] Fix typo in documentationBehnam Esfahbod-1/+1
2016-12-17Minor fix in the merge_sort commentsStjepan Glavina-3/+3
There was an off-by-one error discovered by @tbelaire. So, the two invariants we are enforcing are: 1. Run lengths are decreasing. 2. Sum of lengths of any two adjacent runs is less than the length of their predecessor. This commit changes the comment to be clearer and have correct bounds on `i`.
2016-12-08Inline nested fn collapseStjepan Glavina-0/+1
Since merge_sort is generic and collapse isn't, that means calls to collapse won't be inlined. inlined. Therefore, we must stick an `#[inline]` above `fn collapse`.
2016-12-07Implement a faster sort algorithmStjepan Glavina-180/+298
This is a complete rewrite of the standard sort algorithm. The new algorithm is a simplified variant of TimSort. In summary, the changes are: * Improved performance, especially on partially sorted inputs. * Performs less comparisons on both random and partially sorted inputs. * Decreased the size of temporary memory: the new sort allocates 4x less.
2016-11-26Overload get{,_mut}{,_unchecked}Steven Fackler-4/+14
2016-10-31Changed most vec! invocations to use square bracesiirelu-1/+1
Most of the Rust community agrees that the vec! macro is clearer when called using square brackets [] instead of regular brackets (). Most of these ocurrences are from before macros allowed using different types of brackets. There is one left unchanged in a pretty-print test, as the pretty printer still wants it to have regular brackets.
2016-10-08Add missing urls in slice doc moduleGuillaume Gomez-7/+19
2016-09-30Rollup merge of #36623 - GuillaumeGomez:doc_typos, r=steveklabnikSteve Klabnik-23/+25
Fix some typos and improve doc comments style r? @steveklabnik
2016-09-24Fix some typos and improve doc comments styleGuillaume Gomez-23/+25
2016-09-20Minor correction in `sort_by_key` doc commentNick Platt-1/+1