File modules/rx/rx_search.c

  $Revision: 1.35 $

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


Global Function RX_bin_search()

  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 )
Prototyped in: include/rxroutines.h
Calls: ER_dbg_va()modules/er/er.c
  rx_build_stack()modules/rx/rx_search.c
  rx_nod_search()modules/rx/rx_search.c
  fprintf(), g_list_first(), g_list_length(), g_list_nth_data(), g_list_prepend(), wr_real_calloc(), wr_real_clear_list()
Called by: AC_findcreate_account_l()modules/ac/access_control.c
  AC_findcreate_acl_l()modules/ac/access_control.c
  RP_asc_search()modules/rp/rp_search.c
  ac_find_acl_l()modules/ac/access_control.c
  rp_preflist_search()modules/rp/rp_search.c

Global Function rx_build_stack()

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 )
Prototyped in: include/rxroutines.h
Calls: ER_dbg_va()modules/er/er.c
  ER_is_traced()modules/er/er.c
  IP_addr_bit_get()modules/ip/ip.c
  IP_addr_cmp()modules/ip/ip.c
  IP_pref_b2a()modules/ip/ip.c
  memcpy()
Called by: RX_bin_search()modules/rx/rx_search.c
  rx_bin_node()modules/rx/rx_node.c

Global Function rx_nod_search()

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 )
Prototyped in: include/rxroutines.h
Calls: ER_dbg_va()modules/er/er.c
  ER_is_traced()modules/er/er.c
  IP_addr_cmp()modules/ip/ip.c
  IP_pref_b2a()modules/ip/ip.c
  RX_text_srch_mode()modules/rx/rx_print.c
  rx_nod_append()modules/rx/rx_search.c
  rx_nod_print()modules/rx/rx_print.c
  fprintf(), memcmp(), rx_walk_tree()
Called by: RX_bin_search()modules/rx/rx_search.c
  rx_bin_node()modules/rx/rx_node.c
References Functions: rx_walk_hook_adddoubles()modules/rx/rx_search.c
  rx_walk_hook_addnode()modules/rx/rx_search.c

Local Function rx_nod_append()

   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 )
Calls: g_list_prepend(), memcpy(), wr_real_calloc()
Called by: rx_nod_search()modules/rx/rx_search.c
  rx_walk_hook_adddoubles()modules/rx/rx_search.c
  rx_walk_hook_addnode()modules/rx/rx_search.c

Local Function rx_walk_hook_adddoubles()

  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 )
Calls: ER_dbg_va()modules/er/er.c
  ER_is_traced()modules/er/er.c
  rx_nod_append()modules/rx/rx_search.c
  rx_nod_print()modules/rx/rx_print.c
  g_list_length()
Used in: rx_nod_search()modules/rx/rx_search.c

Local Function rx_walk_hook_addnode()

  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 )
Calls: rx_nod_append()modules/rx/rx_search.c
  memset()
Used in: rx_nod_search()modules/rx/rx_search.c