[glib] docs: Add the cute trick comment to all sort functions



commit cb7a5a8e94a3317961ef98b839e4cfce9abccb42
Author: Benjamin Otte <otte redhat com>
Date:   Sun May 15 16:16:30 2011 +0200

    docs: Add the cute trick comment to all sort functions
    
    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 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/glib/garray.c b/glib/garray.c
index 231db52..f12a8f9 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.
  *
  * <note><para>The comparison function for g_ptr_array_sort() doesn't
  * take the pointers from the array as arguments, it takes pointers to



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]