| gg-tree.h | | gg-tree.h | |
|
| /* $Id: gg-tree.h,v 1.3 2005/08/26 15:00:51 cegger Exp $ | | /* $Id$ | |
| *************************************************************************** | | *************************************************************************** | |
| | | | |
| LibGG - implementations of splay and red-black trees | | LibGG - implementations of splay and red-black trees | |
| | | | |
| *************************************************************************** | | *************************************************************************** | |
| */ | | */ | |
| | | | |
| /* This code has been imported to GGI from NetBSD-current 2004-10-27 */ | | /* This code has been imported to GGI from NetBSD-current 2004-10-27 */ | |
| | | | |
| /* | | /* | |
| | | | |
| skipping to change at line 367 | | skipping to change at line 367 | |
| GG_RB_LEFT(tmp, field) = (elm); \ | | GG_RB_LEFT(tmp, field) = (elm); \ | |
| GG_RB_PARENT(elm, field) = (tmp); \ | | GG_RB_PARENT(elm, field) = (tmp); \ | |
| GG_RB_AUGMENT(tmp); \ | | GG_RB_AUGMENT(tmp); \ | |
| if ((GG_RB_PARENT(tmp, field))) \ | | if ((GG_RB_PARENT(tmp, field))) \ | |
| GG_RB_AUGMENT(GG_RB_PARENT(tmp, field)); \ | | GG_RB_AUGMENT(GG_RB_PARENT(tmp, field)); \ | |
| } while (/*CONSTCOND*/ 0) | | } while (/*CONSTCOND*/ 0) | |
| | | | |
| #define GG_RB_ROTATE_RIGHT(head, elm, tmp, field) do { \ | | #define GG_RB_ROTATE_RIGHT(head, elm, tmp, field) do { \ | |
| (tmp) = GG_RB_LEFT(elm, field); \ | | (tmp) = GG_RB_LEFT(elm, field); \ | |
| if ((GG_RB_LEFT(elm, field) = GG_RB_RIGHT(tmp, field)) != NULL) {\ | | if ((GG_RB_LEFT(elm, field) = GG_RB_RIGHT(tmp, field)) != NULL) {\ | |
|
| GG_RB_PARENT(RB_RIGHT(tmp, field), field) = (elm); \ | | GG_RB_PARENT(GG_RB_RIGHT(tmp, field), field) = (elm); \ | |
| } \ | | } \ | |
| GG_RB_AUGMENT(elm); \ | | GG_RB_AUGMENT(elm); \ | |
| if ((GG_RB_PARENT(tmp, field) = GG_RB_PARENT(elm, field)) != NULL) {
\ | | if ((GG_RB_PARENT(tmp, field) = GG_RB_PARENT(elm, field)) != NULL) {
\ | |
| if ((elm) == GG_RB_LEFT(GG_RB_PARENT(elm, field), field))\ | | if ((elm) == GG_RB_LEFT(GG_RB_PARENT(elm, field), field))\ | |
| GG_RB_LEFT(GG_RB_PARENT(elm, field), field) = (tmp);
\ | | GG_RB_LEFT(GG_RB_PARENT(elm, field), field) = (tmp);
\ | |
| else \ | | else \ | |
| GG_RB_RIGHT(GG_RB_PARENT(elm, field), field) = (tmp)
;\ | | GG_RB_RIGHT(GG_RB_PARENT(elm, field), field) = (tmp)
;\ | |
| } else \ | | } else \ | |
| (head)->rbh_root = (tmp); \ | | (head)->rbh_root = (tmp); \ | |
| GG_RB_RIGHT(tmp, field) = (elm); \ | | GG_RB_RIGHT(tmp, field) = (elm); \ | |
| | | | |
| skipping to change at line 451 | | skipping to change at line 451 | |
| } \ | | } \ | |
| \ | | \ | |
| void \ | | void \ | |
| name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type
*elm) \ | | name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type
*elm) \ | |
| { \ | | { \ | |
| struct type *tmp; \ | | struct type *tmp; \ | |
| while ((elm == NULL || GG_RB_COLOR(elm, field) == GG_RB_BLACK) &&\ | | while ((elm == NULL || GG_RB_COLOR(elm, field) == GG_RB_BLACK) &&\ | |
| elm != GG_RB_ROOT(head)) { \ | | elm != GG_RB_ROOT(head)) { \ | |
| if (GG_RB_LEFT(parent, field) == elm) { \ | | if (GG_RB_LEFT(parent, field) == elm) { \ | |
| tmp = GG_RB_RIGHT(parent, field); \ | | tmp = GG_RB_RIGHT(parent, field); \ | |
|
| if (GG_RB_COLOR(tmp, field) == RB_RED) { \ | | if (GG_RB_COLOR(tmp, field) == GG_RB_RED) { \ | |
| GG_RB_SET_BLACKRED(tmp, parent, field); \ | | GG_RB_SET_BLACKRED(tmp, parent, field); \ | |
| GG_RB_ROTATE_LEFT(head, parent, tmp, field);
\ | | GG_RB_ROTATE_LEFT(head, parent, tmp, field);
\ | |
| tmp = GG_RB_RIGHT(parent, field); \ | | tmp = GG_RB_RIGHT(parent, field); \ | |
| } \ | | } \ | |
| if ((GG_RB_LEFT(tmp, field) == NULL || \ | | if ((GG_RB_LEFT(tmp, field) == NULL || \ | |
| GG_RB_COLOR(GG_RB_LEFT(tmp, field), field) == GG
_RB_BLACK) &&\ | | GG_RB_COLOR(GG_RB_LEFT(tmp, field), field) == GG
_RB_BLACK) &&\ | |
| (GG_RB_RIGHT(tmp, field) == NULL || \ | | (GG_RB_RIGHT(tmp, field) == NULL || \ | |
| GG_RB_COLOR(GG_RB_RIGHT(tmp, field), field) == G
G_RB_BLACK)) {\ | | GG_RB_COLOR(GG_RB_RIGHT(tmp, field), field) == G
G_RB_BLACK)) {\ | |
|
| GG_RB_COLOR(tmp, field) = RB_RED; \ | | GG_RB_COLOR(tmp, field) = GG_RB_RED; \ | |
| elm = parent; \ | | elm = parent; \ | |
| parent = GG_RB_PARENT(elm, field); \ | | parent = GG_RB_PARENT(elm, field); \ | |
| } else { \ | | } else { \ | |
| if (GG_RB_RIGHT(tmp, field) == NULL || \ | | if (GG_RB_RIGHT(tmp, field) == NULL || \ | |
| GG_RB_COLOR(GG_RB_RIGHT(tmp, field), fie
ld) == GG_RB_BLACK) {\ | | GG_RB_COLOR(GG_RB_RIGHT(tmp, field), fie
ld) == GG_RB_BLACK) {\ | |
| struct type *oleft; \ | | struct type *oleft; \ | |
| if ((oleft = GG_RB_LEFT(tmp, field))
\ | | if ((oleft = GG_RB_LEFT(tmp, field))
\ | |
| != NULL) \ | | != NULL) \ | |
| GG_RB_COLOR(oleft, field) =
GG_RB_BLACK;\ | | GG_RB_COLOR(oleft, field) =
GG_RB_BLACK;\ | |
| GG_RB_COLOR(tmp, field) = GG_RB_RED;
\ | | GG_RB_COLOR(tmp, field) = GG_RB_RED;
\ | |
| | | | |
| skipping to change at line 493 | | skipping to change at line 493 | |
| tmp = GG_RB_LEFT(parent, field); \ | | tmp = GG_RB_LEFT(parent, field); \ | |
| if (GG_RB_COLOR(tmp, field) == GG_RB_RED) { \ | | if (GG_RB_COLOR(tmp, field) == GG_RB_RED) { \ | |
| GG_RB_SET_BLACKRED(tmp, parent, field); \ | | GG_RB_SET_BLACKRED(tmp, parent, field); \ | |
| GG_RB_ROTATE_RIGHT(head, parent, tmp, field)
;\ | | GG_RB_ROTATE_RIGHT(head, parent, tmp, field)
;\ | |
| tmp = GG_RB_LEFT(parent, field); \ | | tmp = GG_RB_LEFT(parent, field); \ | |
| } \ | | } \ | |
| if ((GG_RB_LEFT(tmp, field) == NULL || \ | | if ((GG_RB_LEFT(tmp, field) == NULL || \ | |
| GG_RB_COLOR(GG_RB_LEFT(tmp, field), field) == GG
_RB_BLACK) &&\ | | GG_RB_COLOR(GG_RB_LEFT(tmp, field), field) == GG
_RB_BLACK) &&\ | |
| (GG_RB_RIGHT(tmp, field) == NULL || \ | | (GG_RB_RIGHT(tmp, field) == NULL || \ | |
| GG_RB_COLOR(GG_RB_RIGHT(tmp, field), field) == G
G_RB_BLACK)) {\ | | GG_RB_COLOR(GG_RB_RIGHT(tmp, field), field) == G
G_RB_BLACK)) {\ | |
|
| GG_RB_COLOR(tmp, field) = RB_RED; \ | | GG_RB_COLOR(tmp, field) = GG_RB_RED; \ | |
| elm = parent; \ | | elm = parent; \ | |
| parent = GG_RB_PARENT(elm, field); \ | | parent = GG_RB_PARENT(elm, field); \ | |
| } else { \ | | } else { \ | |
| if (GG_RB_LEFT(tmp, field) == NULL || \ | | if (GG_RB_LEFT(tmp, field) == NULL || \ | |
| GG_RB_COLOR(GG_RB_LEFT(tmp, field), fiel
d) == GG_RB_BLACK) {\ | | GG_RB_COLOR(GG_RB_LEFT(tmp, field), fiel
d) == GG_RB_BLACK) {\ | |
| struct type *oright; \ | | struct type *oright; \ | |
| if ((oright = GG_RB_RIGHT(tmp, field
)) \ | | if ((oright = GG_RB_RIGHT(tmp, field
)) \ | |
| != NULL) \ | | != NULL) \ | |
| GG_RB_COLOR(oright, field) =
GG_RB_BLACK;\ | | GG_RB_COLOR(oright, field) =
GG_RB_BLACK;\ | |
| GG_RB_COLOR(tmp, field) = GG_RB_RED;
\ | | GG_RB_COLOR(tmp, field) = GG_RB_RED;
\ | |
| | | | |
| skipping to change at line 561 | | skipping to change at line 561 | |
| if (GG_RB_PARENT(old, field)) { \ | | if (GG_RB_PARENT(old, field)) { \ | |
| if (GG_RB_LEFT(GG_RB_PARENT(old, field), field) == o
ld)\ | | if (GG_RB_LEFT(GG_RB_PARENT(old, field), field) == o
ld)\ | |
| GG_RB_LEFT(GG_RB_PARENT(old, field), field)
= elm;\ | | GG_RB_LEFT(GG_RB_PARENT(old, field), field)
= elm;\ | |
| else \ | | else \ | |
| GG_RB_RIGHT(GG_RB_PARENT(old, field), field)
= elm;\ | | GG_RB_RIGHT(GG_RB_PARENT(old, field), field)
= elm;\ | |
| GG_RB_AUGMENT(GG_RB_PARENT(old, field)); \ | | GG_RB_AUGMENT(GG_RB_PARENT(old, field)); \ | |
| } else \ | | } else \ | |
| GG_RB_ROOT(head) = elm; \ | | GG_RB_ROOT(head) = elm; \ | |
| GG_RB_PARENT(GG_RB_LEFT(old, field), field) = elm; \ | | GG_RB_PARENT(GG_RB_LEFT(old, field), field) = elm; \ | |
| if (GG_RB_RIGHT(old, field)) \ | | if (GG_RB_RIGHT(old, field)) \ | |
|
| GG_RB_PARENT(RB_RIGHT(old, field), field) = elm;\ | | GG_RB_PARENT(GG_RB_RIGHT(old, field), field) = elm;\ | |
| if (parent) { \ | | if (parent) { \ | |
| left = parent; \ | | left = parent; \ | |
| do { \ | | do { \ | |
| GG_RB_AUGMENT(left); \ | | GG_RB_AUGMENT(left); \ | |
| } while ((left = GG_RB_PARENT(left, field)) != NULL)
; \ | | } while ((left = GG_RB_PARENT(left, field)) != NULL)
; \ | |
| } \ | | } \ | |
| goto color; \ | | goto color; \ | |
| } \ | | } \ | |
| parent = GG_RB_PARENT(elm, field); \ | | parent = GG_RB_PARENT(elm, field); \ | |
| color = GG_RB_COLOR(elm, field); \ | | color = GG_RB_COLOR(elm, field); \ | |
| | | | |
End of changes. 6 change blocks. |
| 6 lines changed or deleted | | 6 lines changed or added | |
|