projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
- Check for NULL tree->delete callback
[tinc]
/
lib
/
rbl.c
diff --git
a/lib/rbl.c
b/lib/rbl.c
index
d79c503
..
c5114ef
100644
(file)
--- a/
lib/rbl.c
+++ b/
lib/rbl.c
@@
-17,12
+17,16
@@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: rbl.c,v 1.1.2.
6 2000/11/19 11:05
:59 guus Exp $
+ $Id: rbl.c,v 1.1.2.
9 2000/11/21 09:13
:59 guus Exp $
*/
*/
+#include "config.h"
+
+#include <stdlib.h>
#include <xalloc.h>
#include "rbl.h"
#include <xalloc.h>
#include "rbl.h"
+#include <system.h>
/* Allocate a new rbl node */
rbl_t *new_rbl()
/* Allocate a new rbl node */
rbl_t *new_rbl()
@@
-33,6
+37,8
@@
rbl_t *new_rbl()
/* Free a rbl node */
void free_rbl(rbl_t *rbl)
{
/* Free a rbl node */
void free_rbl(rbl_t *rbl)
{
+ if(rbl->data && rbl->tree->delete)
+ rbl->tree->delete(rbl->data);
free(rbl);
}
free(rbl);
}
@@
-58,7
+64,7
@@
void free_rbltree(rbltree_t *tree)
}
/* Search closest match in the tree */
}
/* Search closest match in the tree */
-rbl_t *rbl_search_closest(rbltree_t *tree, void *data)
+rbl_t *rbl_search_closest
_rbl
(rbltree_t *tree, void *data)
{
rbl_t *rbl, *next;
int result;
{
rbl_t *rbl, *next;
int result;
@@
-82,8
+88,13
@@
rbl_t *rbl_search_closest(rbltree_t *tree, void *data)
return rbl;
}
return rbl;
}
+void *rbl_search_closest(rbltree_t *tree, void *data)
+{
+ return rbl_search_closest_rbl(tree, data)->data;
+}
+
/* Search exact match or return NULL pointer */
/* Search exact match or return NULL pointer */
-rbl_t *rbl_search(rbltree_t *tree, void *data)
+rbl_t *rbl_search
_rbl
(rbltree_t *tree, void *data)
{
rbl_t *rbl, *next;
int result;
{
rbl_t *rbl, *next;
int result;
@@
-107,6
+118,18
@@
rbl_t *rbl_search(rbltree_t *tree, void *data)
return NULL;
}
return NULL;
}
+void *rbl_search(rbltree_t *tree, void *data)
+{
+ rbl_t *rbl;
+
+ rbl = rbl_search_rbl(tree, data);
+
+ if(rbl)
+ return rbl->data;
+ else
+ return NULL;
+}
+
/* Red-black tree operations taken from Introduction to Algorithms,
Cormen, Leiserson & Rivest, chapter 14.
*/
/* Red-black tree operations taken from Introduction to Algorithms,
Cormen, Leiserson & Rivest, chapter 14.
*/
@@
-171,7
+194,7
@@
rbl_t *rbl_insert_rbl(rbltree_t *tree, rbl_t *rbl)
if(tree->top)
{
if(tree->top)
{
- closest = rbl_search_closest(tree, rbl->data);
+ closest = rbl_search_closest
_rbl
(tree, rbl->data);
result = tree->compare(rbl->data, closest->data);
if(result < 0)
{
result = tree->compare(rbl->data, closest->data);
if(result < 0)
{
@@
-423,7
+446,7
@@
rbl_t *rbl_unlink(rbltree_t *tree, void *data)
{
rbl_t *rbl;
{
rbl_t *rbl;
- rbl = rbl_search(tree, data);
+ rbl = rbl_search
_rbl
(tree, data);
if(rbl)
return rbl_unlink_rbl(rbl);
if(rbl)
return rbl_unlink_rbl(rbl);
@@
-457,10
+480,11
@@
rbl_unlink_rbltree_branch(rbl_t *rbl)
rbl->parent->left = NULL;
else
rbl->parent->right = NULL;
rbl->parent->left = NULL;
else
rbl->parent->right = NULL;
+ }
}
/* Optimized unlinking for a complete tree */
}
/* Optimized unlinking for a complete tree */
-rbl_unlink_rbltree(rbltree_t *tree)
+
void
rbl_unlink_rbltree(rbltree_t *tree)
{
rbl_t *rbl, *next;
{
rbl_t *rbl, *next;
@@
-481,14
+505,15
@@
rbl_unlink_rbltree(rbltree_t *tree)
}
/* Optimized deletion for a complete tree */
}
/* Optimized deletion for a complete tree */
-rbl_delete_rbltree(rbltree_t *tree)
+
void
rbl_delete_rbltree(rbltree_t *tree)
{
rbl_t *rbl, *next;
for(rbl = tree->head; rbl; rbl = next)
{
next = rbl->next;
{
rbl_t *rbl, *next;
for(rbl = tree->head; rbl; rbl = next)
{
next = rbl->next;
- tree->delete(rbl->data)
+ if(tree->delete)
+ tree->delete(rbl->data);
}
tree->top = NULL;
}
tree->top = NULL;