[Olsr-cvs] olsrd-current/src lq_avl.h, 1.12, 1.13 lq_avl.c, 1.14, 1.15

Bernd Petrovitsch (spam-protected)
Sun Nov 11 23:55:19 CET 2007


Update of /cvsroot/olsrd/olsrd-current/src
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv6880/src

Modified Files:
	lq_avl.h lq_avl.c 
Log Message:
* made inline functions from avl_walk_{first,last,next,prev}
* created "const" versions of it
* inline_avl_comp_ipv4() is now also an inline function (and not a macro)
* created a typedef for the avl tree comparison functions and use it!
* cleanup: compare tree->comp to NULL as it is a pointer
* killed a superflous "return"at the end of a void function


Index: lq_avl.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/lq_avl.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** lq_avl.h	8 Nov 2007 22:47:41 -0000	1.12
--- lq_avl.h	11 Nov 2007 22:55:16 -0000	1.13
***************
*** 44,47 ****
--- 44,49 ----
  #define _LQ_AVL_H
  
+ #include "defs.h"
+ 
  struct avl_node
  {
***************
*** 57,60 ****
--- 59,64 ----
  };
  
+ typedef int (*avl_tree_comp)(const void *, const void *);
+ 
  struct avl_tree
  {
***************
*** 63,67 ****
    struct avl_node *last;
    unsigned int count;
!   int (*comp)(const void *, const void *);
  };
  
--- 67,71 ----
    struct avl_node *last;
    unsigned int count;
!   avl_tree_comp comp;
  };
  
***************
*** 69,89 ****
  #define AVL_DUP_NO 0
  
! void avl_init(struct avl_tree *, int (*)(const void *, const void *));
  struct avl_node *avl_find(struct avl_tree *, const void *);
  int avl_insert(struct avl_tree *, struct avl_node *, int);
  void avl_delete(struct avl_tree *, struct avl_node *);
- struct avl_node *avl_walk_first(struct avl_tree *);
- struct avl_node *avl_walk_last(struct avl_tree *);
- struct avl_node *avl_walk_next(struct avl_node *);
- struct avl_node *avl_walk_prev(struct avl_node *);
  
! extern int (*avl_comp_default)(const void *, const void *);
! extern int (*avl_comp_prefix_default)(const void *, const void *);
  extern int avl_comp_ipv4(const void *, const void *);
  extern int avl_comp_ipv6(const void *, const void *);
  
! #define inline_avl_comp_ipv4(ip1, ip2) \
!   (*(unsigned int *)(ip1) == *(unsigned int *)(ip2) ? 0 :       \
!    *(unsigned int *)(ip1) < *(unsigned int *)(ip2) ? -1 : +1)
  
  #endif
--- 73,99 ----
  #define AVL_DUP_NO 0
  
! void avl_init(struct avl_tree *, avl_tree_comp);
  struct avl_node *avl_find(struct avl_tree *, const void *);
  int avl_insert(struct avl_tree *, struct avl_node *, int);
  void avl_delete(struct avl_tree *, struct avl_node *);
  
! static INLINE struct avl_node *avl_walk_first(struct avl_tree *tree) { return tree->first; }
! static INLINE struct avl_node *avl_walk_last(struct avl_tree *tree) { return tree->last; }
! static INLINE struct avl_node *avl_walk_next(struct avl_node *node) { return node->next; }
! static INLINE struct avl_node *avl_walk_prev(struct avl_node *node) { return node->prev; }
! /* and const versions*/
! static INLINE const struct avl_node *avl_walk_first_c(const struct avl_tree *tree) { return tree->first; }
! static INLINE const struct avl_node *avl_walk_last_c(const struct avl_tree *tree) { return tree->last; }
! static INLINE const struct avl_node *avl_walk_next_c(const struct avl_node *node) { return node->next; }
! static INLINE const struct avl_node *avl_walk_prev_c(const struct avl_node *node) { return node->prev; }
! 
! extern avl_tree_comp avl_comp_default;
! extern avl_tree_comp avl_comp_prefix_default;
  extern int avl_comp_ipv4(const void *, const void *);
  extern int avl_comp_ipv6(const void *, const void *);
  
! static INLINE int inline_avl_comp_ipv4(const void *_ip1, const void *_ip2) {
!   const unsigned int *ip1 = _ip1, *ip2 = _ip2;
!   return *ip1 == *ip2 ? 0 : *ip1 < *ip2 ? -1 : +1; }
  
  #endif

Index: lq_avl.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/lq_avl.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** lq_avl.c	8 Nov 2007 22:47:41 -0000	1.14
--- lq_avl.c	11 Nov 2007 22:55:17 -0000	1.15
***************
*** 56,61 ****
   * inline ipv4 comparison will be executed.
   */
! int (*avl_comp_default)(const void *, const void *) = NULL;
! int (*avl_comp_prefix_default)(const void *, const void *);
  
  int avl_comp_ipv4(const void *ip1, const void *ip2)
--- 56,61 ----
   * inline ipv4 comparison will be executed.
   */
! avl_tree_comp avl_comp_default = NULL;
! avl_tree_comp avl_comp_prefix_default;
  
  int avl_comp_ipv4(const void *ip1, const void *ip2)
***************
*** 69,73 ****
  }
  
! void avl_init(struct avl_tree *tree, int (*comp)(const void *, const void *))
  {
    tree->root = NULL;
--- 69,73 ----
  }
  
! void avl_init(struct avl_tree *tree, avl_tree_comp comp)
  {
    tree->root = NULL;
***************
*** 96,104 ****
  
  static struct avl_node *avl_find_rec(struct avl_node *node, const void *key,
!                                      int (*comp)(const void *, const void *))
  {
    int diff;
  
!   if (0 == comp)
      return avl_find_rec_ipv4(node, key);
  
--- 96,104 ----
  
  static struct avl_node *avl_find_rec(struct avl_node *node, const void *key,
!                                      avl_tree_comp comp)
  {
    int diff;
  
!   if (NULL == comp)
      return avl_find_rec_ipv4(node, key);
  
***************
*** 133,137 ****
    node = avl_find_rec(tree->root, key, tree->comp);
  
!   if (0 == tree->comp)
    {
      if (0 != inline_avl_comp_ipv4(node->key, key))
--- 133,137 ----
    node = avl_find_rec(tree->root, key, tree->comp);
  
!   if (NULL == tree->comp)
    {
      if (0 != inline_avl_comp_ipv4(node->key, key))
***************
*** 214,220 ****
  static void post_insert(struct avl_tree *tree, struct avl_node *node)
  {
!   struct avl_node *parent;
  
!   if ((parent = node->parent) == NULL)
      return;
  
--- 214,220 ----
  static void post_insert(struct avl_tree *tree, struct avl_node *node)
  {
!   struct avl_node *parent = node->parent;
  
!   if (parent == NULL)
      return;
  
***************
*** 262,266 ****
    avl_rotate_right(tree, node);
    avl_rotate_left(tree, node->parent->parent);
-   return;
  }
  
--- 262,265 ----
***************
*** 345,349 ****
      last = last->next;
  
!   if (0 == tree->comp)
      diff = inline_avl_comp_ipv4(new->key, node->key);
  
--- 344,348 ----
      last = last->next;
  
!   if (NULL == tree->comp)
      diff = inline_avl_comp_ipv4(new->key, node->key);
  
***************
*** 691,714 ****
  }
  
- struct avl_node *avl_walk_first(struct avl_tree *tree)
- {
-   return tree->first;
- }
- 
- struct avl_node *avl_walk_last(struct avl_tree *tree)
- {
-   return tree->last;
- }
- 
- struct avl_node *avl_walk_next(struct avl_node *node)
- {
-   return node->next;
- }
- 
- struct avl_node *avl_walk_prev(struct avl_node *node)
- {
-   return node->prev;
- }
- 
  /*
   * Local Variables:
--- 690,693 ----





More information about the Olsr-cvs mailing list