about summary refs log tree commit diff
path: root/src/liballoc/benches/slice.rs
AgeCommit message (Collapse)AuthorLines
2019-02-03liballoc: revert nested imports style changes.Mazdak Farrokhzad-4/+3
2019-02-02liballoc: refactor & fix some imports.Mazdak Farrokhzad-6/+5
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-21fix deprecation warnings in liballoc benchesRalf Jung-1/+2
2018-10-10Fix slice's benchmarksKazuyoshi Kato-10/+13
Fixes #54013.
2018-03-18Add lexicographic sorting benchmarkvarkor-0/+15
2017-12-24Deprecate [T]::rotate in favor of [T]::rotate_{left,right}.Corey Farwell-1/+1
Background ========== Slices currently have an unstable [`rotate`] method which rotates elements in the slice to the _left_ N positions. [Here][tracking] is the tracking issue for this unstable feature. ```rust let mut a = ['a', 'b' ,'c', 'd', 'e', 'f']; a.rotate(2); assert_eq!(a, ['c', 'd', 'e', 'f', 'a', 'b']); ``` Proposal ======== Deprecate the [`rotate`] method and introduce `rotate_left` and `rotate_right` methods. ```rust let mut a = ['a', 'b' ,'c', 'd', 'e', 'f']; a.rotate_left(2); assert_eq!(a, ['c', 'd', 'e', 'f', 'a', 'b']); ``` ```rust let mut a = ['a', 'b' ,'c', 'd', 'e', 'f']; a.rotate_right(2); assert_eq!(a, ['e', 'f', 'a', 'b', 'c', 'd']); ``` Justification ============= I used this method today for my first time and (probably because I’m a naive westerner who reads LTR) was surprised when the docs mentioned that elements get rotated in a left-ward direction. I was in a situation where I needed to shift elements in a right-ward direction and had to context switch from the main problem I was working on and think how much to rotate left in order to accomplish the right-ward rotation I needed. Ruby’s `Array.rotate` shifts left-ward, Python’s `deque.rotate` shifts right-ward. Both of their implementations allow passing negative numbers to shift in the opposite direction respectively. Introducing `rotate_left` and `rotate_right` would: - remove ambiguity about direction (alleviating need to read docs 😉) - make it easier for people who need to rotate right [`rotate`]: https://doc.rust-lang.org/std/primitive.slice.html#method.rotate [tracking]: https://github.com/rust-lang/rust/issues/41891
2017-11-29Fix use of rand in liballoc benchesJohn-John Tedro-1/+1
2017-06-24Improve sort tests and benchmarksStjepan Glavina-19/+35
2017-06-13Merge crate `collections` into `alloc`Murarth-0/+358