Compare commits

..

No commits in common. "f5c67576aa793313fd7def8c6c250eddd0e0c763" and "30abdf652cc44c3e8b69ab316ebc1c4744699c54" have entirely different histories.

3 changed files with 4 additions and 10 deletions

View File

@ -12,10 +12,10 @@ static bool _stable_sort_merge(char* a,
int (*f_lt)(const void* a, const void* b, void* extra),
void* extra) {
while(a < a_end && b < b_end) {
int res = f_lt(b, a, extra);
int res = f_lt(a, b, extra);
// check error
if(res == -1) return false;
if(res == 0) { // !(b<a) -> (b>=a) -> (a<=b)
if(res) {
memcpy(r, a, elem_size);
a += elem_size;
} else {

View File

@ -88,7 +88,7 @@ assert list(range(5, 1, -2)) == [5, 3]
# test sort
a = [8, 2, 4, 2, 9]
assert a.sort() == None
assert (a == [2, 2, 4, 8, 9]), a
assert a == [2, 2, 4, 8, 9]
a = []
assert a.sort() == None

View File

@ -142,10 +142,4 @@ assert a.__new__ == list.__new__
class A:
x: list[int] = [i for i in range(1, 4)]
assert A.x == [1, 2, 3]
# stable sort
a = [(0, 1), (1, 1), (1, 2)]
b = sorted(a, key=lambda x: x[0])
if b != [(0, 1), (1, 1), (1, 2)]:
assert False, b
assert A.x == [1, 2, 3]