aboutsummaryrefslogtreecommitdiff
path: root/core/slice
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2022-10-18 00:06:21 +0100
committerGitHub <noreply@github.com>2022-10-18 00:06:21 +0100
commit075040ae057e48bb9df4cb03bc0ea39e98a804ad (patch)
treef82c14e81ebe5388ef62ca61475a2e15effb9907 /core/slice
parentaa799d6a0d759f7efd5a08b7af47a9eb94adc337 (diff)
Update sort_private.odin
Diffstat (limited to 'core/slice')
-rw-r--r--core/slice/sort_private.odin5
1 files changed, 3 insertions, 2 deletions
diff --git a/core/slice/sort_private.odin b/core/slice/sort_private.odin
index 86a6f5928..32eb7d417 100644
--- a/core/slice/sort_private.odin
+++ b/core/slice/sort_private.odin
@@ -177,7 +177,6 @@ _quick_sort_general :: proc(data: $T/[]$E, a, b, max_depth: int, call: $P, $KIND
}
-// merge sort
_stable_sort_general :: proc(data: $T/[]$E, call: $P, $KIND: Sort_Kind) where (ORD(E) && KIND == .Ordered) || (KIND != .Ordered) #no_bounds_check {
less :: #force_inline proc(a, b: E, call: P) -> bool {
when KIND == .Ordered {
@@ -190,7 +189,9 @@ _stable_sort_general :: proc(data: $T/[]$E, call: $P, $KIND: Sort_Kind) where (O
#panic("unhandled Sort_Kind")
}
}
-
+
+ // insertion sort
+ // TODO(bill): use a different algorithm as insertion sort is O(n^2)
n := len(data)
for i in 1..<n {
for j := i; j > 0 && less(data[j], data[j-1], call); j -= 1 {