Commit 9df01daa authored by Bob Halley's avatar Bob Halley
Browse files

update

parent 6a632f69
......@@ -4,8 +4,10 @@
* file is used as a template.
*/
#include <isc/result.h>
typedef struct RBT_NODE *RBT_NODE_T;
void RBT_INSERT(RBT_NODE_T, RBT_NODE_T *);
RBT_NODE_T RBT_SEARCH(RBT_NODE_T, RBT_KEY_T);
void RBT_PRINT(RBT_NODE_T);
RBT_LINKAGE isc_result_t RBT_INSERT(RBT_NODE_T, RBT_NODE_T *);
RBT_LINKAGE RBT_NODE_T RBT_SEARCH(RBT_NODE_T, RBT_KEY_T);
RBT_LINKAGE void RBT_PRINT(RBT_NODE_T);
......@@ -79,24 +79,7 @@ rotate_right(RBT_NODE_T node, RBT_NODE_T parent, RBT_NODE_T *rootp) {
*rootp = child;
}
RBT_NODE_T
RBT_SEARCH(RBT_NODE_T current, RBT_KEY_T key) {
int i;
while (current != NULL) {
i = COMPARE_KEYS(key, KEY(current));
if (i == 0)
break;
if (i < 0)
current = LEFT(current);
else
current = RIGHT(current);
}
return (current);
}
void
isc_result_t
RBT_INSERT(RBT_NODE_T node, RBT_NODE_T *rootp) {
RBT_NODE_T current, child, root, parent, grandparent, tmp;
int i;
......@@ -110,7 +93,7 @@ RBT_INSERT(RBT_NODE_T node, RBT_NODE_T *rootp) {
if (root == NULL) {
MAKE_BLACK(node);
*rootp = node;
return;
return (ISC_R_SUCCESS);
}
current = NULL;
......@@ -121,7 +104,8 @@ RBT_INSERT(RBT_NODE_T node, RBT_NODE_T *rootp) {
depth++;
current = child;
i = COMPARE_KEYS(KEY(node), KEY(current));
INSIST(i != 0);
if (i == 0)
return (ISC_R_EXISTS);
if (i < 0)
child = LEFT(current);
else
......@@ -200,6 +184,25 @@ RBT_INSERT(RBT_NODE_T node, RBT_NODE_T *rootp) {
MAKE_BLACK(root);
*rootp = root;
return (ISC_R_SUCCESS);
}
RBT_NODE_T
RBT_SEARCH(RBT_NODE_T current, RBT_KEY_T key) {
int i;
while (current != NULL) {
i = COMPARE_KEYS(key, KEY(current));
if (i == 0)
break;
if (i < 0)
current = LEFT(current);
else
current = RIGHT(current);
}
return (current);
}
static inline void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment