Page MenuHomeFreeBSD

Add <sys/queue_mergesort.h>
ClosedPublic

Authored by cperciva on Jul 19 2023, 12:59 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Nov 13, 11:15 AM
Unknown Object (File)
Tue, Nov 12, 10:10 PM
Unknown Object (File)
Thu, Nov 7, 2:21 PM
Unknown Object (File)
Sat, Oct 19, 10:19 PM
Unknown Object (File)
Sep 30 2024, 10:26 AM
Unknown Object (File)
Sep 30 2024, 5:30 AM
Unknown Object (File)
Sep 18 2024, 5:36 PM
Unknown Object (File)
Sep 18 2024, 3:28 PM
Subscribers

Details

Summary

Thie file provides macros for performing mergesorts and merging two
sorted lists implemented by <sys/queue.h>. The mergesort operates
in guaranteed O(n log n) time and uses constant additional space:
3 or 4 pointers (depending on list type) and 4 size_t values. The
merge operates in guaranteed O(n + m) time and uses constant
additional space: 3 pointers.

In memoriam: hselasky
Sponsored by: https://www.patreon.com/cperciva

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 53105
Build 49996: arc lint + arc unit

Event Timeline

jhb added inline comments.
sys/sys/queue_mergesort.h
39

Arguably you could do shims here for REMOVE_HEAD for LIST and TAILQ btw rather than adding those to the public interface in queue.h. I might slightly prefer that.

55

I might find it more readable to use a pattern of M_<op> like M_FIRST, M_REMOVE_HEAD, for the helper macros rather than MACRO_<abbreviated op>. Especially for things like MACRO_IH vs MACRO_HI

This revision is now accepted and ready to land.Jul 19 2023, 5:55 PM
sys/sys/queue_mergesort.h
39

That was my first thought, but then I figured that _REMOVE_HEAD could be useful elsewhere... and as emaste noticed, there is in fact one place in the tree where we could be using it already. Since LIST_REMOVE_HEAD and TAILQ_REMOVE_HEAD are plausibly useful in code which isn't using queue_mergesort.h I think it's worth exposing them in queue.h.

55

Good point. I'll revise.

Use clearer macro names, per jhb

This revision now requires review to proceed.Aug 9 2023, 6:10 PM
This revision is now accepted and ready to land.Aug 14 2023, 8:03 PM
sys/sys/queue_mergesort.h
57

style(9) is no space after * (applies throughout file)

sys/sys/queue_mergesort.h
182

qsort_r was changed to match POSIX and have the thunk argument passed last

Fixes per jrtc27

style (no space after *) and location of thunk in sort callback

This revision now requires review to proceed.Aug 15 2023, 12:30 AM
This revision was not accepted when it landed; it landed in state Needs Review.Aug 20 2023, 5:06 AM
This revision was automatically updated to reflect the committed changes.