Bug 15421 – The behaviours of the topNs differ with the bottom

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-12-08T11:56:00Z
Last change time
2016-12-09T15:30:05Z
Keywords
bootcamp
Assigned to
nobody
Creator
lt.infiltrator
Blocks
15401

Comments

Comment #0 by lt.infiltrator — 2015-12-08T11:56:19Z
============ import std.algorithm; void main() { auto a = [ 9, 8, 0, 3, 5, 25, 43, 4, 2, 0, 7 ]; auto b = [ 9, 8, 0, 3, 5, 25, 43, 4, 2, 0, 7 ]; topN(a, 4); topN(b[0 .. 4], b[4 .. $]); sort(a[0 .. 4]); sort(a[4 .. $]); sort(b[0 .. 4]); sort(b[4 .. $]); assert(a[0 .. 4] == b[0 .. 4]); assert(a[4 .. $] == b[4 .. $]); // This one fails assert(a == b); // As would this one obviously } ============ Basically, topN(Range, index) rearranges *all* of the elements such that all those on the left are smaller (or whatever the predicate specifies) than those on the right, while still keeping all the elements. However, topN(Range, Range) leaves the second range untouched such that you end up with with some elements disappearing and others being duplicated.
Comment #1 by lt.infiltrator — 2015-12-08T12:08:07Z
Comment #2 by andrei — 2015-12-08T14:07:11Z
Yah that is/was a bug.