docs/Writerside/topics/linked_list.h.md

branch
docs/3.1
changeset 1141
a06a2d27c043
child 1142
9437530176bc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/Writerside/topics/linked_list.h.md	Thu Jan 23 01:33:36 2025 +0100
@@ -0,0 +1,27 @@
+# linked_list.h
+
+On top of implementing the list interface, this header also defines several low-level functions that
+work with arbitrary structures.
+Low-level functions, in contrast to the high-level list interface, can easily be recognized by their snake-casing.
+The function `cx_linked_list_at`, for example, implements a similar functionality like `cxListAt`, but operates
+on arbitrary structures.
+The following snippet shows how it is used.
+All other low-level functions work similarly.
+```c
+struct node {
+    node *next;
+    node *prev;
+    int data;
+};
+
+const ptrdiff_t loc_prev = offsetof(struct node, prev);
+const ptrdiff_t loc_next = offsetof(struct node, next);
+const ptrdiff_t loc_data = offsetof(struct node, data);
+
+struct node a = {0}, b = {0}, c = {0}, d = {0};
+cx_linked_list_link(&a, &b, loc_prev, loc_next);
+cx_linked_list_link(&b, &c, loc_prev, loc_next);
+cx_linked_list_link(&c, &d, loc_prev, loc_next);
+
+cx_linked_list_at(&a, 0, loc_next, 2); // returns pointer to c
+```

mercurial