Open
Graph Drawing
Framework

 v.2012.05
 

HashArray2D.h
Go to the documentation of this file.
00001 /*
00002  * $Revision: 2299 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2012-05-07 15:57:08 +0200 (Mon, 07 May 2012) $ 
00007  ***************************************************************/
00008  
00047 #ifdef _MSC_VER
00048 #pragma once
00049 #endif
00050 
00051 #include <ogdf/basic/HashArray.h>
00052 #include <ogdf/basic/tuples.h>
00053 #include <ogdf/basic/HashIterator2D.h>
00054 
00055 #ifndef OGDF_HASHARRAY2D_H
00056 #define OGDF_HASHARRAY2D_H
00057 
00058 
00059 namespace ogdf {
00060 
00061 
00075 template< class I1_, class I2_, class E_,
00076     class Hash1_ = DefHashFunc<I1_>,
00077     class Hash2_ = DefHashFunc<I2_> >
00078 class HashArray2D : private Hashing<Tuple2<I1_,I2_>, E_,
00079     HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >
00080 {
00081 public:
00083     typedef HashConstIterator2D<I1_,I2_,E_,Hash1_,Hash2_> const_iterator;
00084 
00086     HashArray2D() /*: m_size(0)*/ {}
00087 
00089     HashArray2D(const E_ &defaultValue,
00090         const Hash1_ &hashFunc1 = Hash1_(),
00091         const Hash2_ &hashFunc2 = Hash2_())
00092         : Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >(256,
00093             HashFuncTuple<I1_,I2_,Hash1_,Hash2_>(hashFunc1,hashFunc2)),
00094         m_defaultValue(defaultValue) {}
00095 
00097     HashArray2D(const HashArray2D<I1_,I2_,E_,Hash1_,Hash2_> &A) :
00098         Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >(A),
00099             m_defaultValue(A.m_defaultValue) { }
00100 
00102     HashArray2D &operator=(const HashArray2D<I1_,I2_,E_,Hash1_,Hash2_> &A) {
00103         m_defaultValue = A.m_defaultValue;
00104         Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::operator=(A);
00105 
00106         return *this;
00107     }
00108 
00109     ~HashArray2D(){};
00110 
00112     const E_ &operator()(const I1_ &i, const I2_ &j) const {
00113         HashElement<Tuple2<I1_,I2_>,E_> *pElement =
00114             Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::lookup(Tuple2<I1_,I2_>(i,j));
00115         if (pElement) return pElement->info();
00116         else return m_defaultValue;
00117     }
00118 
00120     E_ &operator()(const I1_ &i, const I2_ &j) {
00121         Tuple2<I1_,I2_> t(i,j);
00122         HashElement<Tuple2<I1_,I2_>,E_> *pElement =
00123             Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::lookup(t);
00124         if (!pElement)
00125             pElement = Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::fastInsert(t,m_defaultValue);
00126         return pElement->info();
00127     }
00128 
00130     bool isDefined(const I1_ &i, const I2_ &j) const {
00131         return Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::member(Tuple2<I1_,I2_>(i,j));
00132     }
00133 
00135     void undefine(const I1_ &i, const I2_ &j) {
00136         return Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::del(Tuple2<I1_,I2_>(i,j));
00137     }
00138 
00140     HashConstIterator2D<I1_,I2_,E_,Hash1_,Hash2_> begin() const {
00141         return HashConstIterator2D<I1_,I2_,E_>(
00142             Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::begin());
00143     }
00144 
00146     int size() const {
00147         return Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::size();
00148     }
00149     
00151     int empty() const { 
00152         return Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::empty();
00153     }
00154 
00155 
00157     void clear() {
00158         Hashing<Tuple2<I1_,I2_>,E_,HashFuncTuple<I1_,I2_,Hash1_,Hash2_> >::clear();
00159     }
00160 
00161 private:
00162     E_ m_defaultValue; 
00163 };
00164 
00165 }
00166 
00167 #endif