Skip to content

Commit 7d2e940

Browse files
author
Stjepan Glavina
committed
Improve wording per brson's request
1 parent c40dc37 commit 7d2e940

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

text/0000-unstable-sort.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ Add an unstable sort to libcore.
1414
At the moment, the only sort function we have in libstd is `slice::sort`. It is stable,
1515
allocates additional memory, and is unavailable in `#![no_std]` environments.
1616

17-
Stable sorting, although a good default, is very rarely useful. Users much more often
18-
value higher performance, lower memory overhead, and compatibility with `#![no_std]`.
17+
The sort function is stable, which is a good but conservative default. However,
18+
stability is rarely a required property in practice, and some other characteristics
19+
of sort algorithms like higher performance or lower memory overhead are often more
20+
desirable.
1921

20-
Having a really performant, non-allocating sort function in libcore would cover these
21-
needs. At the moment, Rust is compromising on these highly regarded qualities for a
22-
systems programming language by not offering a built-in alternative.
22+
Having a performant, non-allocating unstable sort function in libcore would cover those
23+
needs. At the moment Rust is not offering a built-in alternative (only crates), which
24+
is unusual for a systems programming language.
2325

2426
**Q: What is stability?**<br>
2527
A: A sort function is stable if it doesn't reorder equal elements. For example:
@@ -39,8 +41,8 @@ assert!(orig == v); // MAY FAIL!
3941
**Q: When is stability useful?**<br>
4042
A: Not very often. A typical example is sorting columns in interactive GUI tables.
4143
E.g. you want to have rows sorted by column X while breaking ties by column Y, so you
42-
first click on column Y and then click on column X. This is a rare case where stable
43-
sorting is important.
44+
first click on column Y and then click on column X. This is a use case where stability
45+
is important.
4446

4547
**Q: Can stable sort be performed using unstable sort?**<br>
4648
A: Yes. If we transform `[T]` into `[(T, usize)]` by pairing every element with it's
@@ -122,7 +124,7 @@ assert!(v == [1, 2, -3, 4, -5]);
122124
Proposed implementaton is available in the [pdqsort][stjepang-pdqsort] crate.
123125

124126
**Q: Why choose this particular sort algorithm?**<br>
125-
A: First, let's see what unstable sort algorithms other languages use:
127+
A: First, let's analyse what unstable sort algorithms other languages use:
126128

127129
* C: quicksort
128130
* C++: introsort
@@ -142,7 +144,7 @@ Java (talking about `Arrays.sort`, not `Collections.sort`) uses dual-pivot
142144
quicksort. It is an improvement of quicksort that chooses two pivots for finer
143145
grained partitioning, offering better performance in practice.
144146

145-
A very interesting improvement of introsort is [pattern-defeating quicksort][orlp-pdqsort],
147+
A recent improvement of introsort is [pattern-defeating quicksort][orlp-pdqsort],
146148
which is substantially faster in common cases. One of the key tricks pdqsort
147149
uses is block partitioning described in the [BlockQuicksort][blockquicksort] paper.
148150
This algorithm still hasn't been built into in any programming language's
@@ -163,7 +165,7 @@ that, `slice::sort` should be generally slower than pdqsort.
163165
**Q: What about radix sort?**<br>
164166
A: Radix sort is usually blind to patterns in slices. It treats totally random
165167
and partially sorted the same way. It is probably possible to improve it
166-
by combining it with other techniques until it becomes a hybrid sort. Moreover,
168+
by combining it with some other techniques, but it's not trivial. Moreover,
167169
radix sort is incompatible with comparison-based sorting, which makes it
168170
an awkward choice for a general-purpose API. On top of all this, it's
169171
not even that much faster than pdqsort anyway.
@@ -183,8 +185,8 @@ as a faster non-allocating alternative. The documentation for
183185
# Drawbacks
184186
[drawbacks]: #drawbacks
185187

186-
The implementation of sort algorithms will grow bigger, and there will be more
187-
code to review.
188+
The amount of code for sort algorithms will grow, and there will be more code
189+
to review.
188190

189191
It might be surprising to discover cases where `slice::sort` is faster than
190192
`slice::sort_unstable`. However, these peculiarities can be explained in

0 commit comments

Comments
 (0)