d3_dictionary.h
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:4k
开发平台:

MultiPlatform

  1. /*******************************************************************************
  2. +
  3. +  LEDA-R  3.2.3
  4. +
  5. +  d3_dictionary.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_d3_dictionary_H
  12. #define LEDA_d3_dictionary_H
  13. #include <LEDA/impl/range_tree.h>
  14. typedef rt_item dic3_item;
  15. template<class type1, class type2, class type3, class itype>
  16. class d3_dictionary : public range_tree {
  17.   // redefine the virtual functions of class range_tree
  18.   void rt_clear_key(GenPtr*& x) const { 
  19.     Clear(LEDA_ACCESS(type1,x[0])); Clear(LEDA_ACCESS(type2,x[1])); 
  20.     Clear(LEDA_ACCESS(type3,x[2])); 
  21.   }
  22.   
  23.   void rt_copy_key(GenPtr*& x) const { 
  24.     Copy(LEDA_ACCESS(type1,x[0])); Copy(LEDA_ACCESS(type2,x[1])); 
  25.     Copy(LEDA_ACCESS(type3,x[2])); 
  26.   }
  27.   void rt_print_key(int d,GenPtr*& x) const {
  28.     switch(d) {
  29.       case 0: LEDA_PRINT(type1,x[0],cout);
  30.              break;
  31.       case 1: LEDA_PRINT(type2,x[1],cout);
  32.              break;
  33.       case 2: LEDA_PRINT(type3,x[2],cout);
  34.              break;
  35.     }
  36.   }
  37.   void rt_clear_inf(GenPtr& x) const { Clear(LEDA_ACCESS(itype,x));}
  38.   void rt_copy_inf(GenPtr& x) const { Copy(LEDA_ACCESS(itype,x));}
  39.   int rt_cmp(int d, GenPtr* p, GenPtr* q) const { 
  40.     switch(d) {
  41.       case 0: return compare(LEDA_ACCESS(type1,p[0]),LEDA_ACCESS(type1,q[0]));
  42.       case 1: return compare(LEDA_ACCESS(type2,p[1]),LEDA_ACCESS(type2,q[1]));
  43.       case 2: return compare(LEDA_ACCESS(type3,p[2]),LEDA_ACCESS(type3,q[2]));
  44.     }
  45.   }
  46.   range_tree* new_range_tree(int d, int level) { 
  47.     return new d3_dictionary<type1,type2,type3,itype>(level); 
  48.   }
  49.   public:
  50.   
  51.     d3_dictionary( int level=0 ) : range_tree(3,level) {}
  52.     ~d3_dictionary() { clear(); }
  53.   
  54.     itype inf(dic3_item x)    { return LEDA_ACCESS(itype,x->inf()); }
  55.     type1 key1(dic3_item x)   { return LEDA_ACCESS(type1,x->key(0)); }
  56.     type2 key2(dic3_item x)   { return LEDA_ACCESS(type2,x->key(1)); }
  57.     type3 key3(dic3_item x)   { return LEDA_ACCESS(type3,x->key(2)); }
  58.   
  59.   
  60.     void  change_inf(dic3_item x, itype i) { 
  61.       Clear(LEDA_ACCESS(itype,x->inf())); 
  62.       x->inf() = Copy(i); 
  63.     }
  64.   
  65.     dic3_item min_key1() { return range_tree::rt_min(0); }
  66.     dic3_item max_key1() { return range_tree::rt_max(0); }
  67.     dic3_item min_key2() { return range_tree::rt_min(1); }
  68.     dic3_item max_key2() { return range_tree::rt_max(1); }
  69.     dic3_item min_key3() { return range_tree::rt_min(2); }
  70.     dic3_item max_key3() { return range_tree::rt_max(2); }
  71.   
  72.     dic3_item insert(type1 x,type2 y,type3 z,itype i)
  73.     { 
  74.       rt_item p = new rt_elem(Copy(x),Copy(y),Copy(z),Copy(i));
  75.       return range_tree::insert(p);
  76.      }
  77.     
  78.     list<rt_item> range_search( type1 x0, type1 x1,
  79.            type2 y0, type2 y1,
  80.            type3 z0, type3 z1 )
  81.     { 
  82.       rt_elem p(Convert(x0),Convert(y0),Convert(z0),0);
  83.       rt_elem q(Convert(x1),Convert(y1),Convert(z1),0);
  84.       return range_tree::query(&p,&q);
  85.     }
  86.   
  87.     dic3_item lookup( type1 x, type2 y, type3 z ) { 
  88.       rt_elem p(Convert(x),Convert(y),Convert(z),0);
  89.       return range_tree::lookup(&p);
  90.     }
  91.   
  92.     void del(type1 x,type2 y, type3 z) { 
  93.       rt_elem p(Convert(x),Convert(y),Convert(z),0);
  94.       range_tree::del(&p);
  95.      }
  96.   
  97.     void del_item(dic3_item it) { range_tree::del(it); }
  98.     list<dic3_item> all_items() { return range_tree::all_items(); }
  99. };
  100. // iteration macro
  101. //
  102. #define forall_dic3_items(x,T)  (T).init_iteration(); forall(x,(T).L )
  103. #endif