Remove use of find_len and len_from_list. Rename lenof to lengthof

This commit is contained in:
Christoffer Lerno
2025-09-06 18:35:03 +02:00
parent 3eb8f68ded
commit 9f55a74d2e
18 changed files with 46 additions and 61 deletions

View File

@@ -10,7 +10,7 @@ in [0, array.len) where x would be inserted or cmp(i) is true and cmp(j) is true
macro usz binarysearch(list, x, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin
{
usz i;
usz len = len_from_list(list);
usz len = lengthof(list);
var $no_cmp = @is_empty_macro_slot(cmp);
var $has_context = @is_valid_macro_slot(context);
for (usz j = len; i < j;)

View File

@@ -10,7 +10,7 @@ Sort list using the counting sort algorithm.
*>
macro countingsort(list, key_fn = EMPTY_MACRO_SLOT) @builtin
{
usz len = sort::len_from_list(list);
usz len = lengthof(list);
cs::csort{$typeof(list), $typeof(key_fn)}(list, 0, len, key_fn, ~((uint)0));
}

View File

@@ -12,7 +12,7 @@ macro insertionsort(list, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @b
$typeof((*list)[0])[] list2 = list;
is::isort{$typeof(list2), $typeof(cmp), $typeof(context)}(list2, 0, list.len, cmp, context);
$else
usz len = sort::len_from_list(list);
usz len = lengthof(list);
is::isort{$typeof(list), $typeof(cmp), $typeof(context)}(list, 0, (isz)len, cmp, context);
$endif
}

View File

@@ -13,7 +13,7 @@ macro quicksort(list, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @built
$typeof((*list)[0])[] list2 = list;
qs::qsort{$typeof(list2), $typeof(cmp), $typeof(context)}(list2, 0, (isz)list.len - 1, cmp, context);
$else
usz len = sort::len_from_list(list);
usz len = lengthof(list);
qs::qsort{$typeof(list), $typeof(cmp), $typeof(context)}(list, 0, (isz)len - 1, cmp, context);
$endif
}
@@ -29,7 +29,7 @@ list will be partially sorted.
*>
macro quickselect(list, isz k, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin
{
usz len = sort::len_from_list(list);
usz len = lengthof(list);
return qs::qselect{$typeof(list), $typeof(cmp), $typeof(context)}(list, 0, (isz)len - 1, k, cmp, context);
}

View File

@@ -1,13 +1,5 @@
module std::sort;
macro usz len_from_list(list)
{
$if $defined(list.len()):
return list.len();
$else
return list.len;
$endif
}
macro bool @is_sortable(#list)
{

View File

@@ -9,7 +9,7 @@ Returns true if list is sorted in either ascending or descending order.
macro bool is_sorted(list, cmp = EMPTY_MACRO_SLOT, ctx = EMPTY_MACRO_SLOT) @builtin
{
var $Type = $typeof(list);
usz len = sort::len_from_list(list);
usz len = lengthof(list);
if (len <= 1) return true;
var check_sort = fn bool($Type list, usz start, usz end, $typeof(cmp) cmp, $typeof(ctx) ctx)
{