mirror of
https://github.com/dlang/phobos.git
synced 2025-05-05 09:30:49 +03:00
Fix topN(Range, Range) disrespect of its predicate
This commit is contained in:
parent
3f9a33f91d
commit
d70356e019
1 changed files with 11 additions and 1 deletions
|
@ -2301,7 +2301,7 @@ auto topN(alias less = "a < b",
|
||||||
|
|
||||||
static assert(ss == SwapStrategy.unstable,
|
static assert(ss == SwapStrategy.unstable,
|
||||||
"Stable topN not yet implemented");
|
"Stable topN not yet implemented");
|
||||||
auto heap = BinaryHeap!Range1(r1);
|
auto heap = BinaryHeap!(Range1, less)(r1);
|
||||||
for (; !r2.empty; r2.popFront())
|
for (; !r2.empty; r2.popFront())
|
||||||
{
|
{
|
||||||
heap.conditionalInsert(r2.front);
|
heap.conditionalInsert(r2.front);
|
||||||
|
@ -2326,6 +2326,16 @@ unittest
|
||||||
assert(t == [ 0, 1, 2, 2, 3 ]);
|
assert(t == [ 0, 1, 2, 2, 3 ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bug 15420
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
int[] a = [ 5, 7, 2, 6, 7 ];
|
||||||
|
int[] b = [ 2, 1, 5, 6, 7, 3, 0 ];
|
||||||
|
topN!"a > b"(a, b);
|
||||||
|
sort!"a > b"(a);
|
||||||
|
assert(a == [ 7, 7, 7, 6, 6 ]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Copies the top $(D n) elements of the input range $(D source) into the
|
Copies the top $(D n) elements of the input range $(D source) into the
|
||||||
random-access range $(D target), where $(D n =
|
random-access range $(D target), where $(D n =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue