Commit graph

13 commits

Author SHA1 Message Date
mark
2c31b45ae8 mv std libs to library/ 2020-07-27 19:51:13 -05:00
David Tolnay
1c4d453969
Format liballoc with rustfmt 2019-11-29 20:25:07 -08:00
Ralf Jung
5b78e98a37 bump rand to fix Miri failures 2019-08-04 14:50:26 +02:00
Mazdak Farrokhzad
2396780cda liballoc: revert nested imports style changes. 2019-02-03 08:27:44 +01:00
Mazdak Farrokhzad
7693e3e666 liballoc: refactor & fix some imports. 2019-02-02 10:14:40 +01:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Ralf Jung
3414be0b3e fix deprecation warnings in liballoc benches 2018-12-21 11:33:29 +01:00
Kazuyoshi Kato
f930087159 Fix slice's benchmarks
Fixes #54013.
2018-10-10 22:55:12 -07:00
varkor
785e3c38fe Add lexicographic sorting benchmark 2018-03-18 12:50:58 +00:00
Corey Farwell
66ef6b9c09 Deprecate [T]::rotate in favor of [T]::rotate_{left,right}.
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-12-24 23:01:24 -08:00
John-John Tedro
9bea79bd5e Fix use of rand in liballoc benches 2017-11-29 20:14:52 +01:00
Stjepan Glavina
12205f1450 Improve sort tests and benchmarks 2017-06-24 17:14:42 +02:00
Murarth
eadda7665e Merge crate collections into alloc 2017-06-13 23:37:34 -07:00
Renamed from src/libcollections/benches/slice.rs (Browse further)