rbtree.c: make rbnode an ADT.
This commit is contained in:
parent
41a253a00a
commit
e7ebbd30ec
3 changed files with 15 additions and 39 deletions
10
src/rbtree.c
10
src/rbtree.c
|
|
@ -19,6 +19,16 @@
|
|||
#include "xalloc.h"
|
||||
#include "rbtree.h"
|
||||
|
||||
#define RB_RED 0
|
||||
#define RB_BLACK 1
|
||||
|
||||
/* node definition */
|
||||
typedef struct _rbn {
|
||||
const void *key;
|
||||
struct _rbn *child[2];
|
||||
unsigned char color;
|
||||
} rbnode;
|
||||
|
||||
#define is_red(n) ((n) != NULL && (n)->color == RB_RED)
|
||||
#define swap(n,d,q) ((n)->child[(n)->child[d] == (q)])
|
||||
|
||||
|
|
|
|||
12
src/rbtree.h
12
src/rbtree.h
|
|
@ -11,20 +11,10 @@
|
|||
#ifndef __RBTREE_H
|
||||
#define __RBTREE_H
|
||||
|
||||
#define RB_RED 0
|
||||
#define RB_BLACK 1
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/* node definition */
|
||||
typedef struct _rbn {
|
||||
const void *key;
|
||||
struct _rbn *child[2];
|
||||
unsigned char color;
|
||||
} rbnode;
|
||||
|
||||
typedef struct {
|
||||
rbnode *root;
|
||||
struct _rbn *root;
|
||||
/* user defined operations */
|
||||
void (*delete_fn)(void *);
|
||||
void (*update_fn)(void *, void *);
|
||||
|
|
|
|||
Reference in a new issue