Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
- fix FeatureSort
- add error message for invalid unique divisor
- correctly rescale speed for size-mlt < 1
- add minSize parameter for runAll sorts
- add unique limit for runAll sorts
  • Loading branch information
amari-calipso committed May 26, 2024
1 parent 53b7ef2 commit d215e19
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
12 changes: 5 additions & 7 deletions GUI.opal
Original file line number Diff line number Diff line change
Expand Up @@ -640,15 +640,13 @@ new class GUI {
return;
}

if checkType(sizeMlt, float) {
float <- sizeMlt;
} else {
this.userWarn("Error", "Invalid size multiplier value. Please retry.");
return;
}

if checkType(uniqueDiv, float) {
float <- uniqueDiv;

if uniqueDiv < 1 {
this.userWarn("Error", "Minimum unique divisor is 1.");
return;
}
} else {
this.userWarn("Error", "Invalid unique divisor value. Please retry.");
return;
Expand Down
4 changes: 2 additions & 2 deletions sorts/FeatureSort.opal
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use UtilsIterablesStableSort;
use UtilsIterablesSort;

new class FeatureSort {
new method sortSubarray(subarray, mainArray) {
new int l = len(subarray);
if l <= 1 {
return;
}
UtilsIterablesStableSort(len(mainArray), mainArray).sort(subarray, 0, l);
UtilsIterablesSort(len(mainArray), mainArray).sort(subarray, 0, l);
}

new method __adaptAux(_) {
Expand Down
15 changes: 12 additions & 3 deletions threads/runAllSorts.opal
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
this.setVisual(runOpts["visual"]);

new function runAllSort(size, name, speed, toPush = None, killers = None, speedScale = 1, sizeLimit = None) {
new function runAllSort(size, name, speed, toPush = None, killers = None, speedScale = 1, sizeLimit = None, uniqueLimit = 2, minSize = 4) {
size *= runOpts["size-mlt"];
speed *= runOpts["size-mlt"] * runOpts["speed"];

if runOpts["size-mlt"] > 1 {
speed *= speedScale;
}
} elif runOpts["size-mlt"] < 1 {
speed /= speedScale;
}

int <- size;

if sizeLimit is not None && size > sizeLimit {
size = sizeLimit;
} elif size < minSize {
size = minSize;
}

new int unique = size // runOpts["unique-div"];
if unique < uniqueLimit {
unique = uniqueLimit;
}

if needsSeed {
Expand All @@ -29,7 +38,7 @@ new function runAllSort(size, name, speed, toPush = None, killers = None, speedS
}

this.runSortingProcess(
runOpts["distribution"], size, int(size / runOpts["unique-div"]),
runOpts["distribution"], size, unique,
runOpts["shuffle"], ct, name, speed,
killers = {} if killers is None else killers
);
Expand Down

0 comments on commit d215e19

Please sign in to comment.