Skip to content

Fix uniqueColors comparator strict weak ordering#1818

Merged
ddennedy merged 1 commit intomltframework:masterfrom
qwe854896:master
Apr 28, 2026
Merged

Fix uniqueColors comparator strict weak ordering#1818
ddennedy merged 1 commit intomltframework:masterfrom
qwe854896:master

Conversation

@qwe854896
Copy link
Copy Markdown
Contributor

Fix an issue in the uniqueColors sorting comparator where the use of <= violated the requirements of a strict weak ordering. The comparison now uses < instead to restore correct comparator behavior and prevent undefined behavior during sorting.

In terms of the algorithm's contract, the comparator used by std::sort must induce a strict weak ordering. In particular:

  • For all a, comp(a, a) == false.
  • If comp(a, b) == true then comp(b, a) == false.

Using <= violated these rules when two elements were equal. Replacing <= with < ensures compliance with the standard and improves stability.

Even if equal QColor are unlikely or impossible to appear in uniqueColors, switching to < is still safe and makes the comparator correct by definition. If QColor can never be equal, then < and <= behave the same anyway.

References:

@ddennedy ddennedy added this to the v26.4 milestone Apr 28, 2026
@ddennedy
Copy link
Copy Markdown
Member

Thank you

@ddennedy ddennedy merged commit 4fbc9a8 into mltframework:master Apr 28, 2026
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