$Revision: 1.37 $
Radix tree (rx). rx_search.c - functions to search nodes of the tree
Status: NOT REVUED, TESTED, COMPLETE
Design and implementation by: Marek Bukowy
Included Files
pthread_mutex_t Lock
builds a stack for this prefix, finds *nodes* in the stack
and appends *copies of the data leaves* to the LL of answers;
sorts by SQL object keys and uniq's the data
finds:
0 or 1 nodes for exact search
0 or 1 nodes for exless (0 if no less specific node found)
any number (incl. 0) for {more|less}-n specific
then copies the nodes/dataleaves to the answer structs and appends them
to the given LL. So, effectively, the number of answers can be
anything from 0 to infinity, because objects may be duplicate
even at the same node.
returns errcode.
algorithm:
builds stack[MAXBIT (==128)];
if( more/less-depth && par_a == 0)
run rx_nod_search, then
if(more spec) rx_nod_walk(maxdepth=n, append_to_LL() );
if(less spec) do { append(LL, stack[i]) } while(i-- && n--);
otherwise just set LL
The routine provides _at_least_ max_count answers.
It will *try* to stop after max_count as soon as possible
- but it's the higher level routine that should do the final cut.
er_ret_t RX_bin_search ( rx_srch_mt search_mode, int par_a, int par_b, rx_tree_t* tree, ip_prefix_t* prefix, GList** datleaves, int max_count )
Descends the given tree following the last prefix bit to get [past]
the node with the given prefix.
It fills up a stack of COPIES of nodes, including glue nodes.
Then it also sets the number of elements on the stack:
set maxdepth to the position where a next one would be written
( = last + 1, or number of nodes pushed)
The dmodes:
RX_STK_QUERY_NOGLUE = (search exact/less spec) stop when
* the current prefix length >= newprefix length
* the current prefix does not match anymore
* do not add glue nodes
RX_STK_QUERY_ALLNOD = as above, except that the glue and data nodes are
treated equally (i.e. glue nodes are not skipped)
RX_STK_CREAT = descend until the next non-glue node past the one found
in exact mode (for creation)
er_ret_t rx_build_stack ( rx_nodcpy_t stack[], int* maxdepth, rx_tree_t* tree, ip_prefix_t* newpref, rx_stk_mt dmode )
er_ret_t rx_nod_search ( rx_srch_mt search_mode, int par_a, int par_b, rx_tree_t* tree, ip_prefix_t* prefix, rx_nodcpy_t stack[], int stackcount, GList** nodlist, int max_count, void )
static char* asctime_r ( const struct tm* __tm, char* __buf )
static char* ctime_r ( const time_t* __time, char* __buf )
static int getlogin_r ( char* __name, int __len )
static int readdir_r ( DIR* __dp, struct dirent* __ent, struct dirent** __res )
helper for the nod_search routine:
allocate a new node copy struct, copy the struct and add to nodlist
static er_ret_t rx_nod_append ( GList** nodlist, rx_nodcpy_t* element )
helper for DBLS lookup in rx_nod_search
adds a node to the list of answers.
static er_ret_t rx_walk_hook_adddoubles ( rx_node_t* node, int level, int nodecounter, void* userptr )
helper for MORE specific lookup in rx_nod_search
adds a node to the list of answers.
static er_ret_t rx_walk_hook_addnode ( rx_node_t* node, int level, int nodecounter, void* userptr )
static int sigwait ( const sigset_t* __setp, int* __signo )
static int ttyname_r ( int __fildes, char* __buf, size_t __size )