From a040be957ff3db94a1f35f73d4fc1b207ec1c526 Mon Sep 17 00:00:00 2001 From: Andrea Piseri Date: Wed, 13 Apr 2022 10:55:16 +0200 Subject: [PATCH] Fix tail recursion in `_quick_sort_general` The `if` statement should have been a `for` loop, in order to allow recursively sorting the subarrays with quicksort, and not resort to shell sort after one step. --- core/slice/sort_private.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/slice/sort_private.odin b/core/slice/sort_private.odin index 7abd2f1ce..d93d74bf9 100644 --- a/core/slice/sort_private.odin +++ b/core/slice/sort_private.odin @@ -150,7 +150,7 @@ _quick_sort_general :: proc(data: $T/[]$E, a, b, max_depth: int, call: $P, $KIND a, b, max_depth := a, b, max_depth - if b-a > 12 { // only use shell sort for lengths <= 12 + for b-a > 12 { // only use shell sort for lengths <= 12 if max_depth == 0 { heap_sort(data, a, b, call) return