Showing
2 changed files
with
30 additions
and
30 deletions
@@ -32,14 +32,12 @@ | @@ -32,14 +32,12 @@ | ||
32 | #define TR_TREE_CHILD(node) \ | 32 | #define TR_TREE_CHILD(node) \ |
33 | (NULL==TR_TREE_RIGHT((node))?TR_TREE_LEFT((node)):TR_TREE_RIGHT((node))) | 33 | (NULL==TR_TREE_RIGHT((node))?TR_TREE_LEFT((node)):TR_TREE_RIGHT((node))) |
34 | 34 | ||
35 | -#define TR_TREE_SIBLING(node) \ | ||
36 | - (NULL!=TR_TREE_PARENT((node))? \ | ||
37 | - ((node)==TR_TREE_PARENT((node))->left? \ | ||
38 | - TR_TREE_PARENT((node))->right: \ | ||
39 | - TR_TREE_PARENT((node))->left): \ | ||
40 | - NULL) | ||
41 | - | ||
42 | -#define TR_TREE_GRANDPARENT(node) (TR_TREE_PARENT((node))->parent) | 35 | +#define TR_TREE_SIBLING(node) \ |
36 | + (NULL!=(node)->parent? \ | ||
37 | + ((node)==(node)->parent->left? \ | ||
38 | + (node)->parent->right: \ | ||
39 | + (node)->parent->left): \ | ||
40 | + NULL) | ||
43 | 41 | ||
44 | #define TR_TREE_UNCLE(node) \ | 42 | #define TR_TREE_UNCLE(node) \ |
45 | ((node)->parent == (node)->parent->parent->left \ | 43 | ((node)->parent == (node)->parent->parent->left \ |
@@ -110,31 +108,31 @@ typedef enum {rbBlack=1, rbRed=2} TR_rbColor; | @@ -110,31 +108,31 @@ typedef enum {rbBlack=1, rbRed=2} TR_rbColor; | ||
110 | * it before using this macro. | 108 | * it before using this macro. |
111 | * Also be aware that found needs to be a valid lvalue and an integer. | 109 | * Also be aware that found needs to be a valid lvalue and an integer. |
112 | */ | 110 | */ |
113 | -#define TR_TREE_FIND(node, search, found, comp) \ | ||
114 | - (found) = -1; \ | ||
115 | - if ((node)) { \ | ||
116 | - while(1) { \ | ||
117 | - (found) = (comp)((node)->data, (search)); \ | ||
118 | - if (0 != (found)) { \ | ||
119 | - if (0 < (found)) { \ | ||
120 | - if (! (node)->left) break; \ | ||
121 | - (node) = (node)->left; \ | ||
122 | - } else { \ | ||
123 | - if (! (node)->right) break; \ | ||
124 | - (node) = (node)->right; \ | ||
125 | - } \ | ||
126 | - } else { \ | ||
127 | - break; \ | ||
128 | - } \ | ||
129 | - } \ | 111 | +#define TR_TREE_FIND(node, search, found, comp) \ |
112 | + (found) = -1; \ | ||
113 | + if ((node)) { \ | ||
114 | + while (1) { \ | ||
115 | + (found) = (comp)((node)->data, (search)); \ | ||
116 | + if (0 != (found)) { \ | ||
117 | + if (0 < (found)) { \ | ||
118 | + if (! (node)->left) break; \ | ||
119 | + (node) = (node)->left; \ | ||
120 | + } else { \ | ||
121 | + if (! (node)->right) break; \ | ||
122 | + (node) = (node)->right; \ | ||
123 | + } \ | ||
124 | + } else { \ | ||
125 | + break; \ | ||
126 | + } \ | ||
127 | + } \ | ||
130 | } | 128 | } |
131 | 129 | ||
132 | #define TR_TREE_BALANCE_DELETE_CASE1(node) \ | 130 | #define TR_TREE_BALANCE_DELETE_CASE1(node) \ |
133 | - if (NULL == TR_TREE_PARENT((node))) { \ | ||
134 | - break; \ | 131 | + if (NULL == (node)->parent) { \ |
132 | + break; \ | ||
135 | } | 133 | } |
136 | 134 | ||
137 | -#define TR_TREE_BALANCE_DELETE_CASE2(root, node, sibling) \ | 135 | +#define TR_TREE_BALANCE_DELETE_CASE2(root, node, sibling) \ |
138 | if (NULL != (sibling) && rbRed == (sibling)->color) { \ | 136 | if (NULL != (sibling) && rbRed == (sibling)->color) { \ |
139 | (node)->parent->color = rbRed; \ | 137 | (node)->parent->color = rbRed; \ |
140 | (sibling)->color = rbBlack; \ | 138 | (sibling)->color = rbBlack; \ |
@@ -216,6 +214,7 @@ typedef enum {rbBlack=1, rbRed=2} TR_rbColor; | @@ -216,6 +214,7 @@ typedef enum {rbBlack=1, rbRed=2} TR_rbColor; | ||
216 | #define TR_TREE_BALANCE_DELETE(root, node, sibling) \ | 214 | #define TR_TREE_BALANCE_DELETE(root, node, sibling) \ |
217 | while(1) { \ | 215 | while(1) { \ |
218 | TR_TREE_BALANCE_DELETE_CASE1((node)) \ | 216 | TR_TREE_BALANCE_DELETE_CASE1((node)) \ |
217 | + sibling = TR_TREE_SIBLING(node); \ | ||
219 | TR_TREE_BALANCE_DELETE_CASE2((root), (node), (sibling)) \ | 218 | TR_TREE_BALANCE_DELETE_CASE2((root), (node), (sibling)) \ |
220 | TR_TREE_BALANCE_DELETE_CASE34((root), (node), (sibling)) \ | 219 | TR_TREE_BALANCE_DELETE_CASE34((root), (node), (sibling)) \ |
221 | TR_TREE_BALANCE_DELETE_CASE5((root), (node), (sibling)) \ | 220 | TR_TREE_BALANCE_DELETE_CASE5((root), (node), (sibling)) \ |
@@ -224,7 +223,7 @@ typedef enum {rbBlack=1, rbRed=2} TR_rbColor; | @@ -224,7 +223,7 @@ typedef enum {rbBlack=1, rbRed=2} TR_rbColor; | ||
224 | } | 223 | } |
225 | 224 | ||
226 | #define TR_TREE_BALANCE_INSERT_CASE1(node) \ | 225 | #define TR_TREE_BALANCE_INSERT_CASE1(node) \ |
227 | - if (NULL == TR_TREE_PARENT((node))) { \ | 226 | + if (NULL == (node)->parent) { \ |
228 | (node)->color = rbBlack; \ | 227 | (node)->color = rbBlack; \ |
229 | break; \ | 228 | break; \ |
230 | } | 229 | } |
@@ -98,6 +98,7 @@ newElement(size_t size) | @@ -98,6 +98,7 @@ newElement(size_t size) | ||
98 | return element; | 98 | return element; |
99 | } | 99 | } |
100 | 100 | ||
101 | +#ifdef MEM_OPT | ||
101 | static | 102 | static |
102 | int | 103 | int |
103 | _memSegmentFindCompare(const void * a, const void * b) | 104 | _memSegmentFindCompare(const void * a, const void * b) |
@@ -290,7 +291,6 @@ deleteElement(struct memSegment ** tree, size_t size) | @@ -290,7 +291,6 @@ deleteElement(struct memSegment ** tree, size_t size) | ||
290 | return del_node; | 291 | return del_node; |
291 | } | 292 | } |
292 | 293 | ||
293 | - s = TR_TREE_SIBLING(node); | ||
294 | TR_TREE_BALANCE_DELETE(tree, node, s); | 294 | TR_TREE_BALANCE_DELETE(tree, node, s); |
295 | 295 | ||
296 | return del_node; | 296 | return del_node; |
@@ -365,6 +365,7 @@ segmentFree(struct memSegment * segment, int depth) | @@ -365,6 +365,7 @@ segmentFree(struct memSegment * segment, int depth) | ||
365 | segment = next; | 365 | segment = next; |
366 | } | 366 | } |
367 | } | 367 | } |
368 | +#endif | ||
368 | 369 | ||
369 | void * | 370 | void * |
370 | TR_reference(void * mem) | 371 | TR_reference(void * mem) |
Please
register
or
login
to post a comment