binarysearch is now a builtin, quicksort as well.

This commit is contained in:
Christoffer Lerno
2023-07-09 01:49:43 +02:00
parent 053f7880e5
commit 38cc24af27
2 changed files with 4 additions and 3 deletions

View File

@@ -34,14 +34,15 @@ macro usz binarysearch_with(list, x, cmp)
* @require is_searchable(list) "The list must be indexable and support .len or .len()"
* @checked less(list[0], x) "The values must be comparable"
**/
macro usz binarysearch(list, x)
macro usz binarysearch(list, x) @builtin
{
usz i;
usz len = @len_from_list(list);
for (usz j = len; i < j;)
{
usz half = (i + j) / 2;
switch {
switch
{
case greater(list[half], x): j = half;
case less(list[half], x): i = half + 1;
default: return half;

View File

@@ -1,7 +1,7 @@
module std::sort;
import std::sort::qs;
macro quicksort(list, cmp = null)
macro quicksort(list, cmp = null) @builtin
{
var $Type = $typeof(list);
var $CmpType = $typeof(cmp);