00001
00002
00003
00004
00005
00006
00007
00008
00057 #ifdef _MSC_VER
00058 #pragma once
00059 #endif
00060
00061 #include <ogdf/basic/HashArray.h>
00062 #include <ogdf/basic/tuples.h>
00063 #include <ogdf/basic/HashIterator2D.h>
00064
00065 #ifndef OGDF_HASHARRAY2D_H
00066 #define OGDF_HASHARRAY2D_H
00067
00068
00069 namespace ogdf {
00070
00071
00085 template< class I1_, class I2_, class E_,
00086 class Hash1_ = DefHashFunc<I1_>,
00087 class Hash2_ = DefHashFunc<I2_> >
00088 class HashArray2D : private Hashing<Tuple2<I1_,I2_>, E_,
00089 HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >
00090 {
00091 public:
00093 typedef HashConstIterator2D<I1_,I2_,E_,Hash1_,Hash2_> const_iterator;
00094
00096 HashArray2D() {}
00097
00099 HashArray2D(const E_ &defaultValue,
00100 const Hash1_ &hashFunc1 = Hash1_(),
00101 const Hash2_ &hashFunc2 = Hash2_())
00102 : Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >(256,
00103 HashFuncTuple<I1_,I2_,Hash1_,Hash2_>(hashFunc1,hashFunc2)),
00104 m_defaultValue(defaultValue) {}
00105
00107 HashArray2D(const HashArray2D<I1_,I2_,E_,Hash1_,Hash2_> &A) :
00108 Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >(A),
00109 m_defaultValue(A.m_defaultValue) { }
00110
00112 HashArray2D &operator=(const HashArray2D<I1_,I2_,E_,Hash1_,Hash2_> &A) {
00113 m_defaultValue = A.m_defaultValue;
00114 Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::operator=(A);
00115
00116 return *this;
00117 }
00118
00119 ~HashArray2D(){};
00120
00122 const E_ &operator()(const I1_ &i, const I2_ &j) const {
00123 HashElement<Tuple2<I1_,I2_>,E_> *pElement =
00124 Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::lookup(Tuple2<I1_,I2_>(i,j));
00125 if (pElement) return pElement->info();
00126 else return m_defaultValue;
00127 }
00128
00130 E_ &operator()(const I1_ &i, const I2_ &j) {
00131 Tuple2<I1_,I2_> t(i,j);
00132 HashElement<Tuple2<I1_,I2_>,E_> *pElement =
00133 Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::lookup(t);
00134 if (!pElement)
00135 pElement = Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::fastInsert(t,m_defaultValue);
00136 return pElement->info();
00137 }
00138
00140 bool isDefined(const I1_ &i, const I2_ &j) const {
00141 return Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::member(Tuple2<I1_,I2_>(i,j));
00142 }
00143
00145 void undefine(const I1_ &i, const I2_ &j) {
00146 return Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::del(Tuple2<I1_,I2_>(i,j));
00147 }
00148
00150 HashConstIterator2D<I1_,I2_,E_,Hash1_,Hash2_> begin() const {
00151 return HashConstIterator2D<I1_,I2_,E_>(
00152 Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::begin());
00153 }
00154
00156 int size() const {
00157 return Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::size();
00158 }
00159
00161 int empty() const {
00162 return Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::empty();
00163 }
00164
00165
00167 void clear() {
00168 Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::clear();
00169 }
00170
00171 private:
00172 E_ m_defaultValue;
00173 };
00174
00175 }
00176
00177 #endif