Sorting functions correctly took slices by value, but also other types by value. Now, only slices are accepted by value, other containers are always by ref.

This commit is contained in:
Christoffer Lerno
2025-10-07 22:43:40 +02:00
parent d6be1cbf65
commit fe70f10bcc
13 changed files with 346 additions and 125 deletions

View File

@@ -47,7 +47,7 @@ fn void map()
list.push({key, value});
};
assert(list.len() == tcases.len);
quicksort(list, fn int (MapTest a, MapTest b) => (int)(a.value - b.value));
quicksort(&list, fn int (MapTest a, MapTest b) => (int)(a.value - b.value));
foreach (i, tc : tcases)
{
assert(tc.key == list[i].key);

View File

@@ -79,7 +79,7 @@ fn void countingsort_list()
{
CountingSortTestList list;
list.push_all({ 2, 1, 3});
sort::countingsort(list, &sort::key_int_value);
sort::countingsort(&list, &sort::key_int_value);
assert(check::int_ascending_sort(list.array_view()));
}
@@ -94,7 +94,7 @@ fn void countingsort_random_large_list()
list.push(random.next_int());
}
sort::countingsort(list, &sort::key_int_value);
sort::countingsort(&list, &sort::key_int_value);
assert(check::int_ascending_sort(list.array_view()));
list.free();
}

View File

@@ -84,7 +84,7 @@ fn void insertionsort_list()
{
InsertionSortTestList list;
list.push_all({ 2, 1, 3});
sort::insertionsort(list, &sort::cmp_int_value);
sort::insertionsort(&list, &sort::cmp_int_value);
assert(check::int_ascending_sort(list.array_view()));
}

View File

@@ -84,7 +84,7 @@ fn void quicksort_list()
{
List2 list;
list.push_all({ 2, 1, 3});
sort::quicksort(list, &sort::cmp_int_value);
sort::quicksort(&list, &sort::cmp_int_value);
assert(check::int_sort(list.array_view()));
}