Re: g_s?list_sort doesn't do stable sort



Kristian Hogsberg Kristensen <hogsberg@daimi.au.dk> writes:

> Hi,
> 
> The g_s?list_sort functions don't do a stable sort of the list
> elements, that is they don't preserve the order of elements considered
> equal by the comparison function.  The patch to fix this is really
> tiny (see below), so the decision to be made is wether to guarantee a
> stable sort or as in the case of libc's qsort explicitly state: "If
> two members compare as equal, their order in the sorted array is
> undefined." (from the glibc man page).
> 
> From my point of view this is definately useful, and it doesn't change
> anything for people not expecting a stable sort.  I have a few places
> where I have to also consider the element index in the comparison
> function to get the desired behaviour.  On the other hand, leaving it
> unspecified allows you to change the implementation, but given that
> it's a linked list I dont see why you wouldn't use merge sort.
> 
> The patch also corrects some funky looking indentation, which somehow
> made it past the maintainers :-)


IMO, if we don't guarantee that g_{s,}list_sort is stable, someone
will just want to add g_list_sort_stable, or write their own
somewhere. So I think this is a good patch (but I am not one of the
maintainers).

 - Maciej





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