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)
Sun, Jun 23, 3:08 AM
Unknown Object (File)
Sat, Jun 22, 6:27 PM
Unknown Object (File)
May 4 2024, 4:09 AM
Unknown Object (File)
Jan 12 2024, 2:56 AM
Unknown Object (File)
Dec 28 2023, 12:41 PM
Unknown Object (File)
Dec 22 2023, 11:50 PM
Unknown Object (File)
Nov 5 2023, 12:50 PM
Unknown Object (File)
Oct 27 2023, 10:53 AM
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 Not Applicable
Unit
Tests Not Applicable

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.