mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] lib: clarify comparison function requirements
@ 2024-12-24 16:39 Kuan-Wei Chiu
  2024-12-24 16:39 ` [PATCH 1/2] lib/sort: clarify comparison function requirements in sort_r() Kuan-Wei Chiu
  2024-12-24 16:39 ` [PATCH 2/2] lib/list_sort: " Kuan-Wei Chiu
  0 siblings, 2 replies; 3+ messages in thread
From: Kuan-Wei Chiu @ 2024-12-24 16:39 UTC (permalink / raw)
  To: akpm; +Cc: jserv, chuang, linux-kernel, Kuan-Wei Chiu

Add a detailed explanation in the sort_r/list_sort kernel doc comment
specifying that the comparison function must satisfy antisymmetry and
transitivity. These properties are essential for the sorting algorithm
to produce correct results.

Issues have arisen in the past [1][2][3][4] where comparison functions
violated the transitivity property, causing sorting algorithms to fail
to correctly order elements. While these requirements may seem
straightforward, they are commonly misunderstood or overlooked, leading
to bugs. Highlighting these properties in the documentation will help
prevent such mistakes in the future.

Link: https://lore.kernel.org/lkml/20240701205639.117194-1-visitorckw@gmail.com [1]
Link: https://lore.kernel.org/lkml/20241203202228.1274403-1-visitorckw@gmail.com [2]
Link: https://lore.kernel.org/lkml/20241209134226.1939163-1-visitorckw@gmail.com [3]
Link: https://lore.kernel.org/lkml/20241209145728.1975311-1-visitorckw@gmail.com [4]

Kuan-Wei Chiu (2):
  lib/sort: clarify comparison function requirements in sort_r()
  lib/list_sort: clarify comparison function requirements in sort_r()

 lib/list_sort.c | 7 +++++++
 lib/sort.c      | 7 +++++++
 2 files changed, 14 insertions(+)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-12-24 16:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-24 16:39 [PATCH 0/2] lib: clarify comparison function requirements Kuan-Wei Chiu
2024-12-24 16:39 ` [PATCH 1/2] lib/sort: clarify comparison function requirements in sort_r() Kuan-Wei Chiu
2024-12-24 16:39 ` [PATCH 2/2] lib/list_sort: " Kuan-Wei Chiu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®