Skip to content

Commit 756f0a9

Browse files
committed
tree: change type and size of the extra field
Instead of using a bool, let's use a 2-bit unsigned int. Having two bits will clearly be enough for red-black trees, but it will also allow AVL trees (which need to store 3 states per node) to be implemented later on. Signed-off-by: Josef 'Jeff' Sipek <[email protected]>
1 parent 90e9844 commit 756f0a9

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

include/jeffpc/tree_private.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
struct tree_node {
3131
struct tree_node *children[2];
3232
struct tree_node *_parent;
33-
bool _extra;
33+
unsigned int _extra:2;
3434
};
3535

3636
struct tree_tree {

tree.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static inline void __swap_nodes(struct tree_tree *tree,
141141
const enum tree_dir right = 1 - left;
142142
const bool root = tree->root == x;
143143
enum tree_dir dir_to_orig_x;
144-
bool tmp;
144+
unsigned int tmp;
145145

146146
ASSERT3P(x, !=, y);
147147
ASSERT3P(y->children[left], ==, NULL);

tree_impl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ static inline void set_parent(struct tree_node *node, struct tree_node *parent)
5151
node->_parent = parent;
5252
}
5353

54-
static inline bool get_extra(struct tree_node *node)
54+
static inline unsigned int get_extra(struct tree_node *node)
5555
{
5656
return node->_extra;
5757
}
5858

59-
static inline void set_extra(struct tree_node *node, bool extra)
59+
static inline void set_extra(struct tree_node *node, unsigned int extra)
6060
{
6161
node->_extra = extra;
6262
}

0 commit comments

Comments
 (0)