X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=lib%2Frbl.c;h=26a02db029fda93e3480959b1fa262e5b65c323e;hp=1a40535051a5b3704ff9fe0d5882cf3272555c00;hb=afabbd6b9020dd6555a7ecd320a7b3e96119d538;hpb=394ed3fb174bb629bfb4b441fe58842562f955de diff --git a/lib/rbl.c b/lib/rbl.c index 1a405350..26a02db0 100644 --- a/lib/rbl.c +++ b/lib/rbl.c @@ -1,7 +1,7 @@ /* rbl.c -- red-black tree + linked list convenience - Copyright (C) 2000 Ivo Timmermans , - 2000 Guus Sliepen + Copyright (C) 2000 Ivo Timmermans , + 2000 Guus Sliepen 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 @@ -17,7 +17,7 @@ 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.11 2000/11/22 19:14:08 guus Exp $ + $Id: rbl.c,v 1.1.2.13 2002/06/21 10:11:11 guus Exp $ */ #include "config.h" @@ -88,6 +88,38 @@ rbl_t *rbl_search_closest_rbl(rbltree_t *tree, void *data) return rbl; } +/* Search closest match in the tree */ +rbl_t *rbl_search_closest_greater_rbl(rbltree_t *tree, void *data) +{ + rbl_t *rbl; + + rbl = rbl_search_closest_rbl(tree, data); + + if(rbl) + { + if(tree->compare(data, rbl->data) > 0) + rbl = rbl->next; + } + + return rbl; +} + +/* Search closest match in the tree */ +rbl_t *rbl_search_closest_smaller_rbl(rbltree_t *tree, void *data) +{ + rbl_t *rbl; + + rbl = rbl_search_closest_rbl(tree, data); + + if(rbl) + { + if(tree->compare(data, rbl->data) < 0) + rbl = rbl->next; + } + + return rbl; +} + void *rbl_search_closest(rbltree_t *tree, void *data) { rbl_t *rbl; @@ -100,6 +132,30 @@ void *rbl_search_closest(rbltree_t *tree, void *data) return NULL; } +void *rbl_search_closest_greater(rbltree_t *tree, void *data) +{ + rbl_t *rbl; + + rbl = rbl_search_closest_greater_rbl(tree, data); + + if(rbl) + return rbl->data; + else + return NULL; +} + +void *rbl_search_closest_smaller(rbltree_t *tree, void *data) +{ + rbl_t *rbl; + + rbl = rbl_search_closest_smaller_rbl(tree, data); + + if(rbl) + return rbl->data; + else + return NULL; +} + /* Search exact match or return NULL pointer */ rbl_t *rbl_search_rbl(rbltree_t *tree, void *data) {