((((base->left ? base->left->height : -1)) > ((base->right ? base->right->height : -1)))
?
((base->left ? base->left->height : -1) + 1)
:
((base->right ? base->right->height : -1) + 1))
其中base->left是NULL,而base->right->height是0。
我怎么算都应该是1。。
这个表达式是这么来的:
#define MAX_PLUS_1(a, b) (((a) > (b)) ? (a + 1) : (b + 1))
#define BINARY_TREE_HEIGHT(node) (node ? node->height : -1)
#define BINARY_TREE_SYN_HEIGHT(left, right) \
MAX_PLUS_1(\
BINARY_TREE_HEIGHT(left),\
BINARY_TREE_HEIGHT(right)\
)
它其实就是 BINARY_TREE_SYN_HEIGHT(base->left, base->right)
其中base->right的类型是:
typedef struct binary_tree_node
{
struct binary_tree_node *left;
struct binary_tree_node *right;
struct binary_tree_node *parent;
uint32_t ksiz;
uint32_t vsiz;
uint32_t vsiz_remain;
uint32_t height;
} t_binary_tree_node;
