From 959cb20e7b759546b6014fdcf9e7ad3ac7c2e474 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Tue, 21 Jan 2025 16:36:18 +0000 Subject: [PATCH] FasterFinnSort: stackLen calculation --- .../powersort/FinnSort/FasterFinnSort.java | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/de/uni_marburg/powersort/FinnSort/FasterFinnSort.java b/app/src/main/java/de/uni_marburg/powersort/FinnSort/FasterFinnSort.java index b1622ce..32fb651 100644 --- a/app/src/main/java/de/uni_marburg/powersort/FinnSort/FasterFinnSort.java +++ b/app/src/main/java/de/uni_marburg/powersort/FinnSort/FasterFinnSort.java @@ -171,23 +171,8 @@ public class FasterFinnSort { tmpLen = workLen; } - /* - * Allocate runs-to-be-merged stack (which cannot be expanded). The - * stack length requirements are described in listsort.txt. The C - * version always uses the same stack length (85), but this was - * measured to be too expensive when sorting "mid-sized" arrays (e.g., - * 100 elements) in Java. Therefore, we use smaller (but sufficiently - * large) stack lengths for smaller arrays. The "magic numbers" in the - * computation below must be changed if MIN_MERGE is decreased. See - * the MIN_MERGE declaration above for more information. - * The maximum value of 49 allows for an array up to length - * Integer.MAX_VALUE-4, if array is filled by the worst case stack size - * increasing scenario. More explanations are given in section 4 of: - * http://envisage-project.eu/wp-content/uploads/2015/02/sorting.pdf - */ - int stackLen = (len < 120 ? 5 : - len < 1542 ? 10 : - len < 119151 ? 24 : 49); + // TODO: Verify if this is correct + int stackLen = ((int) Math.ceil(Math.log(rangeSize))) + 2; runBase = new int[stackLen]; runLen = new int[stackLen]; runPower = new int[stackLen];