|
|
|
|
|
by lelanthran
432 days ago
|
|
> If the node embeds the data item you can't link the item into multiple linked lists, but if the data item embeds the node(s) suddenly that's trivial. Perhaps I'm missing something, but isn't it the other way around? In C, this is what I'd expect for the intrusive and extrusive: // Intrusive
struct user_data_t {
struct user_data_t *next;
struct user_data_t *prev;
// The object's fields
};
// Extrusive
struct node_t {
struct node_t *next;
struct node_t *prev;
struct user_data_t *payload;
};
The intrusive one obviously can't be shared between lists. |
|
The advantage versus your extrusive example is that the payload doesn't need to be referenced through a pointer, which drastically simplifies lifetime tracking / memory management.