File modules/rx/rx_tree.c

  $Revision: 1.10 $

Radix tree (rx). rx_tree.c - functions to operate on trees (creation/deletion/finding).
Status: NOT REVUED, TESTED, INCOMPLETE
Design and implementation by: Marek Bukowy

Included Files


Preprocessor definitions

#define RX_IMPL

Global Function RX_get_tree()

  finds a tree matching the specified criteria(registry+space+family).

MT-note: locks/unlocks forest (still to be done)
Returns: RX_OK or RX_NOTREE if no such tree can be found.
er_ret_t RX_get_tree ( rx_tree_t** treeptr, rx_regid_t reg_id, ip_space_t spc_id, rx_fam_t fam_id )
rx_tree_t** treeptr
answer goes here, please
rx_regid_t reg_id
id of the registry
ip_space_t spc_id
type of space (ipv4/ipv6)
rx_fam_t fam_id
family of objects (route/inetnum)
Prototyped in: include/rxroutines.h
Calls: ER_dbg_va()modules/er/er.c
  g_list_first()
Called by: RX_asc_node()modules/rx/rx_node.c
  RX_asc_search()modules/rx/rx_search.c
  RX_space_cre()modules/rx/rx_tree.c
References Variables: rx_forestmodules/rx/rx_globals.c

Global Function RX_space_cre()

  creates a (top) tree for the space, fills out sql table of trees
  generates a tablename for a tree (if NONE)
  updates LL of trees

MT-note: locks/unlocks the forest (still to be done)
er_ret_t RX_space_cre ( rx_regid_t reg_id, ip_space_t spc_id, rx_fam_t fam_id, char* prefixstr, rx_mem_mt mem_mode, rx_subtree_mt subtrees )
rx_regid_t reg_id
id of the registry
ip_space_t spc_id
space id, one of IPv4 IPv6.
rx_fam_t fam_id
family of objects (route/inetnum)
char* prefixstr
prefix the tree will cover (string)
rx_mem_mt mem_mode
 
rx_subtree_mt subtrees
one of NONE, AUTO, HAND
Prototyped in: include/rxroutines.h
Calls: ER_dbg_va()modules/er/er.c
  IP_pref_t2b()modules/ip/ip.c
  IP_sizebits()modules/ip/ip.c
  RX_get_tree()modules/rx/rx_tree.c
  fprintf(), g_list_append(), strcpy(), wr_malloc()
References Variables: rx_forestmodules/rx/rx_globals.c

Global Function rx_walk_tree()

  go down the tree calling func on every node.
  (func takes the node pointer and the current level)

the function is called recursively with level increased it stops recursing when no child nodes are found or maxlevel is reached.
therefore the initial call must set level to 0.
the nodecounter increments at every node, and is the return value of the function. So start with 0 to get the number of nodes traversed.
ERROR HANDLING IS DIFFERENT HERE! Unlike other functions it is not the return value: The error code from the func function IF DEFINED (== not NULL ) goes to the variable pointed to by the last parameter.
int rx_walk_tree ( rx_node_t* node, er_ret_t (*func)(rx_node_t* node,int level,int nodecounter,void* userptr), rx_walk_mt walk_mode, int maxlevel, int level, int nodecounter, void* userptr, er_ret_t* err )
Prototyped in: include/rxroutines.h
Calls: ER_dbg_va()modules/er/er.c
  rx_walk_tree()modules/rx/rx_tree.c
  fprintf()
Called by: rx_nod_search()modules/rx/rx_search.c
  rx_tree_print()modules/rx/rx_print.c
  rx_walk_tree()modules/rx/rx_tree.c