home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / incl / h_array.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-29  |  2.1 KB  |  71 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  2.1.1                                                 11-15-1991
  4. +
  5. +
  6. +  h_array.h
  7. +
  8. +
  9. +  Copyright (c) 1991  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. //------------------------------------------------------------------------------
  16. // h_array  
  17. //
  18. // Stefan Naeher (1989)
  19. //------------------------------------------------------------------------------ 
  20. #ifndef HARRAYH
  21. #define HARRAYH
  22.  
  23. #include <LEDA/basic.h> 
  24. #include <LEDA/slist.h> 
  25. #include <LEDA/dp_hashing.h> 
  26.  
  27. #define h_array(itype,etype) name3(itype,etype,h_array)
  28.  
  29. #define h_arraydeclare2(itype,etype)\
  30. \
  31. class h_array(itype,etype) : public dphash {\
  32. \
  33. void copy_key(ent& x)  { x = Copy(*(itype*)&x);  }\
  34. void copy_inf(ent& x)  { x = Copy(*(etype*)&x);  }\
  35. void clear_key(ent& x) { Clear(*(itype*)&x); }\
  36. void clear_inf(ent& x) { Clear(*(etype*)&x); }\
  37. \
  38. etype init;\
  39. SLIST def_list;\
  40. \
  41. public:\
  42. \
  43. etype& operator[](itype y) { stp i=dphash::lookup(Ent(y));\
  44.                              if (i==nil) { i=dphash::insert(Ent(y),Ent(init));\
  45.                                            def_list.append(Ent(y));  }\
  46.                              return *(etype*)&dphash::info(i); }\
  47. /*\
  48. etype  operator[](itype y) const\
  49.                            { stp i=dphash::lookup(Ent(y));\
  50.                              if (i==nil) return init;\
  51.                              else return etype(dphash::info(i)); }\
  52. */\
  53. bool defined(itype y)    { return dphash::member(Ent(y)); }\
  54. \
  55. void init_iterator()     { def_list.init_iterator(); }\
  56. bool next_index(itype& y){ return def_list.next_element(*(ent*)&y); }\
  57. \
  58. h_array(itype,etype)() { }\
  59. h_array(itype,etype)(int n,itype* I,etype* E): dphash(n,(ent*)I,(ent*)E) { }\
  60. h_array(itype,etype)(etype i) { init=i; }\
  61. h_array(itype,etype)(h_array(itype,etype)& A): dphash((dphash&)A)\
  62. { init = A.init; }\
  63. ~h_array(itype,etype)() { def_list.clear(); };\
  64. };
  65.  
  66. #define forall_defined(i,A)  for ((A).init_iterator(); (A).next_index(i); )
  67.  
  68.  
  69. #endif
  70.