29 #include "cx/tree.h" |
29 #include "cx/tree.h" |
30 #include "cx/linked_list.h" |
30 #include "cx/linked_list.h" |
31 |
31 |
32 #define CX_TR_PTR(cur, off) ((void**)(((char*)cur)+off)) |
32 #define CX_TR_PTR(cur, off) ((void**)(((char*)cur)+off)) |
33 |
33 |
34 void *cx_tree_last(void *node, ptrdiff_t loc_next) { |
|
35 void *last; |
|
36 do { |
|
37 last = node; |
|
38 } while ((node = *CX_TR_PTR(node, loc_next)) != NULL); |
|
39 return last; |
|
40 } |
|
41 |
|
42 void cx_tree_add_sibling(void *node, ptrdiff_t loc_prev, ptrdiff_t loc_next, ptrdiff_t loc_parent, void *new_node) { |
34 void cx_tree_add_sibling(void *node, ptrdiff_t loc_prev, ptrdiff_t loc_next, ptrdiff_t loc_parent, void *new_node) { |
43 cx_linked_list_add(&node, NULL, loc_prev, loc_next, new_node); |
35 cx_linked_list_add(&node, NULL, loc_prev, loc_next, new_node); |
44 |
36 |
45 // optional parent link |
37 // optional parent link |
46 if (loc_parent >= 0) { |
38 if (loc_parent >= 0) { |