code wiki / (root) / nx_dlist.nx

nx_dlist.nx

buildroot/runtime/nx_dlist.nx

4460 B165 linesdepth 2pulls 2 transitivereach 1 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

dlist.nx -- intrusive doubly-linked list. Each node carries prev/next pointers; list has a sentinel node (heap-allocated) whose prev/next thread the ring. Intrusive: the node pointer is the handle the caller holds, not a wrapper around T. Trade-offs vs std::list-style wrapped list: + O(1) remove given just a node pointer (no search) + one user struct can participate in multiple lists (LRU + pending + free) with separate DNode fields - caller allocates nodes Design note: NishiLang v1 doesn't allow `&struct.field` for inline fields, so DList stores the sentinel as a separately- allocated *DNode rather than an embedded DNode. Small extra alloc at list-construction time only. Used by: - LRU caches (move-to-front, evict tail) - scheduler run queues - free-block chains in allocators - order-preserving map iteration (map + sibling dlist) Invariants: DL1 Empty list: sentinel.next == sentinel.prev == sentinel. DL2 dlist_insert_after + dlist_remove maintain n.next.prev == n for all n. DL3 dlist_remove does NOT free the node -- caller owns lifetime.

dependencies 1 imports · 1 importers

nx_syscalls.nx nx_dlist.nx nx_lru.nx

imports: nx_syscalls.nx

imported by: nx_lru.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main dlist_new sys_mmap dlist_empty dnode_new sys_mmap ↻ dlist_push_back dlist_insert_after dlist_begin dlist_move_to_front dlist_remove dlist_push_front dlist_insert_after ↻ dlist_pop_back dlist_empty ↻ dlist_remove ↻ dlist_pop_front dlist_empty ↻ dlist_remove ↻

structs

38struct DNode
44struct DList

consts

none

functions

49func dlist_new() -> *DList
called by 2: mainlru_new calls 1: sys_mmap
62func dnode_new(data: *u8) -> *DNode
called by 2: mainlru_put calls 1: sys_mmap
71func dlist_empty(L: *DList) -> i64
78func dlist_insert_after(pos: *DNode, n: *DNode) -> i64
87func dlist_push_front(L: *DList, n: *DNode) -> i64
92func dlist_push_back(L: *DList, n: *DNode) -> i64
called by 1: main calls 1: dlist_insert_after
97func dlist_remove(n: *DNode) -> i64
104func dlist_move_to_front(L: *DList, n: *DNode) -> i64
111func dlist_pop_front(L: *DList) -> *DNode
called by 1: main calls 2: dlist_emptydlist_remove
119func dlist_pop_back(L: *DList) -> *DNode
called by 2: mainlru_put calls 2: dlist_emptydlist_remove
127func dlist_begin(L: *DList) -> *DNode
called by 1: main
131func dlist_end(L: *DList) -> *DNode
136func main() -> i64