mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Improved #foo resolution inside of the compiler.
Deprecation of several `&` macros.
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 = len_from_list(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 = sort::len_from_list(list);
|
||||
cs::csort(<$typeof(list), $typeof(key_fn)>)(list, 0, len, key_fn, ~((uint)0));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Sort list using the quick sort algorithm.
|
||||
*>
|
||||
macro insertionsort(list, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin
|
||||
{
|
||||
usz len = sort::@len_from_list(list);
|
||||
usz len = sort::len_from_list(list);
|
||||
is::isort(<$typeof(list), $typeof(cmp), $typeof(context)>)(list, 0, (isz)len, cmp, context);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ Sort list using the quick sort algorithm.
|
||||
*>
|
||||
macro quicksort(list, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin
|
||||
{
|
||||
usz len = sort::@len_from_list(list);
|
||||
usz len = sort::len_from_list(list);
|
||||
qs::qsort(<$typeof(list), $typeof(cmp), $typeof(context)>)(list, 0, (isz)len - 1, cmp, context);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,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 = sort::len_from_list(list);
|
||||
return qs::qselect(<$typeof(list), $typeof(cmp), $typeof(context)>)(list, 0, (isz)len - 1, k, cmp, context);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
module std::sort;
|
||||
|
||||
macro usz @len_from_list(&list)
|
||||
macro usz @len_from_list(&list) @deprecated
|
||||
{
|
||||
return len_from_list(*list);
|
||||
}
|
||||
|
||||
macro usz len_from_list(list)
|
||||
{
|
||||
$if $defined(list.len()):
|
||||
return list.len();
|
||||
|
||||
@@ -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 = sort::len_from_list(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