Add method _left, right, _up and _down for tree to get directly an iterator to the requested element
This commit is contained in:
1 parent
eab3f701a8
commit
27621db95d
3 files changed
+47
No files matched your search
@@ -3561,6 +3561,14 @@ Return a pointer to the type of the node which is
|
||||
respectively.
|
||||
It returns NULL if there is no such node.
|
||||
|
||||
##### `it_t name_up(it_t it)`
|
||||
##### `it_t name_down(it_t it)`
|
||||
##### `it_t name_left(it_t it)`
|
||||
##### `it_t name_right(it_t it)`
|
||||
|
||||
Return an iterator to point to the node which is up (resp. down, left and right) the given iterator.
|
||||
Return a valid iterator in case of success, an invalid one otherwse (see `name_end_p`)
|
||||
|
||||
##### `bool name_it_up(it_t *it)`
|
||||
##### `bool name_it_down(it_t *it)`
|
||||
##### `bool name_it_left(it_t *it)`
|
||||
|
||||
@@ -669,6 +669,34 @@ typedef int32_t m_tr33_index_t;
|
||||
return ret; \
|
||||
} \
|
||||
\
|
||||
M_INLINE it_t \
|
||||
M_F(name, _up)(it_t it) { \
|
||||
M_TR33_IT_CONTRACT(it, true); \
|
||||
it_t i = { it.tree, it.tree->tab[it.index].parent }; \
|
||||
return i; \
|
||||
} \
|
||||
\
|
||||
M_INLINE it_t \
|
||||
M_F(name, _down)(it_t it) { \
|
||||
M_TR33_IT_CONTRACT(it, true); \
|
||||
it_t i = { it.tree, it.tree->tab[it.index].child }; \
|
||||
return i; \
|
||||
} \
|
||||
\
|
||||
M_INLINE it_t \
|
||||
M_F(name, _left)(it_t it) { \
|
||||
M_TR33_IT_CONTRACT(it, true); \
|
||||
it_t i = { it.tree, it.tree->tab[it.index].left }; \
|
||||
return i; \
|
||||
} \
|
||||
\
|
||||
M_INLINE it_t \
|
||||
M_F(name, _right)(it_t it) { \
|
||||
M_TR33_IT_CONTRACT(it, true); \
|
||||
it_t i = { it.tree, it.tree->tab[it.index].right }; \
|
||||
return i; \
|
||||
} \
|
||||
\
|
||||
M_INLINE bool \
|
||||
M_F(name, _root_p)(const it_t it) { \
|
||||
M_TR33_IT_CONTRACT(it, true); \
|
||||
|
||||
@@ -113,6 +113,17 @@ static void test_basic(void)
|
||||
tree_get_str(s, t, false);
|
||||
assert(string_equal_str_p(s, "[{-1,[{0,[{1,[{3},{5,[{2}]},{4,[{9},{7,[{8}]},{10},{6}]}]}]}]}]"));
|
||||
|
||||
assert( *tree_cref(it7) == 7 );
|
||||
assert( *tree_cref(tree_down(it7)) == 8 );
|
||||
assert( *tree_cref(tree_up(it7)) == 4);
|
||||
assert( *tree_cref(tree_left(it7)) == 9);
|
||||
assert( *tree_cref(tree_right(it7)) == 10);
|
||||
assert( *tree_cref(tree_down(root)) == 0);
|
||||
|
||||
assert( tree_end_p(tree_up(root)));
|
||||
assert( tree_end_p(tree_left(root)));
|
||||
assert( tree_end_p(tree_right(root)));
|
||||
|
||||
assert( *tree_down_ref(it7) == 8);
|
||||
assert( *tree_up_ref(it7) == 4);
|
||||
assert( *tree_left_ref(it7) == 9);
|
||||
|
||||
Reference in new issue
Block a user