Skip to content

Commit

Permalink
mx_util: Mention stable sort property in comments
Browse files Browse the repository at this point in the history
_mx_sort_linked_list and its macro wrapper mx_sort_linked_list currently
do a stable sort. Add comments to the code and the test that this is
guaranteed behaviour, because we are going to depend on it in the
following commits.
  • Loading branch information
donald committed Mar 20, 2022
1 parent 33383ba commit 1d0aef7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions mx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,7 @@ int mx_daemon(int nochdir, int noclose)
return daemon(nochdir, noclose);
}

/* guarantee stable sort */
void _mx_sort_linked_list (void **list, int (*cmp)(void *o1,void *o2), void ** getnextptr(void *o)) {

void *unsorted=*list;
Expand Down
1 change: 1 addition & 0 deletions test_mx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ static void test_listsort(void)
}

/* (100 0 1 2 50 50 2 1 0 100) -> ( 0 0 1 1 2 2 50 50 100 100) stable */
/* also verify stable sort */
for (int i=0;i<10;i++) {
o[i].next= i==9 ? NULL : &o[i+1];
}
Expand Down

0 comments on commit 1d0aef7

Please sign in to comment.