]> git.cworth.org Git - notmuch/commitdiff
lib/string_map: simulate stable sorting
authorDavid Bremner <david@tethera.net>
Sat, 25 Nov 2023 12:33:52 +0000 (08:33 -0400)
committerDavid Bremner <david@tethera.net>
Tue, 28 Nov 2023 13:19:21 +0000 (09:19 -0400)
qsort(3) does not promise stability, and recent versions of glibc have
been showing more unstable behaviour [2]. Michael Gruber observed [1] test
breakage due to changing output order for message properties.

We provide a sorting order of (key,value) pairs that _looks_ stable by
breaking ties based on value if keys are equal. Internally there may
be some instability in the case of duplicate (key,value) pairs, but it
should not be observable via the iterator API.

[1]: id:CAA19uiSHjVFmwH0pMC7WwDYCOSzu3yqNbuYhu3ZMeNNRh313eA@mail.gmail.com
[2]: id:87msv3i44u.fsf@oldenburg.str.redhat.com


No differences found