From 1f2f0c66d8233ef697885ae4f1d124e7102ff04e Mon Sep 17 00:00:00 2001 From: Ed_ Date: Wed, 6 Mar 2024 22:41:01 -0500 Subject: [PATCH] Added impl for singly-linked lists --- code/grime_linked_list.odin | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/code/grime_linked_list.odin b/code/grime_linked_list.odin index 5df853a..933a3d2 100644 --- a/code/grime_linked_list.odin +++ b/code/grime_linked_list.odin @@ -3,10 +3,23 @@ package sectr LL_Node :: struct ( $ Type : typeid ) { - value : ^Type, - next : ^LL_Node(Type), + next : ^Type, } +ll_push :: #force_inline proc "contextless" ( list_ptr : ^(^ ($ Type)), node : ^Type ) { + list := (list_ptr^) + node.next = list + (list_ptr^) = node +} + +ll_pop :: #force_inline proc "contextless" ( list_ptr : ^(^ ($ Type)) ) -> ( node : ^Type ) { + list := (list_ptr^) + (list_ptr^) = list.next + return list +} + +//region Intrusive Doubly-Linked-List + DLL_Node :: struct ( $ Type : typeid ) #raw_union { using _ : struct { left, right : ^Type, @@ -102,3 +115,5 @@ dll_full_insert_raw :: proc "contextless" ( null : ^($ Type), parent, pos, node dll_full_push_back :: proc "contextless" ( null : ^($ Type), parent, node : ^ Type ) { dll_full_insert_raw( null, parent, parent.last, node ) } + +//endregion Intrusive Doubly-Linked-List