version 1.1.2.2, 2011/06/07 11:18:13
|
version 1.3.28.2, 2012/08/17 22:00:03
|
Line 12 terms:
|
Line 12 terms:
|
All of the documentation and software included in the ELWIX and AITNET |
All of the documentation and software included in the ELWIX and AITNET |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
|
|
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 | Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
|
|
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
Line 135 struct { \
|
Line 135 struct { \
|
SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ |
SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ |
(head)->sph_root = tmp; \ |
(head)->sph_root = tmp; \ |
} while (0) |
} while (0) |
| |
#define SPLAY_ROTATE_LEFT(head, tmp, field) do { \ |
#define SPLAY_ROTATE_LEFT(head, tmp, field) do { \ |
SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \ |
SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \ |
SPLAY_LEFT(tmp, field) = (head)->sph_root; \ |
SPLAY_LEFT(tmp, field) = (head)->sph_root; \ |
Line 339 void name##_SPLAY_MINMAX(struct name *head, int __comp
|
Line 339 void name##_SPLAY_MINMAX(struct name *head, int __comp
|
(x) != NULL; \ |
(x) != NULL; \ |
(x) = SPLAY_NEXT(name, head, x)) |
(x) = SPLAY_NEXT(name, head, x)) |
|
|
|
#define SPLAY_FOREACH_SAFE(x, name, head, y) \ |
|
for ((x) = SPLAY_MIN(name, head); \ |
|
((x) != NULL) && \ |
|
((y) = SPLAY_NEXT(name, head, x), (x) != NULL); \ |
|
(x) = (y)) |
|
|
|
|
/* Macros that define a red-black tree */ |
/* Macros that define a red-black tree */ |
#define RB_HEAD(name, type) \ |
#define RB_HEAD(name, type) \ |
struct name { \ |
struct name { \ |
Line 381 struct { \
|
Line 388 struct { \
|
} while (0) |
} while (0) |
|
|
#ifndef RB_AUGMENT |
#ifndef RB_AUGMENT |
#define RB_AUGMENT(x) do {} while (0) | #define RB_AUGMENT(x) (void)(x) |
#endif |
#endif |
|
|
#define RB_ROTATE_LEFT(head, elm, tmp, field) do { \ |
#define RB_ROTATE_LEFT(head, elm, tmp, field) do { \ |
Line 425 struct { \
|
Line 432 struct { \
|
} while (0) |
} while (0) |
|
|
/* Generates prototypes and inline functions */ |
/* Generates prototypes and inline functions */ |
#define RB_PROTOTYPE(name, type, field, cmp) \ | #define RB_PROTOTYPE(name, type, field, cmp) \ |
RB_PROTOTYPE_INTERNAL(name, type, field, cmp,) |
RB_PROTOTYPE_INTERNAL(name, type, field, cmp,) |
#define RB_PROTOTYPE_STATIC(name, type, field, cmp) \ |
#define RB_PROTOTYPE_STATIC(name, type, field, cmp) \ |
RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static) |
RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static) |
Line 517 name##_RB_REMOVE_COLOR(struct name *head, struct type
|
Line 524 name##_RB_REMOVE_COLOR(struct name *head, struct type
|
if (RB_RIGHT(tmp, field) == NULL || \ |
if (RB_RIGHT(tmp, field) == NULL || \ |
RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) {\ |
RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) {\ |
struct type *oleft; \ |
struct type *oleft; \ |
if ((oleft = RB_LEFT(tmp, field)))\ | if ((oleft = RB_LEFT(tmp, field))) \ |
RB_COLOR(oleft, field) = RB_BLACK;\ |
RB_COLOR(oleft, field) = RB_BLACK;\ |
RB_COLOR(tmp, field) = RB_RED; \ |
RB_COLOR(tmp, field) = RB_RED; \ |
RB_ROTATE_RIGHT(head, tmp, oleft, field);\ |
RB_ROTATE_RIGHT(head, tmp, oleft, field);\ |
Line 549 name##_RB_REMOVE_COLOR(struct name *head, struct type
|
Line 556 name##_RB_REMOVE_COLOR(struct name *head, struct type
|
if (RB_LEFT(tmp, field) == NULL || \ |
if (RB_LEFT(tmp, field) == NULL || \ |
RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) {\ |
RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) {\ |
struct type *oright; \ |
struct type *oright; \ |
if ((oright = RB_RIGHT(tmp, field)))\ | if ((oright = RB_RIGHT(tmp, field))) \ |
RB_COLOR(oright, field) = RB_BLACK;\ |
RB_COLOR(oright, field) = RB_BLACK;\ |
RB_COLOR(tmp, field) = RB_RED; \ |
RB_COLOR(tmp, field) = RB_RED; \ |
RB_ROTATE_LEFT(head, tmp, oright, field);\ |
RB_ROTATE_LEFT(head, tmp, oright, field);\ |
Line 808 name##_RB_MINMAX(struct name *head, int val) \
|
Line 815 name##_RB_MINMAX(struct name *head, int val) \
|
(x) = (y)) |
(x) = (y)) |
|
|
/* Macros that define a avl tree */ |
/* Macros that define a avl tree */ |
#define AVL_MAX_HEIGHT 42 | #ifndef AVL_MAX_HEIGHT |
| #define AVL_MAX_HEIGHT 32 |
| #endif |
#define AVL_HEAD(name, type) \ |
#define AVL_HEAD(name, type) \ |
struct name { \ |
struct name { \ |
struct type *avlh_root; /* root of the tree */ \ | struct type *avlh_root; /* root of the tree */ \ |
int avlh_height; \ | |
long avlh_count; \ | |
} |
} |
|
|
#define AVL_INITIALIZER(root) \ |
#define AVL_INITIALIZER(root) \ |
{ NULL, 0, 0 } | { NULL } |
|
|
#define AVL_INIT(root, height) do { \ | #define AVL_INIT(root) do { \ |
(root)->avlh_root = NULL; \ |
(root)->avlh_root = NULL; \ |
(root)->avlh_height = !height ? AVL_MAX_HEIGHT : height; \ |
|
(root)->avlh_count = 0; \ |
|
} while (0) |
} while (0) |
|
|
#define AVL_ENTRY(type) \ |
#define AVL_ENTRY(type) \ |
struct { \ |
struct { \ |
struct type *avle_left; /* left element */ \ | struct type *avle_left; /* left element */ \ |
struct type *avle_right; /* right element */ \ | struct type *avle_right; /* right element */ \ |
int avle_height; /* node color */ \ | int avle_height; /* node height */ \ |
} |
} |
|
|
#define AVL_LEFT(elm, field) (elm)->field.avle_left |
#define AVL_LEFT(elm, field) (elm)->field.avle_left |
Line 837 struct { \
|
Line 842 struct { \
|
#define AVL_HEIGHT(elm, field) (elm)->field.avle_height |
#define AVL_HEIGHT(elm, field) (elm)->field.avle_height |
#define AVL_ROOT(head) (head)->avlh_root |
#define AVL_ROOT(head) (head)->avlh_root |
#define AVL_EMPTY(head) (AVL_ROOT(head) == NULL) |
#define AVL_EMPTY(head) (AVL_ROOT(head) == NULL) |
#define AVL_ROOT_HEIGHT(head) (head)->avlh_height |
|
#define AVL_ROOT_COUNT(head) (head)->avlh_count |
|
|
|
/* Generates prototypes and inline functions */ |
/* Generates prototypes and inline functions */ |
#define AVL_PROTOTYPE(name, type, field, cmp) \ |
#define AVL_PROTOTYPE(name, type, field, cmp) \ |
Line 1029 attr struct type * \
|
Line 1032 attr struct type * \
|
name##_AVL_INSERT(struct name *head, struct type *elm) \ |
name##_AVL_INSERT(struct name *head, struct type *elm) \ |
{ \ |
{ \ |
struct type *temp, **pt; \ |
struct type *temp, **pt; \ |
struct type ***ancestors; \ | struct type **ancestors[AVL_MAX_HEIGHT] = { 0 }; \ |
register int i; \ |
register int i; \ |
int comp; \ |
int comp; \ |
\ |
\ |
ancestors = (struct type ***) alloca(AVL_ROOT_HEIGHT(head) * sizeof(void*)); \ | for (i = 0, pt = &AVL_ROOT(head); i < AVL_MAX_HEIGHT && *pt; i++) { \ |
if (!ancestors) \ | |
return (struct type *) -1; \ | |
else \ | |
memset(ancestors, 0, AVL_ROOT_HEIGHT(head) * sizeof(void*)); \ | |
for (i = 0, pt = &AVL_ROOT(head); i < AVL_ROOT_HEIGHT(head) && *pt; i++) { \ | |
temp = *pt; \ |
temp = *pt; \ |
ancestors[i] = pt; \ |
ancestors[i] = pt; \ |
comp = (cmp)(temp, elm); \ |
comp = (cmp)(temp, elm); \ |
Line 1054 name##_AVL_INSERT(struct name *head, struct type *elm)
|
Line 1052 name##_AVL_INSERT(struct name *head, struct type *elm)
|
AVL_LEFT(elm, field) = AVL_RIGHT(elm, field) = (struct type *) NULL; \ |
AVL_LEFT(elm, field) = AVL_RIGHT(elm, field) = (struct type *) NULL; \ |
AVL_HEIGHT(elm, field) = 1; \ |
AVL_HEIGHT(elm, field) = 1; \ |
\ |
\ |
AVL_ROOT_COUNT(head)++; \ |
|
AVL_REBALANCE(ancestors, type, field, i); \ |
AVL_REBALANCE(ancestors, type, field, i); \ |
return (NULL); \ |
return (NULL); \ |
} \ |
} \ |
Line 1063 attr struct type * \
|
Line 1060 attr struct type * \
|
name##_AVL_REMOVE(struct name *head, struct type *elm) \ |
name##_AVL_REMOVE(struct name *head, struct type *elm) \ |
{ \ |
{ \ |
struct type *temp, *old, **dp, **pt; \ |
struct type *temp, *old, **dp, **pt; \ |
struct type ***ancestors; \ | struct type **ancestors[AVL_MAX_HEIGHT] = { 0 }; \ |
register int i; \ |
register int i; \ |
int comp, delcnt; \ |
int comp, delcnt; \ |
\ |
\ |
ancestors = (struct type ***) alloca(AVL_ROOT_HEIGHT(head) * sizeof(void*)); \ | for (i = 0, pt = &AVL_ROOT(head); i < AVL_MAX_HEIGHT; i++) { \ |
if (!ancestors) \ | |
return (NULL); \ | |
else \ | |
memset(ancestors, 0, AVL_ROOT_HEIGHT(head) * sizeof(void*)); \ | |
for (i = 0, pt = &AVL_ROOT(head); i < AVL_ROOT_HEIGHT(head); i++) { \ | |
if (!*pt) \ |
if (!*pt) \ |
return (NULL); \ |
return (NULL); \ |
else \ |
else \ |
Line 1094 name##_AVL_REMOVE(struct name *head, struct type *elm)
|
Line 1086 name##_AVL_REMOVE(struct name *head, struct type *elm)
|
} else { \ |
} else { \ |
delcnt = i; \ |
delcnt = i; \ |
dp = pt; \ |
dp = pt; \ |
for (pt = &AVL_LEFT(temp, field); i < AVL_ROOT_HEIGHT(head) && \ | for (pt = &AVL_LEFT(temp, field); i < AVL_MAX_HEIGHT && \ |
AVL_RIGHT(temp, field); i++) { \ |
AVL_RIGHT(temp, field); i++) { \ |
temp = *pt; \ |
temp = *pt; \ |
ancestors[i] = pt; \ |
ancestors[i] = pt; \ |
Line 1110 name##_AVL_REMOVE(struct name *head, struct type *elm)
|
Line 1102 name##_AVL_REMOVE(struct name *head, struct type *elm)
|
ancestors[delcnt] = &AVL_LEFT(temp, field); \ |
ancestors[delcnt] = &AVL_LEFT(temp, field); \ |
} \ |
} \ |
\ |
\ |
AVL_ROOT_COUNT(head)--; \ |
|
AVL_REBALANCE(ancestors, type, field, i); \ |
AVL_REBALANCE(ancestors, type, field, i); \ |
return (old); \ |
return (old); \ |
} |
} |