version 1.2.2.1, 2011/06/20 15:05:48
|
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 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 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); \ |
} |
} |