have sort_with_indices allocate. Add a couple convenience procs for using the indices result to sort other slices.

This commit is contained in:
Phil
2022-09-01 11:46:59 -07:00
parent 000861cba8
commit 002bec256a
2 changed files with 32 additions and 15 deletions
+4 -10
View File
@@ -51,23 +51,17 @@ test_sort_with_indices :: proc(t: ^testing.T) {
r := rand.create(seed)
vals := make([]u64, test_size)
f_idx := make([]int, test_size) // Forward index, will be sorted
defer delete(vals)
r_idx := make([]int, test_size) // Reverse index
defer {
delete(vals)
delete(f_idx)
delete(r_idx)
}
// Set up test values
for _, i in vals {
vals[i] = rand.uint64(&r)
f_idx[i] = i
}
// Sort
slice.sort_with_indices(vals, f_idx)
f_idx := slice.sort_with_indices(vals)
defer delete(f_idx)
// Verify sorted test values
rand.init(&r, seed)
@@ -94,4 +88,4 @@ test_sort_with_indices :: proc(t: ^testing.T) {
last = v
}
}
}
}