2000-11-16 09:18:38 +00:00
|
|
|
/*
|
|
|
|
rbl.h -- header file for rbl.c
|
|
|
|
Copyright (C) 2000 Ivo Timmermans <itimmermans@bigfoot.com>,
|
|
|
|
2000 Guus Sliepen <guus@sliepen.warande.net>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
2000-11-24 23:13:07 +00:00
|
|
|
$Id: rbl.h,v 1.1.2.8 2000/11/24 23:13:00 guus Exp $
|
2000-11-16 09:18:38 +00:00
|
|
|
*/
|
|
|
|
|
2000-11-20 19:12:17 +00:00
|
|
|
#ifndef __RBL_H__
|
|
|
|
#define __RBL_H__
|
|
|
|
|
|
|
|
#define RBL_FOREACH(tree,rbl) for(rbl = tree->head; rbl; rbl = rbl->next)
|
|
|
|
|
2000-11-16 09:18:38 +00:00
|
|
|
typedef struct rbl_t
|
|
|
|
{
|
|
|
|
/* 'red-black tree' part */
|
|
|
|
|
|
|
|
struct rbltree_t *tree;
|
|
|
|
|
|
|
|
int color;
|
|
|
|
|
2000-11-19 02:04:29 +00:00
|
|
|
struct rbl_t *parent;
|
|
|
|
struct rbl_t *left;
|
|
|
|
struct rbl_t *right;
|
2000-11-16 09:18:38 +00:00
|
|
|
|
|
|
|
/* 'linked list' part */
|
|
|
|
|
2000-11-19 02:04:29 +00:00
|
|
|
struct rbl_t *prev;
|
|
|
|
struct rbl_t *next;
|
2000-11-16 09:18:38 +00:00
|
|
|
|
|
|
|
/* payload */
|
|
|
|
|
|
|
|
void *data;
|
|
|
|
|
|
|
|
} rbl_t;
|
|
|
|
|
2000-11-19 22:12:46 +00:00
|
|
|
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 *);
|
|
|
|
|
2000-11-16 09:18:38 +00:00
|
|
|
typedef struct rbltree_t
|
|
|
|
{
|
2000-11-18 23:21:01 +00:00
|
|
|
/* callback functions */
|
|
|
|
|
2000-11-19 02:04:29 +00:00
|
|
|
rbl_compare_t compare;
|
|
|
|
rbl_action_t delete;
|
2000-11-18 23:21:01 +00:00
|
|
|
|
|
|
|
/* tree part */
|
|
|
|
|
|
|
|
struct rbl_t *top;
|
|
|
|
|
|
|
|
/* linked list */
|
|
|
|
|
2000-11-16 09:18:38 +00:00
|
|
|
struct rbl_t *head;
|
2000-11-18 23:21:01 +00:00
|
|
|
struct rbl_t *tail;
|
|
|
|
|
2000-11-16 09:18:38 +00:00
|
|
|
} rbltree_t;
|
|
|
|
|
2000-11-19 02:04:29 +00:00
|
|
|
enum color
|
2000-11-16 09:18:38 +00:00
|
|
|
{
|
2000-11-19 02:04:29 +00:00
|
|
|
RBL_RED,
|
|
|
|
RBL_BLACK
|
|
|
|
} color;
|
2000-11-16 09:18:38 +00:00
|
|
|
|
2000-11-19 02:04:29 +00:00
|
|
|
extern rbltree_t *new_rbltree(rbl_compare_t, rbl_action_t);
|
2000-11-18 18:14:57 +00:00
|
|
|
extern void free_rbltree(rbltree_t *);
|
|
|
|
extern rbl_t *new_rbl(void);
|
|
|
|
extern void free_rbl(rbl_t *);
|
|
|
|
|
2000-11-19 22:12:46 +00:00
|
|
|
extern void *rbl_search(rbltree_t *, void *);
|
|
|
|
extern void *rbl_search_closest(rbltree_t *, void *);
|
2000-11-24 23:13:07 +00:00
|
|
|
extern void *rbl_search_closest_greater(rbltree_t *, void *);
|
|
|
|
extern void *rbl_search_closest_smaller(rbltree_t *, void *);
|
2000-11-19 22:12:46 +00:00
|
|
|
extern rbl_t *rbl_search_rbl(rbltree_t *, void *);
|
|
|
|
extern rbl_t *rbl_search_closest_rbl(rbltree_t *, void *);
|
2000-11-24 23:13:07 +00:00
|
|
|
extern rbl_t *rbl_search_closest_greater_rbl(rbltree_t *, void *);
|
|
|
|
extern rbl_t *rbl_search_closest_smaller_rbl(rbltree_t *, void *);
|
2000-11-18 18:14:57 +00:00
|
|
|
extern rbl_t *rbl_insert(rbltree_t *, void *);
|
|
|
|
extern rbl_t *rbl_unlink(rbltree_t *, void *);
|
2000-11-19 02:04:29 +00:00
|
|
|
extern void rbl_delete(rbltree_t *, void *);
|
2000-11-18 18:14:57 +00:00
|
|
|
extern rbl_t *rbl_insert_rbl(rbltree_t *, rbl_t *);
|
2000-11-19 02:04:29 +00:00
|
|
|
extern rbl_t *rbl_unlink_rbl(rbl_t *);
|
|
|
|
extern void rbl_delete_rbl(rbl_t *);
|
2000-11-19 11:05:59 +00:00
|
|
|
extern void rbl_unlink_rbltree(rbltree_t *);
|
|
|
|
extern void rbl_delete_rbltree(rbltree_t *);
|
2000-11-18 23:21:01 +00:00
|
|
|
|
2000-11-19 02:04:29 +00:00
|
|
|
extern void rbl_foreach(rbltree_t *, rbl_action_t);
|
2000-11-19 11:05:59 +00:00
|
|
|
extern void rbl_foreach_rbl(rbltree_t *, rbl_action_rbl_t);
|
2000-11-20 19:12:17 +00:00
|
|
|
|
|
|
|
#endif /* __RBL_H__ */
|