Commit db5f9d43f73232005c597f273cb74c0fca9908f6
1 parent
0cecd080
ensure that a grandparent exists when it is involved in the ballance
Showing
1 changed file
with
10 additions
and
8 deletions
@@ -263,14 +263,16 @@ typedef enum {rbBlack=1, rbRed=2} TR_rbColor; | @@ -263,14 +263,16 @@ typedef enum {rbBlack=1, rbRed=2} TR_rbColor; | ||
263 | TR_TREE_ROTATE(left, (root), (node)->parent->parent); \ | 263 | TR_TREE_ROTATE(left, (root), (node)->parent->parent); \ |
264 | } | 264 | } |
265 | 265 | ||
266 | -#define TR_TREE_BALANCE_INSERT(root, node) \ | ||
267 | - while (1) { \ | ||
268 | - TR_TREE_BALANCE_INSERT_CASE1((node)) \ | ||
269 | - TR_TREE_BALANCE_INSERT_CASE2((node)) \ | ||
270 | - TR_TREE_BALANCE_INSERT_CASE3((node)) \ | ||
271 | - TR_TREE_BALANCE_INSERT_CASE4((root), (node)) \ | ||
272 | - TR_TREE_BALANCE_INSERT_CASE5((root), (node)) \ | ||
273 | - break; \ | 266 | +#define TR_TREE_BALANCE_INSERT(root, node) \ |
267 | + while (1) { \ | ||
268 | + TR_TREE_BALANCE_INSERT_CASE1((node)) \ | ||
269 | + TR_TREE_BALANCE_INSERT_CASE2((node)) \ | ||
270 | + if (NULL != (node)->parent->parent) { \ | ||
271 | + TR_TREE_BALANCE_INSERT_CASE3((node)) \ | ||
272 | + TR_TREE_BALANCE_INSERT_CASE4((root), (node)) \ | ||
273 | + TR_TREE_BALANCE_INSERT_CASE5((root), (node)) \ | ||
274 | + } \ | ||
275 | + break; \ | ||
274 | } | 276 | } |
275 | 277 | ||
276 | #endif // __TR_TREE_MACROS_H__ | 278 | #endif // __TR_TREE_MACROS_H__ |
Please
register
or
login
to post a comment