From 1d0aef7d0b5448be980a3c51ef9fd04b5a0ab339 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Sun, 20 Mar 2022 10:38:25 +0100 Subject: [PATCH] mx_util: Mention stable sort property in comments _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. --- mx_util.c | 1 + test_mx_util.c | 1 + 2 files changed, 2 insertions(+) diff --git a/mx_util.c b/mx_util.c index 8b675159..0aea3183 100644 --- a/mx_util.c +++ b/mx_util.c @@ -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; diff --git a/test_mx_util.c b/test_mx_util.c index 6f473093..20b58c81 100644 --- a/test_mx_util.c +++ b/test_mx_util.c @@ -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]; }