bb_tree.h
Upload User: gzelex
Upload Date: 2007-01-07
Package Size: 707k
Code Size: 2k
Development Platform:

MultiPlatform

  1. /*******************************************************************************
  2. +
  3. +  LEDA-R  3.2.3
  4. +
  5. +  bb_tree.h
  6. +
  7. +  Copyright (c) 1995  by  Max-Planck-Institut fuer Informatik
  8. +  Im Stadtwald, 66123 Saarbruecken, Germany     
  9. +  All rights reserved.
  10. *******************************************************************************/
  11. #ifndef LEDA_BB_TREE_H
  12. #define LEDA_BB_TREE_H
  13. //------------------------------------------------------------------------------
  14. //
  15. // bb_tree:  
  16. //
  17. //           BB[alpha] trees (derived from class "bin_tree")
  18. //
  19. // Stefan N"aher (1993)
  20. //
  21. //------------------------------------------------------------------------------
  22. #include <LEDA/basic.h>
  23. #include <LEDA/impl/bin_tree.h>
  24.  
  25. typedef bin_tree_node* bb_tree_item;
  26.  
  27. // ----------------------------------------------------------------
  28. // class bb_tree
  29. // ----------------------------------------------------------------
  30. // const float alpha = 0.28;
  31. // const float d     = 0.58;
  32. // we multiply alpha, d, and all balances by 64 to make them integers
  33.   const int alpha = 18; // 0.28 * 64
  34.   const int d = 37;     // 0.58 * 64
  35. class bb_tree : public bin_tree
  36.   int root_balance() { return 2; }
  37.   int node_balance() { return 2; }
  38.   int leaf_balance() { return 1; }
  39.   void rebal(bb_tree_item,int);
  40.   void insert_rebal(bb_tree_item);
  41.   void del_rebal(bb_tree_item, bb_tree_item);
  42.   float balance(bb_tree_item p)
  43.   { if (p->is_leaf()) 
  44.        return 0.5 ;
  45.     else 
  46.        return float(p->child[left]->get_bal())/p->get_bal();
  47.    }
  48. public:
  49.   bb_tree() {}
  50.  ~bb_tree() {}
  51.   bb_tree(const bb_tree& T) : bin_tree(T) {}
  52.   bb_tree& operator=(const bb_tree& T) 
  53.   { bin_tree::operator=(T); return *this; }
  54. };
  55. #endif