From 48a2db7beeba63488cdcb826d1ca023e8c2421e5 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Mon, 30 Dec 2024 16:22:17 +0000 Subject: [PATCH] fix: QuickSort mergeRuns --- .../powersort/sort/dpqs/DualPivotQuicksort.java | 12 ++++++------ .../uni_marburg/powersort/sort/AbstractSortTest.java | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/de/uni_marburg/powersort/sort/dpqs/DualPivotQuicksort.java b/app/src/main/java/de/uni_marburg/powersort/sort/dpqs/DualPivotQuicksort.java index 0d50d43..2587829 100644 --- a/app/src/main/java/de/uni_marburg/powersort/sort/dpqs/DualPivotQuicksort.java +++ b/app/src/main/java/de/uni_marburg/powersort/sort/dpqs/DualPivotQuicksort.java @@ -818,13 +818,13 @@ public final class DualPivotQuicksort { a1 = mergeRuns(a, b, offset, -aim, run, lo, mi); a2 = mergeRuns(a, b, offset, 0, run, mi, hi); - Object[] dst = NaturalOrder.INSTANCE.compare(a1, a) == 0 ? b : a; + Object[] dst = a1 == a ? b : a; - int k = NaturalOrder.INSTANCE.compare(a1 , a)==0 ? run[lo] - offset : run[lo]; - int lo1 = NaturalOrder.INSTANCE.compare(a1 , b)==0 ? run[lo] - offset : run[lo]; - int hi1 = NaturalOrder.INSTANCE.compare(a1 , b)==0 ? run[mi] - offset : run[mi]; - int lo2 = NaturalOrder.INSTANCE.compare(a2 , b)==0 ? run[mi] - offset : run[mi]; - int hi2 = NaturalOrder.INSTANCE.compare(a2 , b)==0 ? run[hi] - offset : run[hi]; + int k = a1 == a ? run[lo] - offset : run[lo]; + int lo1 = a1 == b ? run[lo] - offset : run[lo]; + int hi1 = a1 == b ? run[mi] - offset : run[mi]; + int lo2 = a2 == b ? run[mi] - offset : run[mi]; + int hi2 = a2 == b ? run[hi] - offset : run[hi]; mergeParts(dst, k, a1, lo1, hi1, a2, lo2, hi2); return dst; diff --git a/app/src/test/java/de/uni_marburg/powersort/sort/AbstractSortTest.java b/app/src/test/java/de/uni_marburg/powersort/sort/AbstractSortTest.java index 4802fcf..e3c4f71 100644 --- a/app/src/test/java/de/uni_marburg/powersort/sort/AbstractSortTest.java +++ b/app/src/test/java/de/uni_marburg/powersort/sort/AbstractSortTest.java @@ -32,6 +32,7 @@ public abstract class AbstractSortTest { "3,7,-3", "10,10,-5", "17,17,-17", + "2,128,-64", // Large runs to trigger function `mergeRuns` of DualPivotQuicksort }) void test2(int numOfRuns, int runLength, int decreaseBetweenRuns) { Integer[] array = AscendingRuns.newAscendingRuns(numOfRuns, runLength, decreaseBetweenRuns).getCopy();