News for hackers. Stuff that matters.
Re:Show HN: libcodr7 – fundamental collections in the spirit... by thestoicattack on Monday December 30, 2019 @01:54PM (#21915726)
Okay, I'm getting it. Not a knock on the author, but looking at this macro'd, pointer-to-void'd stuff certainly makes me appreciate the STL.

Edit: aha, I see "intrusive" was the keyword I was missing to learn all about this different style.

Re:Show HN: libcodr7 – fundamental collections in the spirit... by DSMan195276 on Monday December 30, 2019 @02:23PM (#21915918)
Using `container_of` lets you avoid having to use void pointers. And the macros like foreach are surprisingly readable once you give them a shot, and they're simple enough they don't really have any big gotchas in how they work.

Not every `container_of` data structure is perfect, but in general I'd say they're just as nice to use as any other language's data structures (Though `container_of` is flexible in different ways). The only big downside is that it not part of the C standard, leading to more than a few implementations, some more featureful than others. This one is probably the "least featureful" version I've seen, which may be intentional. The Linux Kernel's implementation has a lot more utility things like looping in different ways and different types of list manipulations. Some are highly useful, others not at much.

Re:Show HN: libcodr7 – fundamental collections in the spirit... by rafa1981 on Monday December 30, 2019 @03:04PM (#21916197)
Intrusive lists are very different beasts than lists by value.

There are less allocations involved (perf and points of failure), values can be inserted on different lists without new allocations, deletion is O(1), elements can be heterogeneous (different sizes and types), etc

etc

I seldomly use linked lists, but most of the time i prefer them to be intrusive. There of course are intrusive list implementations on C++.

Re:Show HN: libcodr7 – fundamental collections in the spirit... by codr7 on Wednesday January 01, 2020 @04:43PM (#21930906)
Same here.

Using non-intrusive linked lists just feels wrong once you've gotten used to the idea of embedding links, I find there are always better options.

Intrusive lists on the other hand is simply the best solution in some cases.

Re:Show HN: libcodr7 – fundamental collections in the spirit... by jcheng on Monday December 30, 2019 @03:53PM (#21916622)
> values can be inserted on different lists without new allocations

Not multiple lists at the same time, surely...?

Re:Show HN: libcodr7 – fundamental collections in the spirit... by DSMan195276 on Monday December 30, 2019 @04:01PM (#21916686)
They were talking about taking a value off of one list and adding it to a different one, which doesn't require an allocation, but the entity is never on more than one list at a time in that scenario.

That said, you can add an entity onto multiple lists if it contains multiple nodes embedded inside. You have to keep track of which nodes are attached to which lists though (Which generally just means being consistent on which you use where). If you give them decent names, then it's not usually a problem, but it can sometimes get a little confusing if you're not careful.

Re:Show HN: libcodr7 – fundamental collections in the spirit... by rafa1981 on Monday December 30, 2019 @05:58PM (#21917460)
Obviously not
Re:Show HN: libcodr7 – fundamental collections in the spirit... by codr7 on Monday December 30, 2019 @02:13PM (#21915848)
It's all about control and flexibility. If you don't need it you shouldn't pay the price. Having spent quite some time trying to bend the STL to my exact requirements, I don't mind so much.