mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Remove use of find_len and len_from_list. Rename lenof to lengthof
This commit is contained in:
@@ -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;)
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user