From cb7a5a8e94a3317961ef98b839e4cfce9abccb42 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 15 May 2011 16:16:30 +0200 Subject: [PATCH] docs: Add the cute trick comment to all sort functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to Sebastian Dröge for pointing out there's more than g_array_sort() and I hadn't in fact added the comment to g_array_sort() in 80928ea403cfff5ffaa4bc73e84e3d4ebcb09123 --- glib/garray.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/glib/garray.c b/glib/garray.c index 231db527d..f12a8f918 100644 --- a/glib/garray.c +++ b/glib/garray.c @@ -616,7 +616,10 @@ g_array_remove_range (GArray *farray, * greater than second arg). * * If two array elements compare equal, their order in the sorted array - * is undefined. + * is undefined. If you want equal elements to keep their order - ie + * you want a stable sort - you can write a comparison function that, + * if two elements would otherwise compare equal, it compares them by + * their addresses. **/ void g_array_sort (GArray *farray, @@ -1238,7 +1241,10 @@ g_ptr_array_add (GPtrArray *farray, * greater than second arg). * * If two array elements compare equal, their order in the sorted array - * is undefined. + * is undefined. If you want equal elements to keep their order - ie + * you want a stable sort - you can write a comparison function that, + * if two elements would otherwise compare equal, it compares them by + * their addresses. * * The comparison function for g_ptr_array_sort() doesn't * take the pointers from the array as arguments, it takes pointers to