Skip to content

Commit 0860023

Browse files
committed
Fix sorting
1 parent 10a0558 commit 0860023

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

source/mir/ndslice/sorting.d

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ void quickSortImpl(alias less, Iterator)(Slice!Iterator slice) @trusted
293293
auto r = l;
294294
r += slice.length;
295295

296+
if(slice.length <= 1)
297+
return;
298+
296299
static if (naive > 1)
297300
{
298301
if (slice.length <= naive || __ctfe)
@@ -341,11 +344,6 @@ void quickSortImpl(alias less, Iterator)(Slice!Iterator slice) @trusted
341344
return;
342345
}
343346
}
344-
else
345-
{
346-
if(slice.length <= 1)
347-
return;
348-
}
349347

350348
// partition
351349
auto lessI = l;
@@ -1822,3 +1820,40 @@ unittest
18221820
auto hiI = frontI + 6;
18231821
assert(expandPartition!((a, b) => a < b)(frontI, lastI, loI, pivotI, hiI) == (frontI + 9));
18241822
}
1823+
1824+
version(mir_test)
1825+
unittest
1826+
{
1827+
import std.random;
1828+
import mir.ndslice.sorting: sort;
1829+
1830+
static struct StructA
1831+
{
1832+
double val0;
1833+
double val1;
1834+
double val2;
1835+
}
1836+
1837+
static struct StructB
1838+
{
1839+
ulong productId;
1840+
StructA strA;
1841+
}
1842+
1843+
auto createStructBArray(uint nbTrades)
1844+
{
1845+
auto rnd = Random(42);
1846+
1847+
auto p = StructA(0,0,0);
1848+
1849+
StructB[] ret;
1850+
foreach(i;0..nbTrades)
1851+
{
1852+
ret ~= StructB(uniform(0, nbTrades, rnd), p);
1853+
}
1854+
1855+
return ret;
1856+
}
1857+
1858+
auto arrayB = createStructBArray(10000).sort!((a,b) => a.productId<b.productId);
1859+
}

0 commit comments

Comments
 (0)