26 * POSSIBILITY OF SUCH DAMAGE. |
26 * POSSIBILITY OF SUCH DAMAGE. |
27 */ |
27 */ |
28 |
28 |
29 #include "cx/tree.h" |
29 #include "cx/tree.h" |
30 |
30 |
|
31 #define CX_TR_PTR(cur, off) ((void**)(((char*)cur)+off)) |
|
32 |
|
33 void* cx_tree_last(void *node, ptrdiff_t loc_next) { |
|
34 void *last; |
|
35 do { |
|
36 last = node; |
|
37 } while ((node = *CX_TR_PTR(node, loc_next)) != NULL); |
|
38 return last; |
|
39 } |
31 |
40 |
32 int cx_tree_add_node(void *node, ptrdiff_t loc_parent, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node) { |
41 int cx_tree_add_node(void *node, ptrdiff_t loc_parent, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node) { |
33 return 1; |
42 void *last = cx_tree_last(node, loc_next); |
|
43 if(!last) |
|
44 return 1; |
|
45 |
|
46 // next pointer must be present |
|
47 *CX_TR_PTR(last, loc_next) = new_node; |
|
48 |
|
49 // optional fields |
|
50 if(loc_parent >= 0) { |
|
51 *CX_TR_PTR(new_node, loc_parent) = *CX_TR_PTR(node, loc_parent); |
|
52 } |
|
53 if(loc_prev >= 0) { |
|
54 *CX_TR_PTR(new_node, loc_prev) = last; |
|
55 } |
|
56 |
|
57 return 0; |
34 } |
58 } |
35 |
59 |
36 int cx_tree_add_child_node( |
60 int cx_tree_add_child_node( |
37 void *parent, |
61 void *parent, |
38 ptrdiff_t loc_parent, |
62 ptrdiff_t loc_parent, |