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.7 2000/11/19 22:12:46 guus Exp $
*/
#include <xalloc.h>
}
/* 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;
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 */
-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;
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.
*/
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)
{
{
rbl_t *rbl;
- rbl = rbl_search(tree, data);
+ rbl = rbl_search_rbl(tree, data);
if(rbl)
return rbl_unlink_rbl(rbl);
rbl->parent->left = NULL;
else
rbl->parent->right = NULL;
+ }
}
/* Optimized unlinking for a complete tree */
-rbl_unlink_rbltree(rbltree_t *tree)
+void rbl_unlink_rbltree(rbltree_t *tree)
{
rbl_t *rbl, *next;
}
/* 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;
- tree->delete(rbl->data)
+ tree->delete(rbl->data);
}
tree->top = NULL;
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: rbl.h,v 1.1.2.5 2000/11/19 11:05:59 guus Exp $
+ $Id: rbl.h,v 1.1.2.6 2000/11/19 22:12:46 guus Exp $
*/
-typedef int (*rbl_compare_t) (const void *, const void *);
-typedef void (*rbl_action_t) (const void *);
-typedef void (*rbl_action_rbl_t) (const struct rbl_t *);
-
typedef struct rbl_t
{
/* 'red-black tree' part */
} rbl_t;
+typedef int (*rbl_compare_t) (const void *, const void *);
+typedef void (*rbl_action_t) (const void *);
+typedef void (*rbl_action_rbl_t) (const struct rbl_t *);
+
typedef struct rbltree_t
{
/* callback functions */
extern rbl_t *new_rbl(void);
extern void free_rbl(rbl_t *);
-extern rbl_t *rbl_search(rbltree_t *, void *);
-extern rbl_t *rbl_search_closest(rbltree_t *, void *);
+extern void *rbl_search(rbltree_t *, void *);
+extern void *rbl_search_closest(rbltree_t *, void *);
+extern rbl_t *rbl_search_rbl(rbltree_t *, void *);
+extern rbl_t *rbl_search_closest_rbl(rbltree_t *, void *);
extern rbl_t *rbl_insert(rbltree_t *, void *);
extern rbl_t *rbl_unlink(rbltree_t *, void *);
extern void rbl_delete(rbltree_t *, void *);