| ▲ | flohofwoe 5 hours ago | |
Hmm interesting, the doubly linked list presented here is missing the elegant 'overlapped list header' trick from AmigaOS (at least that's where I saw it first): E.g. an AmigaOS list node looks conventional, it has two pointers, one to the next node (succ), and one to the previous node (pred):
Most AmigaOS structs embed such a Node struct at the start....but the list header has three pointers which basically form two overlapped Node structs:
In an empty list, lh_Head points to &lh_Tail, and lh_TailPred points to &lh_Head. The lh_Tail pointer is always null (this is the 'end marker').In a populated list, lh_Head points to the embedded Node struct of the first list node, and lh_TailPred points to the embedded Node struct of the last list node. The ln_Succ pointer of the last node points to the address of the list header's lh_Tail pointer (...which is always null). That way you only need an existing node pointer to walk forward and backward, or insert or remove a node. When walking the list by following the succ or pred pointers you know you've reached the end when encountering a null pointer. Apparently the Linux-style lists in the article require to know the address of the list header to detect when the end is reached which isn't needed for the Amiga style list (at the cost of an additional 'sentinel null pointer' in the list header). Pretty much all of AmigaOS was held together by such doubly linked lists. (I hope I got that all right, it's been a long time) | ||
| ▲ | layer8 4 hours ago | parent [-] | |
This looks correct, here is a reference: https://wiki.amigaos.net/wiki/Exec_Lists_and_Queues#List_Hea.... | ||