After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 508976 - Does g_slist_sort preserve the order of equal elements?
Does g_slist_sort preserve the order of equal elements?
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: glist
2.15.x
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2008-01-12 16:58 UTC by Дилян Палаузов
Modified: 2017-11-28 14:12 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch (807 bytes, patch)
2009-09-23 13:30 UTC, Alberto Garcia
rejected Details | Review
gslist: Document that g_slist_sort() is stable (919 bytes, patch)
2017-11-16 10:29 UTC, Philip Withnall
committed Details | Review
tests: Add tests to ensure g_[s]list_sort() are stable sorts (3.67 KB, patch)
2017-11-16 10:29 UTC, Philip Withnall
committed Details | Review

Description Дилян Палаузов 2008-01-12 16:58:09 UTC
Please describe the problem:
The documentation for g_slist_sort () at http://library.gnome.org/devel/glib/unstable/glib-Singly-Linked-Lists.html#g-slist-sort does not say what happens with two equal elements - is their original order preserved, does one of them disappear?



Steps to reproduce:
1

Actual results:


Expected results:


Does this happen every time?


Other information:
Comment 1 Tim Janik 2008-01-12 17:31:58 UTC
the order is unfortunately not preserved (i.e. the sorting is not "stable"). the documentation should outline this.
Comment 2 Alberto Garcia 2009-09-23 13:30:10 UTC
Created attachment 143791 [details] [review]
Patch
Comment 3 Alberto Garcia 2009-09-23 13:34:31 UTC
By the way, g_list_sort() would also require a similar comment. Is that
sorting algorithm stable?
Comment 4 Charlie Brej 2010-07-04 21:40:02 UTC
Actually, it is currently implemented as a merge sort and thus is stable.
Comment 5 Philip Withnall 2017-11-16 10:26:59 UTC
Review of attachment 143791 [details] [review]:

Sorry, this has bitrotted for a bit too long: we no longer use DocBook in documentation comments, and the sorting algorithm actually is stable. I’ll provide an updated patch shortly.
Comment 6 Philip Withnall 2017-11-16 10:27:16 UTC
See also: bug #531973, which fixed this for GList.
Comment 7 Philip Withnall 2017-11-16 10:29:21 UTC
Created attachment 363822 [details] [review]
gslist: Document that g_slist_sort() is stable

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Comment 8 Philip Withnall 2017-11-16 10:29:27 UTC
Created attachment 363823 [details] [review]
tests: Add tests to ensure g_[s]list_sort() are stable sorts

Given that we guarantee it in the API…

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Comment 9 Emmanuele Bassi (:ebassi) 2017-11-28 12:48:28 UTC
Review of attachment 363822 [details] [review]:

:+1:
Comment 10 Emmanuele Bassi (:ebassi) 2017-11-28 12:48:55 UTC
Review of attachment 363823 [details] [review]:

:+1:
Comment 11 Philip Withnall 2017-11-28 14:11:57 UTC
Attachment 363822 [details] pushed as 74cbd6c - gslist: Document that g_slist_sort() is stable
Attachment 363823 [details] pushed as 2cd2671 - tests: Add tests to ensure g_[s]list_sort() are stable sorts