[glib] docs: Add a cute trick for achieving a stable sort



commit 80928ea403cfff5ffaa4bc73e84e3d4ebcb09123
Author: Benjamin Otte <otte redhat com>
Date:   Sun May 15 16:11:51 2011 +0200

    docs: Add a cute trick for achieving a stable sort
    
    This trick is inspired by
    http://www.gnu.org/s/hello/manual/libc/Array-Sort-Function.html
    http://jeffreystedfast.blogspot.com/2011/04/optimizing-merge-sort.html

 glib/garray.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
---
diff --git a/glib/garray.c b/glib/garray.c
index e3d872b..231db52 100644
--- a/glib/garray.c
+++ b/glib/garray.c
@@ -1560,7 +1560,10 @@ g_byte_array_remove_range (GByteArray *array,
  * first arg is 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_byte_array_sort (GByteArray   *array,



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