|
|
|
@ -0,0 +1,725 @@
|
|
|
|
|
$OpenBSD: patch-src_redblack_c,v 1.1 2012/11/07 14:53:59 dcoppa Exp $
|
|
|
|
|
|
|
|
|
|
redblack.h:45:1: warning: "RB_ENTRY" redefined
|
|
|
|
|
/usr/include/sys/tree.h:305:1: warning: this is the location of the previous definition
|
|
|
|
|
|
|
|
|
|
--- src/redblack.c.orig Sun Dec 9 14:03:36 2007
|
|
|
|
|
+++ src/redblack.c Wed Nov 7 15:45:17 2012
|
|
|
|
|
@@ -39,20 +39,20 @@ static char rcsid[]="$Id: redblack.c,v 1.9 2003/10/24
|
|
|
|
|
|
|
|
|
|
enum nodecolour { BLACK, RED };
|
|
|
|
|
|
|
|
|
|
-struct RB_ENTRY(node)
|
|
|
|
|
+struct USHARE_RB_ENTRY(node)
|
|
|
|
|
{
|
|
|
|
|
- struct RB_ENTRY(node) *left; /* Left down */
|
|
|
|
|
- struct RB_ENTRY(node) *right; /* Right down */
|
|
|
|
|
- struct RB_ENTRY(node) *up; /* Up */
|
|
|
|
|
+ struct USHARE_RB_ENTRY(node) *left; /* Left down */
|
|
|
|
|
+ struct USHARE_RB_ENTRY(node) *right; /* Right down */
|
|
|
|
|
+ struct USHARE_RB_ENTRY(node) *up; /* Up */
|
|
|
|
|
enum nodecolour colour; /* Node colour */
|
|
|
|
|
#ifdef RB_INLINE
|
|
|
|
|
- RB_ENTRY(data_t) key; /* User's key (and data) */
|
|
|
|
|
+ USHARE_RB_ENTRY(data_t) key; /* User's key (and data) */
|
|
|
|
|
#define RB_GET(x,y) &x->y
|
|
|
|
|
-#define RB_SET(x,y,v) x->y = *(v)
|
|
|
|
|
+#define USHARE_RB_SET(x,y,v) x->y = *(v)
|
|
|
|
|
#else
|
|
|
|
|
- const RB_ENTRY(data_t) *key; /* Pointer to user's key (and data) */
|
|
|
|
|
+ const USHARE_RB_ENTRY(data_t) *key; /* Pointer to user's key (and data) */
|
|
|
|
|
#define RB_GET(x,y) x->y
|
|
|
|
|
-#define RB_SET(x,y,v) x->y = v
|
|
|
|
|
+#define USHARE_RB_SET(x,y,v) x->y = v
|
|
|
|
|
#endif /* RB_INLINE */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@@ -63,50 +63,50 @@ struct RB_ENTRY(node)
|
|
|
|
|
** Initialization of the last field in this initializer is left implicit
|
|
|
|
|
** because it could be of any type. We count on the compiler to zero it.
|
|
|
|
|
*/
|
|
|
|
|
-struct RB_ENTRY(node) RB_ENTRY(_null)={&RB_ENTRY(_null), &RB_ENTRY(_null), &RB_ENTRY(_null), BLACK, &RB_ENTRY(_null)};
|
|
|
|
|
-#define RBNULL (&RB_ENTRY(_null))
|
|
|
|
|
+struct USHARE_RB_ENTRY(node) USHARE_RB_ENTRY(_null)={&USHARE_RB_ENTRY(_null), &USHARE_RB_ENTRY(_null), &USHARE_RB_ENTRY(_null), BLACK, &USHARE_RB_ENTRY(_null)};
|
|
|
|
|
+#define RBNULL (&USHARE_RB_ENTRY(_null))
|
|
|
|
|
|
|
|
|
|
#if defined(USE_SBRK)
|
|
|
|
|
|
|
|
|
|
-static struct RB_ENTRY(node) *RB_ENTRY(_alloc)();
|
|
|
|
|
-static void RB_ENTRY(_free)(struct RB_ENTRY(node) *);
|
|
|
|
|
+static struct USHARE_RB_ENTRY(node) *USHARE_RB_ENTRY(_alloc)();
|
|
|
|
|
+static void USHARE_RB_ENTRY(_free)(struct USHARE_RB_ENTRY(node) *);
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
-static struct RB_ENTRY(node) *RB_ENTRY(_alloc)() {return (struct RB_ENTRY(node) *) malloc(sizeof(struct RB_ENTRY(node)));}
|
|
|
|
|
-static void RB_ENTRY(_free)(struct RB_ENTRY(node) *x) {free(x);}
|
|
|
|
|
+static struct USHARE_RB_ENTRY(node) *USHARE_RB_ENTRY(_alloc)() {return (struct USHARE_RB_ENTRY(node) *) malloc(sizeof(struct USHARE_RB_ENTRY(node)));}
|
|
|
|
|
+static void USHARE_RB_ENTRY(_free)(struct USHARE_RB_ENTRY(node) *x) {free(x);}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* These functions are always needed */
|
|
|
|
|
-static void RB_ENTRY(_left_rotate)(struct RB_ENTRY(node) **, struct RB_ENTRY(node) *);
|
|
|
|
|
-static void RB_ENTRY(_right_rotate)(struct RB_ENTRY(node) **, struct RB_ENTRY(node) *);
|
|
|
|
|
-static struct RB_ENTRY(node) *RB_ENTRY(_successor)(const struct RB_ENTRY(node) *);
|
|
|
|
|
-static struct RB_ENTRY(node) *RB_ENTRY(_predecessor)(const struct RB_ENTRY(node) *);
|
|
|
|
|
-static struct RB_ENTRY(node) *RB_ENTRY(_traverse)(int, const RB_ENTRY(data_t) * , struct RB_ENTRY(tree) *);
|
|
|
|
|
+static void USHARE_RB_ENTRY(_left_rotate)(struct USHARE_RB_ENTRY(node) **, struct USHARE_RB_ENTRY(node) *);
|
|
|
|
|
+static void USHARE_RB_ENTRY(_right_rotate)(struct USHARE_RB_ENTRY(node) **, struct USHARE_RB_ENTRY(node) *);
|
|
|
|
|
+static struct USHARE_RB_ENTRY(node) *USHARE_RB_ENTRY(_successor)(const struct USHARE_RB_ENTRY(node) *);
|
|
|
|
|
+static struct USHARE_RB_ENTRY(node) *USHARE_RB_ENTRY(_predecessor)(const struct USHARE_RB_ENTRY(node) *);
|
|
|
|
|
+static struct USHARE_RB_ENTRY(node) *USHARE_RB_ENTRY(_traverse)(int, const USHARE_RB_ENTRY(data_t) * , struct USHARE_RB_ENTRY(tree) *);
|
|
|
|
|
|
|
|
|
|
/* These functions may not be needed */
|
|
|
|
|
#ifndef no_lookup
|
|
|
|
|
-static struct RB_ENTRY(node) *RB_ENTRY(_lookup)(int, const RB_ENTRY(data_t) * , struct RB_ENTRY(tree) *);
|
|
|
|
|
+static struct USHARE_RB_ENTRY(node) *USHARE_RB_ENTRY(_lookup)(int, const USHARE_RB_ENTRY(data_t) * , struct USHARE_RB_ENTRY(tree) *);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef no_destroy
|
|
|
|
|
-static void RB_ENTRY(_destroy)(struct RB_ENTRY(node) *);
|
|
|
|
|
+static void USHARE_RB_ENTRY(_destroy)(struct USHARE_RB_ENTRY(node) *);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef no_delete
|
|
|
|
|
-static void RB_ENTRY(_delete)(struct RB_ENTRY(node) **, struct RB_ENTRY(node) *);
|
|
|
|
|
-static void RB_ENTRY(_delete_fix)(struct RB_ENTRY(node) **, struct RB_ENTRY(node) *);
|
|
|
|
|
+static void USHARE_RB_ENTRY(_delete)(struct USHARE_RB_ENTRY(node) **, struct USHARE_RB_ENTRY(node) *);
|
|
|
|
|
+static void USHARE_RB_ENTRY(_delete_fix)(struct USHARE_RB_ENTRY(node) **, struct USHARE_RB_ENTRY(node) *);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef no_walk
|
|
|
|
|
-static void RB_ENTRY(_walk)(const struct RB_ENTRY(node) *, void (*)(const RB_ENTRY(data_t) *, const VISIT, const int, void *), void *, int);
|
|
|
|
|
+static void USHARE_RB_ENTRY(_walk)(const struct USHARE_RB_ENTRY(node) *, void (*)(const USHARE_RB_ENTRY(data_t) *, const VISIT, const int, void *), void *, int);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef no_readlist
|
|
|
|
|
-static RBLIST *RB_ENTRY(_openlist)(const struct RB_ENTRY(node) *);
|
|
|
|
|
-static const RB_ENTRY(data_t) * RB_ENTRY(_readlist)(RBLIST *);
|
|
|
|
|
-static void RB_ENTRY(_closelist)(RBLIST *);
|
|
|
|
|
+static RBLIST *USHARE_RB_ENTRY(_openlist)(const struct USHARE_RB_ENTRY(node) *);
|
|
|
|
|
+static const USHARE_RB_ENTRY(data_t) * USHARE_RB_ENTRY(_readlist)(RBLIST *);
|
|
|
|
|
+static void USHARE_RB_ENTRY(_closelist)(RBLIST *);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
@@ -133,18 +133,18 @@ static void RB_ENTRY(_closelist)(RBLIST *);
|
|
|
|
|
* Returns a pointer to the top of the tree.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef RB_CUSTOMIZE
|
|
|
|
|
-RB_STATIC struct RB_ENTRY(tree) *
|
|
|
|
|
+RB_STATIC struct USHARE_RB_ENTRY(tree) *
|
|
|
|
|
rbinit(int (*cmp)(const void *, const void *, const void *), const void *config)
|
|
|
|
|
#else
|
|
|
|
|
-RB_STATIC struct RB_ENTRY(tree) *RB_ENTRY(init)(void)
|
|
|
|
|
+RB_STATIC struct USHARE_RB_ENTRY(tree) *USHARE_RB_ENTRY(init)(void)
|
|
|
|
|
#endif /* RB_CUSTOMIZE */
|
|
|
|
|
{
|
|
|
|
|
- struct RB_ENTRY(tree) *retval;
|
|
|
|
|
+ struct USHARE_RB_ENTRY(tree) *retval;
|
|
|
|
|
char c;
|
|
|
|
|
|
|
|
|
|
c=rcsid[0]; /* This does nothing but shutup the -Wall */
|
|
|
|
|
|
|
|
|
|
- if ((retval=(struct RB_ENTRY(tree) *) malloc(sizeof(struct RB_ENTRY(tree))))==NULL)
|
|
|
|
|
+ if ((retval=(struct USHARE_RB_ENTRY(tree) *) malloc(sizeof(struct USHARE_RB_ENTRY(tree))))==NULL)
|
|
|
|
|
return(NULL);
|
|
|
|
|
|
|
|
|
|
#ifndef RB_CUSTOMIZE
|
|
|
|
|
@@ -158,38 +158,38 @@ RB_STATIC struct RB_ENTRY(tree) *RB_ENTRY(init)(void)
|
|
|
|
|
|
|
|
|
|
#ifndef no_destroy
|
|
|
|
|
RB_STATIC void
|
|
|
|
|
-RB_ENTRY(destroy)(struct RB_ENTRY(tree) *rbinfo)
|
|
|
|
|
+USHARE_RB_ENTRY(destroy)(struct USHARE_RB_ENTRY(tree) *rbinfo)
|
|
|
|
|
{
|
|
|
|
|
if (rbinfo==NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (rbinfo->rb_root!=RBNULL)
|
|
|
|
|
- RB_ENTRY(_destroy)(rbinfo->rb_root);
|
|
|
|
|
+ USHARE_RB_ENTRY(_destroy)(rbinfo->rb_root);
|
|
|
|
|
|
|
|
|
|
free(rbinfo);
|
|
|
|
|
}
|
|
|
|
|
#endif /* no_destroy */
|
|
|
|
|
|
|
|
|
|
#ifndef no_search
|
|
|
|
|
-RB_STATIC const RB_ENTRY(data_t) *
|
|
|
|
|
-RB_ENTRY(search)(const RB_ENTRY(data_t) *key, struct RB_ENTRY(tree) *rbinfo)
|
|
|
|
|
+RB_STATIC const USHARE_RB_ENTRY(data_t) *
|
|
|
|
|
+USHARE_RB_ENTRY(search)(const USHARE_RB_ENTRY(data_t) *key, struct USHARE_RB_ENTRY(tree) *rbinfo)
|
|
|
|
|
{
|
|
|
|
|
- struct RB_ENTRY(node) *x;
|
|
|
|
|
+ struct USHARE_RB_ENTRY(node) *x;
|
|
|
|
|
|
|
|
|
|
if (rbinfo==NULL)
|
|
|
|
|
return(NULL);
|
|
|
|
|
|
|
|
|
|
- x=RB_ENTRY(_traverse)(1, key, rbinfo);
|
|
|
|
|
+ x=USHARE_RB_ENTRY(_traverse)(1, key, rbinfo);
|
|
|
|
|
|
|
|
|
|
return((x==RBNULL) ? NULL : RB_GET(x, key));
|
|
|
|
|
}
|
|
|
|
|
#endif /* no_search */
|
|
|
|
|
|
|
|
|
|
#ifndef no_find
|
|
|
|
|
-RB_STATIC const RB_ENTRY(data_t) *
|
|
|
|
|
-RB_ENTRY(find)(const RB_ENTRY(data_t) *key, struct RB_ENTRY(tree) *rbinfo)
|
|
|
|
|
+RB_STATIC const USHARE_RB_ENTRY(data_t) *
|
|
|
|
|
+USHARE_RB_ENTRY(find)(const USHARE_RB_ENTRY(data_t) *key, struct USHARE_RB_ENTRY(tree) *rbinfo)
|
|
|
|
|
{
|
|
|
|
|
- struct RB_ENTRY(node) *x;
|
|
|
|
|
+ struct USHARE_RB_ENTRY(node) *x;
|
|
|
|
|
|
|
|
|
|
if (rbinfo==NULL)
|
|
|
|
|
return(NULL);
|
|
|
|
|
@@ -198,23 +198,23 @@ RB_ENTRY(find)(const RB_ENTRY(data_t) *key, struct RB_
|
|
|
|
|
if (rbinfo->rb_root==RBNULL)
|
|
|
|
|
return(NULL);
|
|
|
|
|
|
|
|
|
|
- x=RB_ENTRY(_traverse)(0, key, rbinfo);
|
|
|
|
|
+ x=USHARE_RB_ENTRY(_traverse)(0, key, rbinfo);
|
|
|
|
|
|
|
|
|
|
return((x==RBNULL) ? NULL : RB_GET(x, key));
|
|
|
|
|
}
|
|
|
|
|
#endif /* no_find */
|
|
|
|
|
|
|
|
|
|
#ifndef no_delete
|
|
|
|
|
-RB_STATIC const RB_ENTRY(data_t) *
|
|
|
|
|
-RB_ENTRY(delete)(const RB_ENTRY(data_t) *key, struct RB_ENTRY(tree) *rbinfo)
|
|
|
|
|
+RB_STATIC const USHARE_RB_ENTRY(data_t) *
|
|
|
|
|
+USHARE_RB_ENTRY(delete)(const USHARE_RB_ENTRY(data_t) *key, struct USHARE_RB_ENTRY(tree) *rbinfo)
|
|
|
|
|
{
|
|
|
|
|
- struct RB_ENTRY(node) *x;
|
|
|
|
|
- const RB_ENTRY(data_t) * y;
|
|
|
|
|
+ struct USHARE_RB_ENTRY(node) *x;
|
|
|
|
|
+ const USHARE_RB_ENTRY(data_t) * y;
|
|
|
|
|
|
|
|
|
|
if (rbinfo==NULL)
|
|
|
|
|
return(NULL);
|
|
|
|
|
|
|
|
|
|
- x=RB_ENTRY(_traverse)(0, key, rbinfo);
|
|
|
|
|
+ x=USHARE_RB_ENTRY(_traverse)(0, key, rbinfo);
|
|
|
|
|
|
|
|
|
|
if (x==RBNULL)
|
|
|
|
|
{
|
|
|
|
|
@@ -223,7 +223,7 @@ RB_ENTRY(delete)(const RB_ENTRY(data_t) *key, struct R
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
y=RB_GET(x, key);
|
|
|
|
|
- RB_ENTRY(_delete)(&rbinfo->rb_root, x);
|
|
|
|
|
+ USHARE_RB_ENTRY(_delete)(&rbinfo->rb_root, x);
|
|
|
|
|
|
|
|
|
|
return(y);
|
|
|
|
|
}
|
|
|
|
|
@@ -232,55 +232,55 @@ RB_ENTRY(delete)(const RB_ENTRY(data_t) *key, struct R
|
|
|
|
|
|
|
|
|
|
#ifndef no_walk
|
|
|
|
|
RB_STATIC void
|
|
|
|
|
-RB_ENTRY(walk)(const struct RB_ENTRY(tree) *rbinfo, void (*action)(const RB_ENTRY(data_t) *, const VISIT, const int, void *), void *arg)
|
|
|
|
|
+USHARE_RB_ENTRY(walk)(const struct USHARE_RB_ENTRY(tree) *rbinfo, void (*action)(const USHARE_RB_ENTRY(data_t) *, const VISIT, const int, void *), void *arg)
|
|
|
|
|
{
|
|
|
|
|
if (rbinfo==NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
- RB_ENTRY(_walk)(rbinfo->rb_root, action, arg, 0);
|
|
|
|
|
+ USHARE_RB_ENTRY(_walk)(rbinfo->rb_root, action, arg, 0);
|
|
|
|
|
}
|
|
|
|
|
#endif /* no_walk */
|
|
|
|
|
|
|
|
|
|
#ifndef no_readlist
|
|
|
|
|
RB_STATIC RBLIST *
|
|
|
|
|
-RB_ENTRY(openlist)(const struct RB_ENTRY(tree) *rbinfo)
|
|
|
|
|
+USHARE_RB_ENTRY(openlist)(const struct USHARE_RB_ENTRY(tree) *rbinfo)
|
|
|
|
|
{
|
|
|
|
|
if (rbinfo==NULL)
|
|
|
|
|
return(NULL);
|
|
|
|
|
|
|
|
|
|
- return(RB_ENTRY(_openlist)(rbinfo->rb_root));
|
|
|
|
|
+ return(USHARE_RB_ENTRY(_openlist)(rbinfo->rb_root));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-RB_STATIC const RB_ENTRY(data_t) *
|
|
|
|
|
-RB_ENTRY(readlist)(RBLIST *rblistp)
|
|
|
|
|
+RB_STATIC const USHARE_RB_ENTRY(data_t) *
|
|
|
|
|
+USHARE_RB_ENTRY(readlist)(RBLIST *rblistp)
|
|
|
|
|
{
|
|
|
|
|
if (rblistp==NULL)
|
|
|
|
|
return(NULL);
|
|
|
|
|
|
|
|
|
|
- return(RB_ENTRY(_readlist)(rblistp));
|
|
|
|
|
+ return(USHARE_RB_ENTRY(_readlist)(rblistp));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RB_STATIC void
|
|
|
|
|
-RB_ENTRY(closelist)(RBLIST *rblistp)
|
|
|
|
|
+USHARE_RB_ENTRY(closelist)(RBLIST *rblistp)
|
|
|
|
|
{
|
|
|
|
|
if (rblistp==NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
- RB_ENTRY(_closelist)(rblistp);
|
|
|
|
|
+ USHARE_RB_ENTRY(_closelist)(rblistp);
|
|
|
|
|
}
|
|
|
|
|
#endif /* no_readlist */
|
|
|
|
|
|
|
|
|
|
#ifndef no_lookup
|
|
|
|
|
-RB_STATIC const RB_ENTRY(data_t) *
|
|
|
|
|
-RB_ENTRY(lookup)(int mode, const RB_ENTRY(data_t) *key, struct RB_ENTRY(tree) *rbinfo)
|
|
|
|
|
+RB_STATIC const USHARE_RB_ENTRY(data_t) *
|
|
|
|
|
+USHARE_RB_ENTRY(lookup)(int mode, const USHARE_RB_ENTRY(data_t) *key, struct USHARE_RB_ENTRY(tree) *rbinfo)
|
|
|
|
|
{
|
|
|
|
|
- struct RB_ENTRY(node) *x;
|
|
|
|
|
+ struct USHARE_RB_ENTRY(node) *x;
|
|
|
|
|
|
|
|
|
|
/* If we have a NULL root (empty tree) then just return NULL */
|
|
|
|
|
if (rbinfo==NULL || rbinfo->rb_root==NULL)
|
|
|
|
|
return(NULL);
|
|
|
|
|
|
|
|
|
|
- x=RB_ENTRY(_lookup)(mode, key, rbinfo);
|
|
|
|
|
+ x=USHARE_RB_ENTRY(_lookup)(mode, key, rbinfo);
|
|
|
|
|
|
|
|
|
|
return((x==RBNULL) ? NULL : RB_GET(x, key));
|
|
|
|
|
}
|
|
|
|
|
@@ -291,10 +291,10 @@ RB_ENTRY(lookup)(int mode, const RB_ENTRY(data_t) *key
|
|
|
|
|
/* Search for and if not found and insert is true, will add a new
|
|
|
|
|
** node in. Returns a pointer to the new node, or the node found
|
|
|
|
|
*/
|
|
|
|
|
-static struct RB_ENTRY(node) *
|
|
|
|
|
-RB_ENTRY(_traverse)(int insert, const RB_ENTRY(data_t) *key, struct RB_ENTRY(tree) *rbinfo)
|
|
|
|
|
+static struct USHARE_RB_ENTRY(node) *
|
|
|
|
|
+USHARE_RB_ENTRY(_traverse)(int insert, const USHARE_RB_ENTRY(data_t) *key, struct USHARE_RB_ENTRY(tree) *rbinfo)
|
|
|
|
|
{
|
|
|
|
|
- struct RB_ENTRY(node) *x,*y,*z;
|
|
|
|
|
+ struct USHARE_RB_ENTRY(node) *x,*y,*z;
|
|
|
|
|
int cmp;
|
|
|
|
|
int found=0;
|
|
|
|
|
int cmpmods();
|
|
|
|
|
@@ -324,13 +324,13 @@ RB_ENTRY(_traverse)(int insert, const RB_ENTRY(data_t)
|
|
|
|
|
if (found || !insert)
|
|
|
|
|
return(x);
|
|
|
|
|
|
|
|
|
|
- if ((z=RB_ENTRY(_alloc)())==NULL)
|
|
|
|
|
+ if ((z=USHARE_RB_ENTRY(_alloc)())==NULL)
|
|
|
|
|
{
|
|
|
|
|
/* Whoops, no memory */
|
|
|
|
|
return(RBNULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- RB_SET(z, key, key);
|
|
|
|
|
+ USHARE_RB_SET(z, key, key);
|
|
|
|
|
z->up=y;
|
|
|
|
|
if (y==RBNULL)
|
|
|
|
|
{
|
|
|
|
|
@@ -391,7 +391,7 @@ RB_ENTRY(_traverse)(int insert, const RB_ENTRY(data_t)
|
|
|
|
|
{
|
|
|
|
|
/* Move up to our parent */
|
|
|
|
|
x=x->up;
|
|
|
|
|
- RB_ENTRY(_left_rotate)(&rbinfo->rb_root, x);
|
|
|
|
|
+ USHARE_RB_ENTRY(_left_rotate)(&rbinfo->rb_root, x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* make our parent black */
|
|
|
|
|
@@ -399,7 +399,7 @@ RB_ENTRY(_traverse)(int insert, const RB_ENTRY(data_t)
|
|
|
|
|
/* make our grandparent red */
|
|
|
|
|
x->up->up->colour = RED;
|
|
|
|
|
/* right rotate our grandparent */
|
|
|
|
|
- RB_ENTRY(_right_rotate)(&rbinfo->rb_root, x->up->up);
|
|
|
|
|
+ USHARE_RB_ENTRY(_right_rotate)(&rbinfo->rb_root, x->up->up);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
@@ -422,12 +422,12 @@ RB_ENTRY(_traverse)(int insert, const RB_ENTRY(data_t)
|
|
|
|
|
if (x == x->up->left)
|
|
|
|
|
{
|
|
|
|
|
x=x->up;
|
|
|
|
|
- RB_ENTRY(_right_rotate)(&rbinfo->rb_root, x);
|
|
|
|
|
+ USHARE_RB_ENTRY(_right_rotate)(&rbinfo->rb_root, x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
x->up->colour = BLACK;
|
|
|
|
|
x->up->up->colour = RED;
|
|
|
|
|
- RB_ENTRY(_left_rotate)(&rbinfo->rb_root, x->up->up);
|
|
|
|
|
+ USHARE_RB_ENTRY(_left_rotate)(&rbinfo->rb_root, x->up->up);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -441,10 +441,10 @@ RB_ENTRY(_traverse)(int insert, const RB_ENTRY(data_t)
|
|
|
|
|
#ifndef no_lookup
|
|
|
|
|
/* Search for a key according to mode (see redblack.h)
|
|
|
|
|
*/
|
|
|
|
|
-static struct RB_ENTRY(node) *
|
|
|
|
|
-RB_ENTRY(_lookup)(int mode, const RB_ENTRY(data_t) *key, struct RB_ENTRY(tree) *rbinfo)
|
|
|
|
|
+static struct USHARE_RB_ENTRY(node) *
|
|
|
|
|
+USHARE_RB_ENTRY(_lookup)(int mode, const USHARE_RB_ENTRY(data_t) *key, struct USHARE_RB_ENTRY(tree) *rbinfo)
|
|
|
|
|
{
|
|
|
|
|
- struct RB_ENTRY(node) *x,*y;
|
|
|
|
|
+ struct USHARE_RB_ENTRY(node) *x,*y;
|
|
|
|
|
int cmp=0;
|
|
|
|
|
int found=0;
|
|
|
|
|
|
|
|
|
|
@@ -503,7 +503,7 @@ RB_ENTRY(_lookup)(int mode, const RB_ENTRY(data_t) *ke
|
|
|
|
|
if (mode==RB_LUGTEQ || (!found && mode==RB_LUGREAT))
|
|
|
|
|
{
|
|
|
|
|
if (cmp>0)
|
|
|
|
|
- return(RB_ENTRY(_successor)(y));
|
|
|
|
|
+ return(USHARE_RB_ENTRY(_successor)(y));
|
|
|
|
|
else
|
|
|
|
|
return(y);
|
|
|
|
|
}
|
|
|
|
|
@@ -511,16 +511,16 @@ RB_ENTRY(_lookup)(int mode, const RB_ENTRY(data_t) *ke
|
|
|
|
|
if (mode==RB_LULTEQ || (!found && mode==RB_LULESS))
|
|
|
|
|
{
|
|
|
|
|
if (cmp<0)
|
|
|
|
|
- return(RB_ENTRY(_predecessor)(y));
|
|
|
|
|
+ return(USHARE_RB_ENTRY(_predecessor)(y));
|
|
|
|
|
else
|
|
|
|
|
return(y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mode==RB_LUNEXT || (found && mode==RB_LUGREAT))
|
|
|
|
|
- return(RB_ENTRY(_successor)(x));
|
|
|
|
|
+ return(USHARE_RB_ENTRY(_successor)(x));
|
|
|
|
|
|
|
|
|
|
if (mode==RB_LUPREV || (found && mode==RB_LULESS))
|
|
|
|
|
- return(RB_ENTRY(_predecessor)(x));
|
|
|
|
|
+ return(USHARE_RB_ENTRY(_predecessor)(x));
|
|
|
|
|
|
|
|
|
|
/* Shouldn't get here */
|
|
|
|
|
return(RBNULL);
|
|
|
|
|
@@ -533,15 +533,15 @@ RB_ENTRY(_lookup)(int mode, const RB_ENTRY(data_t) *ke
|
|
|
|
|
* only useful as part of a complete tree destroy.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
-RB_ENTRY(_destroy)(struct RB_ENTRY(node) *x)
|
|
|
|
|
+USHARE_RB_ENTRY(_destroy)(struct USHARE_RB_ENTRY(node) *x)
|
|
|
|
|
{
|
|
|
|
|
if (x!=RBNULL)
|
|
|
|
|
{
|
|
|
|
|
if (x->left!=RBNULL)
|
|
|
|
|
- RB_ENTRY(_destroy)(x->left);
|
|
|
|
|
+ USHARE_RB_ENTRY(_destroy)(x->left);
|
|
|
|
|
if (x->right!=RBNULL)
|
|
|
|
|
- RB_ENTRY(_destroy)(x->right);
|
|
|
|
|
- RB_ENTRY(_free)(x);
|
|
|
|
|
+ USHARE_RB_ENTRY(_destroy)(x->right);
|
|
|
|
|
+ USHARE_RB_ENTRY(_free)(x);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /* no_destroy */
|
|
|
|
|
@@ -561,9 +561,9 @@ RB_ENTRY(_destroy)(struct RB_ENTRY(node) *x)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
-RB_ENTRY(_left_rotate)(struct RB_ENTRY(node) **rootp, struct RB_ENTRY(node) *x)
|
|
|
|
|
+USHARE_RB_ENTRY(_left_rotate)(struct USHARE_RB_ENTRY(node) **rootp, struct USHARE_RB_ENTRY(node) *x)
|
|
|
|
|
{
|
|
|
|
|
- struct RB_ENTRY(node) *y;
|
|
|
|
|
+ struct USHARE_RB_ENTRY(node) *y;
|
|
|
|
|
|
|
|
|
|
assert(x!=RBNULL);
|
|
|
|
|
assert(x->right!=RBNULL);
|
|
|
|
|
@@ -606,9 +606,9 @@ RB_ENTRY(_left_rotate)(struct RB_ENTRY(node) **rootp,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
-RB_ENTRY(_right_rotate)(struct RB_ENTRY(node) **rootp, struct RB_ENTRY(node) *y)
|
|
|
|
|
+USHARE_RB_ENTRY(_right_rotate)(struct USHARE_RB_ENTRY(node) **rootp, struct USHARE_RB_ENTRY(node) *y)
|
|
|
|
|
{
|
|
|
|
|
- struct RB_ENTRY(node) *x;
|
|
|
|
|
+ struct USHARE_RB_ENTRY(node) *x;
|
|
|
|
|
|
|
|
|
|
assert(y!=RBNULL);
|
|
|
|
|
assert(y->left!=RBNULL);
|
|
|
|
|
@@ -652,10 +652,10 @@ RB_ENTRY(_right_rotate)(struct RB_ENTRY(node) **rootp,
|
|
|
|
|
|
|
|
|
|
/* Return a pointer to the smallest key greater than x
|
|
|
|
|
*/
|
|
|
|
|
-static struct RB_ENTRY(node) *
|
|
|
|
|
-RB_ENTRY(_successor)(const struct RB_ENTRY(node) *x)
|
|
|
|
|
+static struct USHARE_RB_ENTRY(node) *
|
|
|
|
|
+USHARE_RB_ENTRY(_successor)(const struct USHARE_RB_ENTRY(node) *x)
|
|
|
|
|
{
|
|
|
|
|
- struct RB_ENTRY(node) *y;
|
|
|
|
|
+ struct USHARE_RB_ENTRY(node) *y;
|
|
|
|
|
|
|
|
|
|
if (x->right!=RBNULL)
|
|
|
|
|
{
|
|
|
|
|
@@ -683,10 +683,10 @@ RB_ENTRY(_successor)(const struct RB_ENTRY(node) *x)
|
|
|
|
|
|
|
|
|
|
/* Return a pointer to the largest key smaller than x
|
|
|
|
|
*/
|
|
|
|
|
-static struct RB_ENTRY(node) *
|
|
|
|
|
-RB_ENTRY(_predecessor)(const struct RB_ENTRY(node) *x)
|
|
|
|
|
+static struct USHARE_RB_ENTRY(node) *
|
|
|
|
|
+USHARE_RB_ENTRY(_predecessor)(const struct USHARE_RB_ENTRY(node) *x)
|
|
|
|
|
{
|
|
|
|
|
- struct RB_ENTRY(node) *y;
|
|
|
|
|
+ struct USHARE_RB_ENTRY(node) *y;
|
|
|
|
|
|
|
|
|
|
if (x->left!=RBNULL)
|
|
|
|
|
{
|
|
|
|
|
@@ -716,14 +716,14 @@ RB_ENTRY(_predecessor)(const struct RB_ENTRY(node) *x)
|
|
|
|
|
/* Delete the node z, and free up the space
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
-RB_ENTRY(_delete)(struct RB_ENTRY(node) **rootp, struct RB_ENTRY(node) *z)
|
|
|
|
|
+USHARE_RB_ENTRY(_delete)(struct USHARE_RB_ENTRY(node) **rootp, struct USHARE_RB_ENTRY(node) *z)
|
|
|
|
|
{
|
|
|
|
|
- struct RB_ENTRY(node) *x, *y;
|
|
|
|
|
+ struct USHARE_RB_ENTRY(node) *x, *y;
|
|
|
|
|
|
|
|
|
|
if (z->left == RBNULL || z->right == RBNULL)
|
|
|
|
|
y=z;
|
|
|
|
|
else
|
|
|
|
|
- y=RB_ENTRY(_successor)(z);
|
|
|
|
|
+ y=USHARE_RB_ENTRY(_successor)(z);
|
|
|
|
|
|
|
|
|
|
if (y->left != RBNULL)
|
|
|
|
|
x=y->left;
|
|
|
|
|
@@ -746,20 +746,20 @@ RB_ENTRY(_delete)(struct RB_ENTRY(node) **rootp, struc
|
|
|
|
|
|
|
|
|
|
if (y!=z)
|
|
|
|
|
{
|
|
|
|
|
- RB_SET(z, key, RB_GET(y, key));
|
|
|
|
|
+ USHARE_RB_SET(z, key, RB_GET(y, key));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (y->colour == BLACK)
|
|
|
|
|
- RB_ENTRY(_delete_fix)(rootp, x);
|
|
|
|
|
+ USHARE_RB_ENTRY(_delete_fix)(rootp, x);
|
|
|
|
|
|
|
|
|
|
- RB_ENTRY(_free)(y);
|
|
|
|
|
+ USHARE_RB_ENTRY(_free)(y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Restore the reb-black properties after a delete */
|
|
|
|
|
static void
|
|
|
|
|
-RB_ENTRY(_delete_fix)(struct RB_ENTRY(node) **rootp, struct RB_ENTRY(node) *x)
|
|
|
|
|
+USHARE_RB_ENTRY(_delete_fix)(struct USHARE_RB_ENTRY(node) **rootp, struct USHARE_RB_ENTRY(node) *x)
|
|
|
|
|
{
|
|
|
|
|
- struct RB_ENTRY(node) *w;
|
|
|
|
|
+ struct USHARE_RB_ENTRY(node) *w;
|
|
|
|
|
|
|
|
|
|
while (x!=*rootp && x->colour==BLACK)
|
|
|
|
|
{
|
|
|
|
|
@@ -785,7 +785,7 @@ RB_ENTRY(_delete_fix)(struct RB_ENTRY(node) **rootp, s
|
|
|
|
|
{
|
|
|
|
|
w->left->colour=BLACK;
|
|
|
|
|
w->colour=RED;
|
|
|
|
|
- RB_ENTRY(_right_rotate)(rootp, w);
|
|
|
|
|
+ USHARE_RB_ENTRY(_right_rotate)(rootp, w);
|
|
|
|
|
w=x->up->right;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -793,7 +793,7 @@ RB_ENTRY(_delete_fix)(struct RB_ENTRY(node) **rootp, s
|
|
|
|
|
w->colour=x->up->colour;
|
|
|
|
|
x->up->colour = BLACK;
|
|
|
|
|
w->right->colour = BLACK;
|
|
|
|
|
- RB_ENTRY(_left_rotate)(rootp, x->up);
|
|
|
|
|
+ USHARE_RB_ENTRY(_left_rotate)(rootp, x->up);
|
|
|
|
|
x=*rootp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -804,7 +804,7 @@ RB_ENTRY(_delete_fix)(struct RB_ENTRY(node) **rootp, s
|
|
|
|
|
{
|
|
|
|
|
w->colour=BLACK;
|
|
|
|
|
x->up->colour=RED;
|
|
|
|
|
- RB_ENTRY(_right_rotate)(rootp, x->up);
|
|
|
|
|
+ USHARE_RB_ENTRY(_right_rotate)(rootp, x->up);
|
|
|
|
|
w=x->up->left;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -819,14 +819,14 @@ RB_ENTRY(_delete_fix)(struct RB_ENTRY(node) **rootp, s
|
|
|
|
|
{
|
|
|
|
|
w->right->colour=BLACK;
|
|
|
|
|
w->colour=RED;
|
|
|
|
|
- RB_ENTRY(_left_rotate)(rootp, w);
|
|
|
|
|
+ USHARE_RB_ENTRY(_left_rotate)(rootp, w);
|
|
|
|
|
w=x->up->left;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
w->colour=x->up->colour;
|
|
|
|
|
x->up->colour = BLACK;
|
|
|
|
|
w->left->colour = BLACK;
|
|
|
|
|
- RB_ENTRY(_right_rotate)(rootp, x->up);
|
|
|
|
|
+ USHARE_RB_ENTRY(_right_rotate)(rootp, x->up);
|
|
|
|
|
x=*rootp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -838,7 +838,7 @@ RB_ENTRY(_delete_fix)(struct RB_ENTRY(node) **rootp, s
|
|
|
|
|
|
|
|
|
|
#ifndef no_walk
|
|
|
|
|
static void
|
|
|
|
|
-RB_ENTRY(_walk)(const struct RB_ENTRY(node) *x, void (*action)(const RB_ENTRY(data_t) *, const VISIT, const int, void *), void *arg, int level)
|
|
|
|
|
+USHARE_RB_ENTRY(_walk)(const struct USHARE_RB_ENTRY(node) *x, void (*action)(const USHARE_RB_ENTRY(data_t) *, const VISIT, const int, void *), void *arg, int level)
|
|
|
|
|
{
|
|
|
|
|
if (x==RBNULL)
|
|
|
|
|
return;
|
|
|
|
|
@@ -852,11 +852,11 @@ RB_ENTRY(_walk)(const struct RB_ENTRY(node) *x, void (
|
|
|
|
|
{
|
|
|
|
|
(*action)(RB_GET(x, key), preorder, level, arg);
|
|
|
|
|
|
|
|
|
|
- RB_ENTRY(_walk)(x->left, action, arg, level+1);
|
|
|
|
|
+ USHARE_RB_ENTRY(_walk)(x->left, action, arg, level+1);
|
|
|
|
|
|
|
|
|
|
(*action)(RB_GET(x, key), postorder, level, arg);
|
|
|
|
|
|
|
|
|
|
- RB_ENTRY(_walk)(x->right, action, arg, level+1);
|
|
|
|
|
+ USHARE_RB_ENTRY(_walk)(x->right, action, arg, level+1);
|
|
|
|
|
|
|
|
|
|
(*action)(RB_GET(x, key), endorder, level, arg);
|
|
|
|
|
}
|
|
|
|
|
@@ -865,7 +865,7 @@ RB_ENTRY(_walk)(const struct RB_ENTRY(node) *x, void (
|
|
|
|
|
|
|
|
|
|
#ifndef no_readlist
|
|
|
|
|
static RBLIST *
|
|
|
|
|
-RB_ENTRY(_openlist)(const struct RB_ENTRY(node) *rootp)
|
|
|
|
|
+USHARE_RB_ENTRY(_openlist)(const struct USHARE_RB_ENTRY(node) *rootp)
|
|
|
|
|
{
|
|
|
|
|
RBLIST *rblistp;
|
|
|
|
|
|
|
|
|
|
@@ -887,15 +887,15 @@ RB_ENTRY(_openlist)(const struct RB_ENTRY(node) *rootp
|
|
|
|
|
return(rblistp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-static const RB_ENTRY(data_t) *
|
|
|
|
|
-RB_ENTRY(_readlist)(RBLIST *rblistp)
|
|
|
|
|
+static const USHARE_RB_ENTRY(data_t) *
|
|
|
|
|
+USHARE_RB_ENTRY(_readlist)(RBLIST *rblistp)
|
|
|
|
|
{
|
|
|
|
|
- const RB_ENTRY(data_t) *key=NULL;
|
|
|
|
|
+ const USHARE_RB_ENTRY(data_t) *key=NULL;
|
|
|
|
|
|
|
|
|
|
if (rblistp!=NULL && rblistp->nextp!=RBNULL)
|
|
|
|
|
{
|
|
|
|
|
key=RB_GET(rblistp->nextp, key);
|
|
|
|
|
- rblistp->nextp=RB_ENTRY(_successor)(rblistp->nextp);
|
|
|
|
|
+ rblistp->nextp=USHARE_RB_ENTRY(_successor)(rblistp->nextp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(key);
|
|
|
|
|
@@ -913,27 +913,27 @@ rb_closelist(RBLIST *rblistp)
|
|
|
|
|
/* Allocate space for our nodes, allowing us to get space from
|
|
|
|
|
** sbrk in larger chucks.
|
|
|
|
|
*/
|
|
|
|
|
-static struct RB_ENTRY(node) *rbfreep=NULL;
|
|
|
|
|
+static struct USHARE_RB_ENTRY(node) *rbfreep=NULL;
|
|
|
|
|
|
|
|
|
|
-#define RB_ENTRY(NODE)ALLOC_CHUNK_SIZE 1000
|
|
|
|
|
-static struct RB_ENTRY(node) *
|
|
|
|
|
-RB_ENTRY(_alloc)()
|
|
|
|
|
+#define USHARE_RB_ENTRY(NODE)ALLOC_CHUNK_SIZE 1000
|
|
|
|
|
+static struct USHARE_RB_ENTRY(node) *
|
|
|
|
|
+USHARE_RB_ENTRY(_alloc)()
|
|
|
|
|
{
|
|
|
|
|
- struct RB_ENTRY(node) *x;
|
|
|
|
|
+ struct USHARE_RB_ENTRY(node) *x;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (rbfreep==NULL)
|
|
|
|
|
{
|
|
|
|
|
/* must grab some more space */
|
|
|
|
|
- rbfreep=(struct RB_ENTRY(node) *) sbrk(sizeof(struct RB_ENTRY(node)) * RB_ENTRY(NODE)ALLOC_CHUNK_SIZE);
|
|
|
|
|
+ rbfreep=(struct USHARE_RB_ENTRY(node) *) sbrk(sizeof(struct USHARE_RB_ENTRY(node)) * USHARE_RB_ENTRY(NODE)ALLOC_CHUNK_SIZE);
|
|
|
|
|
|
|
|
|
|
- if (rbfreep==(struct RB_ENTRY(node) *) -1)
|
|
|
|
|
+ if (rbfreep==(struct USHARE_RB_ENTRY(node) *) -1)
|
|
|
|
|
{
|
|
|
|
|
return(NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* tie them together in a linked list (use the up pointer) */
|
|
|
|
|
- for (i=0, x=rbfreep; i<RB_ENTRY(NODE)ALLOC_CHUNK_SIZE-1; i++, x++)
|
|
|
|
|
+ for (i=0, x=rbfreep; i<USHARE_RB_ENTRY(NODE)ALLOC_CHUNK_SIZE-1; i++, x++)
|
|
|
|
|
{
|
|
|
|
|
x->up = (x+1);
|
|
|
|
|
}
|
|
|
|
|
@@ -952,7 +952,7 @@ RB_ENTRY(_alloc)()
|
|
|
|
|
** N.B. RB_ENTRY(node) need not have been allocated through rb_alloc()
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
-RB_ENTRY(_free)(struct RB_ENTRY(node) *x)
|
|
|
|
|
+USHARE_RB_ENTRY(_free)(struct USHARE_RB_ENTRY(node) *x)
|
|
|
|
|
{
|
|
|
|
|
#ifdef RB_FREE
|
|
|
|
|
RB_FREE(ACCESS(x, key));
|
|
|
|
|
@@ -965,7 +965,7 @@ RB_ENTRY(_free)(struct RB_ENTRY(node) *x)
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
int
|
|
|
|
|
-RB_ENTRY(_check)(struct RB_ENTRY(node) *rootp)
|
|
|
|
|
+USHARE_RB_ENTRY(_check)(struct USHARE_RB_ENTRY(node) *rootp)
|
|
|
|
|
{
|
|
|
|
|
if (rootp==NULL || rootp==RBNULL)
|
|
|
|
|
return(0);
|
|
|
|
|
@@ -977,15 +977,15 @@ RB_ENTRY(_check)(struct RB_ENTRY(node) *rootp)
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- if (RB_ENTRY(_check)1(rootp))
|
|
|
|
|
+ if (USHARE_RB_ENTRY(_check)1(rootp))
|
|
|
|
|
{
|
|
|
|
|
- RB_ENTRY(dumptree)(rootp, 0);
|
|
|
|
|
+ USHARE_RB_ENTRY(dumptree)(rootp, 0);
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- if (RB_ENTRY(count_black)(rootp)==-1)
|
|
|
|
|
+ if (USHARE_RB_ENTRY(count_black)(rootp)==-1)
|
|
|
|
|
{
|
|
|
|
|
- RB_ENTRY(dumptree)(rootp, 0);
|
|
|
|
|
+ USHARE_RB_ENTRY(dumptree)(rootp, 0);
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -993,7 +993,7 @@ RB_ENTRY(_check)(struct RB_ENTRY(node) *rootp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
-RB_ENTRY(_check1)(struct RB_ENTRY(node) *x)
|
|
|
|
|
+USHARE_RB_ENTRY(_check1)(struct USHARE_RB_ENTRY(node) *x)
|
|
|
|
|
{
|
|
|
|
|
if (x->left==NULL || x->right==NULL)
|
|
|
|
|
{
|
|
|
|
|
@@ -1036,15 +1036,15 @@ RB_ENTRY(_check1)(struct RB_ENTRY(node) *x)
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-RB_ENTRY(count_black)(struct RB_ENTRY(node) *x)
|
|
|
|
|
+USHARE_RB_ENTRY(count_black)(struct USHARE_RB_ENTRY(node) *x)
|
|
|
|
|
{
|
|
|
|
|
int nleft, nright;
|
|
|
|
|
|
|
|
|
|
if (x==RBNULL)
|
|
|
|
|
return(1);
|
|
|
|
|
|
|
|
|
|
- nleft=RB_ENTRY(count_black)(x->left);
|
|
|
|
|
- nright=RB_ENTRY(count_black)(x->right);
|
|
|
|
|
+ nleft=USHARE_RB_ENTRY(count_black)(x->left);
|
|
|
|
|
+ nright=USHARE_RB_ENTRY(count_black)(x->right);
|
|
|
|
|
|
|
|
|
|
if (nleft==-1 || nright==-1)
|
|
|
|
|
return(-1);
|
|
|
|
|
@@ -1063,7 +1063,7 @@ RB_ENTRY(count_black)(struct RB_ENTRY(node) *x)
|
|
|
|
|
return(nleft);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-RB_ENTRY(dumptree)(struct RB_ENTRY(node) *x, int n)
|
|
|
|
|
+USHARE_RB_ENTRY(dumptree)(struct USHARE_RB_ENTRY(node) *x, int n)
|
|
|
|
|
{
|
|
|
|
|
char *prkey();
|
|
|
|
|
|
|
|
|
|
@@ -1079,8 +1079,8 @@ RB_ENTRY(dumptree)(struct RB_ENTRY(node) *x, int n)
|
|
|
|
|
(x->colour==BLACK) ? "BLACK" : "RED",
|
|
|
|
|
prkey(RB_GET(x, key)));
|
|
|
|
|
|
|
|
|
|
- RB_ENTRY(dumptree)(x->left, n);
|
|
|
|
|
- RB_ENTRY(dumptree)(x->right, n);
|
|
|
|
|
+ USHARE_RB_ENTRY(dumptree)(x->left, n);
|
|
|
|
|
+ USHARE_RB_ENTRY(dumptree)(x->right, n);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|