From b99ea332f013d32d54734f9c2208031012d5de87 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 5 Dec 2020 23:14:14 +0200 Subject: [PATCH] cgen,builtin: fix sort for []u64 --- vlib/builtin/array.v | 20 ++++++++++++++++++++ vlib/v/gen/cgen.v | 3 +++ 2 files changed, 23 insertions(+) diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index 166ab1c5c3..f2f4842254 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -531,6 +531,26 @@ fn compare_ints_reverse(a &int, b &int) int { return 0 } +fn compare_u64s(a &u64, b &u64) int { + if *a < *b { + return -1 + } + if *a > *b { + return 1 + } + return 0 +} + +fn compare_u64s_reverse(a &u64, b &u64) int { + if *a > *b { + return -1 + } + if *a < *b { + return 1 + } + return 0 +} + fn compare_floats(a &f64, b &f64) int { if *a < *b { return -1 diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index c872b82e26..460946be2f 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -4866,6 +4866,9 @@ fn (mut g Gen) gen_array_sort(node ast.CallExpr) { table.int_type { compare_fn = 'compare_ints' } + table.u64_type { + compare_fn = 'compare_u64s' + } table.string_type { compare_fn = 'compare_strings' }