mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
improve the sort and collections libs (#853)
* lib/std/sort: unify binarysearch and binarysearch_with; add comments to quicksort Signed-off-by: Pierre Curto <pierre.curto@gmail.com> * lib/std/collections: mark List.{len, is_empty, get} with @inline Signed-off-by: Pierre Curto <pierre.curto@gmail.com> * lib/std/collections: add PriorityQueueMax; add tests for PriorityQueue and PriorityQueueMax Signed-off-by: Pierre Curto <pierre.curto@gmail.com> --------- Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
@@ -25,14 +25,13 @@ fn void binarysearch()
|
||||
usz idx = sort::binarysearch(tc.data, tc.x);
|
||||
assert(idx == tc.index, "%s: got %d; want %d", tc.data, idx, tc.index);
|
||||
|
||||
usz cmp_idx = sort::binarysearch_with(tc.data, tc.x, &sort::cmp_int_ref);
|
||||
usz cmp_idx = sort::binarysearch(tc.data, tc.x, &sort::cmp_int_ref);
|
||||
assert(cmp_idx == tc.index, "%s: got %d; want %d", tc.data, cmp_idx, tc.index);
|
||||
|
||||
usz cmp_idx2 = sort::binarysearch_with(tc.data, tc.x, &sort::cmp_int_value);
|
||||
usz cmp_idx2 = sort::binarysearch(tc.data, tc.x, &sort::cmp_int_value);
|
||||
assert(cmp_idx2 == tc.index, "%s: got %d; want %d", tc.data, cmp_idx2, tc.index);
|
||||
|
||||
usz cmp_idx3 = sort::binarysearch_with(tc.data, tc.x, fn int(int a, int b) => a - b);
|
||||
usz cmp_idx3 = sort::binarysearch(tc.data, tc.x, fn int(int a, int b) => a - b);
|
||||
assert(cmp_idx3 == tc.index, "%s: got %d; want %d", tc.data, cmp_idx2, tc.index);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user