Page MenuHomeFreeBSD

sys/queue.h: add STAILQ_REVERSE
ClosedPublic

Authored by kib on May 3 2025, 8:46 AM.
Tags
None
Referenced Files
F132369760: D50131.id154838.diff
Thu, Oct 16, 7:25 AM
F132362937: D50131.id154794.diff
Thu, Oct 16, 6:03 AM
Unknown Object (File)
Sun, Oct 12, 7:52 AM
Unknown Object (File)
Wed, Oct 8, 3:39 PM
Unknown Object (File)
Tue, Sep 30, 4:32 AM
Unknown Object (File)
Sat, Sep 27, 8:16 AM
Unknown Object (File)
Wed, Sep 17, 11:25 AM
Unknown Object (File)
Wed, Sep 17, 6:52 AM
Subscribers

Details

Summary

The implementation of the traditional interview question about in-place reversing of the single-linked list.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/sys/queue.h
567

Rather than forcing consumers to declare these variable, it'd be better IMO to pass the type name as parameter, and declare temp variables within the macro. This is consistent with how the *_SWAP macros work.

kib marked an inline comment as done.

Define locals in the macro.

Looks ok to me, but there should be a queue.3 update too.

olce requested changes to this revision.May 5 2025, 9:47 AM

I've also written a corresponding test, to be uploaded to a new revision.

sys/sys/queue.h
567–579

(head)->stqh_last = &STAILQ_FIRST(head); is wrong.

I'm also suggesting to break early if the stailq is empty, as this seems clearer and it alleviates the need to introduce a similar test when setting ->stqh_last.

This revision now requires changes to proceed.May 5 2025, 9:47 AM

Do nothing for empty stailq.
Fix stqh_last.

I'd also suggest removing _Var = STAILQ_LAST(head, type, field); and setting ->stqh_first to _Varp directly, as _Varp already contains the old last/new first element.

This revision is now accepted and ready to land.May 5 2025, 10:12 AM

Rely on _Varp to set head.

This revision now requires review to proceed.May 5 2025, 10:27 AM
This revision is now accepted and ready to land.May 5 2025, 10:35 AM
This revision was automatically updated to reflect the committed changes.