Skip to content

Make reglist_sort_() stable#2575

Merged
pd3 merged 1 commit into
samtools:developfrom
daviesrob:stabilize-reglist-sort
Jul 6, 2026
Merged

Make reglist_sort_() stable#2575
pd3 merged 1 commit into
samtools:developfrom
daviesrob:stabilize-reglist-sort

Conversation

@daviesrob

Copy link
Copy Markdown
Member

Add a tie-breaker comparison so that reglist_sort_() preserves the original ordering when regions compare exactly. This only matters where the region list includes payload data for the regions being sorted, otherwise region entries that tie are indistinguishable. As in that case an array of pointers into the original region list is sorted, the pointer values can be used to break any ties.

This resolves a test failure for the bcftools csq --greedy option on alpine Linux because its qsort() implementation did not give the same ordering as the glibc one. As glibc often (but not always!) uses mergesort for its qsort() implementation, it may have given the impression of being stable when in fact this is not guaranteed.

Add a tie-breaker comparison so that reglist_sort_() preserves
the original ordering when regions compare exactly.  This
only matters where the region list includes payload data for
the regions being sorted, otherwise region entries that tie
are indistinguishable.  As in that case an array of pointers
into the original region list is sorted, the pointer values
can be used to break any ties.

This resolves a test failure for the `bcftools csq --greedy`
option on alpine Linux because its qsort() implementation
did not give the same ordering as the glibc one.  As glibc
often (but not always!) uses mergesort for its qsort()
implementation, it may have given the impression of being
stable when in fact this is not guaranteed.

Signed-off-by: Rob Davies <rmd+git@sanger.ac.uk>
@pd3 pd3 merged commit f440c1c into samtools:develop Jul 6, 2026
8 checks passed
@pd3

pd3 commented Jul 6, 2026

Copy link
Copy Markdown
Member

Thank you

@daviesrob daviesrob deleted the stabilize-reglist-sort branch July 6, 2026 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants