Diff for /libelwix/src/patricia.c between versions 1.1 and 1.5.74.3

version 1.1, 2013/01/17 10:05:35 version 1.5.74.3, 2024/01/22 15:19:13
Line 12  terms: Line 12  terms:
 All of the documentation and software included in the ELWIX and AITNET  All of the documentation and software included in the ELWIX and AITNET
 Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>  Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
   
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013Copyright 2004 - 2024
         by Michael Pounov <misho@elwix.org>.  All rights reserved.          by Michael Pounov <misho@elwix.org>.  All rights reserved.
   
 Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
Line 57  SUCH DAMAGE. Line 57  SUCH DAMAGE.
  */   */
 #include "global.h"  #include "global.h"
   
#ifdef PATRICIA_SUPPORT
 static int num_active_patricia;  static int num_active_patricia;
   
   
Line 213  static inline prefix_t *New_Prefix(int family, void *d Line 213  static inline prefix_t *New_Prefix(int family, void *d
   
 // ------------------------------------------------------------------------------------  // ------------------------------------------------------------------------------------
   
inline char *prefix_toa(prefix_t * prefix)char *prefix_toa(prefix_t * prefix)
 {  {
     return prefix_toa2x(prefix, NULL, 0);      return prefix_toa2x(prefix, NULL, 0);
 }  }
   
inline prefix_t *ascii2prefix(int family, char *string)prefix_t *ascii2prefix(int family, char *string)
 {  {
         u_long bitlen, maxbitlen = 0;          u_long bitlen, maxbitlen = 0;
         char *cp;          char *cp;
Line 257  inline prefix_t *ascii2prefix(int family, char *string Line 257  inline prefix_t *ascii2prefix(int family, char *string
                 memcpy(save, string, cp - string);                  memcpy(save, string, cp - string);
                 save[cp - string] = 0;                  save[cp - string] = 0;
                 string = save;                  string = save;
                if (bitlen < 0 || bitlen > maxbitlen)                if (bitlen > maxbitlen)
                         bitlen = maxbitlen;                          bitlen = maxbitlen;
         } else          } else
                 bitlen = maxbitlen;                  bitlen = maxbitlen;
Line 279  inline prefix_t *ascii2prefix(int family, char *string Line 279  inline prefix_t *ascii2prefix(int family, char *string
                         return NULL;                          return NULL;
 }  }
   
inline prefix_t *Ref_Prefix(prefix_t *prefix)prefix_t *Ref_Prefix(prefix_t *prefix)
 {  {
         if (!prefix)          if (!prefix)
                 return NULL;                  return NULL;
Line 293  inline prefix_t *Ref_Prefix(prefix_t *prefix) Line 293  inline prefix_t *Ref_Prefix(prefix_t *prefix)
         return prefix;          return prefix;
 }  }
   
inline void Deref_Prefix(prefix_t *prefix)void Deref_Prefix(prefix_t *prefix)
 {  {
         if (!prefix)          if (!prefix)
                 return;                  return;
Line 309  inline void Deref_Prefix(prefix_t *prefix) Line 309  inline void Deref_Prefix(prefix_t *prefix)
 /* } */  /* } */
   
 /* these routines support continuous mask only */  /* these routines support continuous mask only */
inline patricia_tree_t *New_Patricia(int maxbits)patricia_tree_t *New_Patricia(int maxbits)
 {  {
         patricia_tree_t *patricia;          patricia_tree_t *patricia;
   
Line 330  inline patricia_tree_t *New_Patricia(int maxbits) Line 330  inline patricia_tree_t *New_Patricia(int maxbits)
  * if func is supplied, it will be called as func(node->data)   * if func is supplied, it will be called as func(node->data)
  * before deleting the node   * before deleting the node
  */   */
inline void Clear_Patricia(patricia_tree_t *patricia, void_fn_t func)void Clear_Patricia(patricia_tree_t *patricia, void_fn_t func)
 {  {
         assert(patricia);          assert(patricia);
         if (patricia->head) {          if (patricia->head) {
Line 368  inline void Clear_Patricia(patricia_tree_t *patricia,  Line 368  inline void Clear_Patricia(patricia_tree_t *patricia, 
         /* Delete(patricia); */          /* Delete(patricia); */
 }  }
   
inline void Destroy_Patricia(patricia_tree_t *patricia, void_fn_t func)void Destroy_Patricia(patricia_tree_t *patricia, void_fn_t func)
 {  {
         Clear_Patricia(patricia, func);          Clear_Patricia(patricia, func);
         Delete(patricia);          Delete(patricia);
Line 379  inline void Destroy_Patricia(patricia_tree_t *patricia Line 379  inline void Destroy_Patricia(patricia_tree_t *patricia
 /*  /*
  * if func is supplied, it will be called as func(node->prefix, node->data)   * if func is supplied, it will be called as func(node->prefix, node->data)
  */   */
inline void patricia_process(patricia_tree_t *patricia, void_fn_t func)void patricia_process(patricia_tree_t *patricia, void_fn_t func)
 {  {
         patricia_node_t *node;          patricia_node_t *node;
   
Line 391  inline void patricia_process(patricia_tree_t *patricia Line 391  inline void patricia_process(patricia_tree_t *patricia
 }  }
   
   
inline patricia_node_t *patricia_search_exact(patricia_tree_t *patricia, prefix_t *prefix)patricia_node_t *patricia_search_exact(patricia_tree_t *patricia, prefix_t *prefix)
 {  {
         patricia_node_t *node;          patricia_node_t *node;
         u_char *addr;          u_char *addr;
Line 459  inline patricia_node_t *patricia_search_exact(patricia Line 459  inline patricia_node_t *patricia_search_exact(patricia
   
   
 /* if inclusive != 0, "best" may be the given prefix itself */  /* if inclusive != 0, "best" may be the given prefix itself */
inline patricia_node_t *patricia_search_best2(patricia_tree_t *patricia, prefix_t *prefix, int inclusive)patricia_node_t *patricia_search_best2(patricia_tree_t *patricia, prefix_t *prefix, int inclusive)
 {  {
         patricia_node_t *node;          patricia_node_t *node;
         patricia_node_t *stack[PATRICIA_MAXBITS + 1];          patricia_node_t *stack[PATRICIA_MAXBITS + 1];
Line 549  inline patricia_node_t *patricia_search_best2(patricia Line 549  inline patricia_node_t *patricia_search_best2(patricia
         return NULL;          return NULL;
 }  }
   
inline patricia_node_t *patricia_search_best(patricia_tree_t *patricia, prefix_t *prefix)patricia_node_t *patricia_search_best(patricia_tree_t *patricia, prefix_t *prefix)
 {  {
     return patricia_search_best2(patricia, prefix, 1);      return patricia_search_best2(patricia, prefix, 1);
 }  }
   
   
inline patricia_node_t *patricia_lookup(patricia_tree_t *patricia, prefix_t *prefix)patricia_node_t *patricia_lookup(patricia_tree_t *patricia, prefix_t *prefix)
 {  {
         patricia_node_t *node, *new_node, *parent, *glue;          patricia_node_t *node, *new_node, *parent, *glue;
         u_char *addr, *test_addr;          u_char *addr, *test_addr;
Line 759  inline patricia_node_t *patricia_lookup(patricia_tree_ Line 759  inline patricia_node_t *patricia_lookup(patricia_tree_
 }  }
   
   
inline void patricia_remove(patricia_tree_t *patricia, patricia_node_t *node)void patricia_remove(patricia_tree_t *patricia, patricia_node_t *node)
 {  {
         patricia_node_t *parent, *child;          patricia_node_t *parent, *child;
   
Line 860  inline void patricia_remove(patricia_tree_t *patricia, Line 860  inline void patricia_remove(patricia_tree_t *patricia,
   
 /* { from demo.c */  /* { from demo.c */
   
inline void lookup_then_remove(patricia_tree_t *tree, char *string)void lookup_then_remove(patricia_tree_t *tree, char *string)
 {  {
         patricia_node_t *node;          patricia_node_t *node;
   
Line 868  inline void lookup_then_remove(patricia_tree_t *tree,  Line 868  inline void lookup_then_remove(patricia_tree_t *tree, 
                 patricia_remove(tree, node);                  patricia_remove(tree, node);
 }  }
   
inline patricia_node_t *make_and_lookup(patricia_tree_t *tree, char *string)patricia_node_t *make_and_lookup(patricia_tree_t *tree, char *string)
 {  {
         prefix_t *prefix;          prefix_t *prefix;
         patricia_node_t *node;          patricia_node_t *node;
Line 883  inline patricia_node_t *make_and_lookup(patricia_tree_ Line 883  inline patricia_node_t *make_and_lookup(patricia_tree_
         return node;          return node;
 }  }
   
inline patricia_node_t *try_search_exact(patricia_tree_t *tree, char *string)patricia_node_t *try_search_exact(patricia_tree_t *tree, char *string)
 {  {
         prefix_t *prefix;          prefix_t *prefix;
         patricia_node_t *node;          patricia_node_t *node;
Line 904  inline patricia_node_t *try_search_exact(patricia_tree Line 904  inline patricia_node_t *try_search_exact(patricia_tree
         return node;          return node;
 }  }
   
inline patricia_node_t *try_search_best(patricia_tree_t *tree, char *string)patricia_node_t *try_search_best(patricia_tree_t *tree, char *string)
 {  {
         prefix_t *prefix;          prefix_t *prefix;
         patricia_node_t *node;          patricia_node_t *node;
Line 926  inline patricia_node_t *try_search_best(patricia_tree_ Line 926  inline patricia_node_t *try_search_best(patricia_tree_
 }  }
   
 /* } */  /* } */
   #endif

Removed from v.1.1  
changed lines
  Added in v.1.5.74.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>