00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "error.H"
00034 #include "IOstreams.H"
00035
00036
00037
00038 namespace Foam
00039 {
00040
00041
00042
00043
00044
00045
00046 template<class T, class Key, class Hash>
00047 inline label StaticHashTable<T, Key, Hash>::size() const
00048 {
00049 return nElmts_;
00050 }
00051
00052
00053
00054
00055 template<class T, class Key, class Hash>
00056 inline T& StaticHashTable<T, Key, Hash>::operator[](const Key& key)
00057 {
00058 iterator iter = find(key);
00059
00060 if (iter == end())
00061 {
00062 FatalErrorIn("StaticHashTable<T, Key, Hash>::operator[](const Key&)")
00063 << key << " not found in table. Valid entries are "
00064 << toc()
00065 << exit(FatalError);
00066 }
00067
00068 return *iter;
00069 }
00070
00071 template<class T, class Key, class Hash>
00072 inline const T& StaticHashTable<T, Key, Hash>::operator[](const Key& key) const
00073 {
00074 const_iterator iter = find(key);
00075
00076 if (iter == end())
00077 {
00078 FatalErrorIn
00079 (
00080 "StaticHashTable<T, Key, Hash>::operator[](const Key&) const"
00081 ) << key << " not found in table. Valid entries are "
00082 << toc()
00083 << exit(FatalError);
00084 }
00085
00086 return *iter;
00087 }
00088
00089
00090
00091
00092 template<class T, class Key, class Hash>
00093 template<class TRef, class TableRef>
00094 inline StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
00095 Iterator
00096 (
00097 TableRef curStaticHashTable,
00098 label hashIndex,
00099 label elementIndex
00100 )
00101 :
00102 curStaticHashTable_(curStaticHashTable),
00103 hashIndex_(hashIndex),
00104 elementIndex_(elementIndex)
00105 {}
00106
00107
00108 template<class T, class Key, class Hash>
00109 template<class TRef, class TableRef>
00110 inline StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
00111 Iterator(const iterator& iter)
00112 :
00113 curStaticHashTable_(iter.curStaticHashTable_),
00114 hashIndex_(iter.hashIndex_),
00115 elementIndex_(iter.elementIndex_)
00116 {}
00117
00118
00119 template<class T, class Key, class Hash>
00120 template<class TRef, class TableRef>
00121 inline void StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
00122 operator=(const iterator& iter)
00123 {
00124 this->hashIndex_ = iter.hashIndex_;
00125 this->elementIndex_ = iter.elementIndex_;
00126 }
00127
00128
00129 template<class T, class Key, class Hash>
00130 template<class TRef, class TableRef>
00131 inline bool StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
00132 operator==(const iterator& iter) const
00133 {
00134 return hashIndex_ == iter.hashIndex_ && elementIndex_ == iter.elementIndex_;
00135 }
00136
00137 template<class T, class Key, class Hash>
00138 template<class TRef, class TableRef>
00139 inline bool StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
00140 operator==(const const_iterator& iter) const
00141 {
00142 return hashIndex_ == iter.hashIndex_ && elementIndex_ == iter.elementIndex_;
00143 }
00144
00145
00146 template<class T, class Key, class Hash>
00147 template<class TRef, class TableRef>
00148 inline bool StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
00149 operator!=(const iterator& iter) const
00150 {
00151 return !operator==(iter);
00152 }
00153
00154 template<class T, class Key, class Hash>
00155 template<class TRef, class TableRef>
00156 inline bool StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
00157 operator!=(const const_iterator& iter) const
00158 {
00159 return !operator==(iter);
00160 }
00161
00162
00163 template<class T, class Key, class Hash>
00164 template<class TRef, class TableRef>
00165 inline TRef StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
00166 operator*()
00167 {
00168 return curStaticHashTable_.objects_[hashIndex_][elementIndex_];
00169 }
00170
00171
00172 template<class T, class Key, class Hash>
00173 template<class TRef, class TableRef>
00174 inline TRef StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
00175 operator()()
00176 {
00177 return operator*();
00178 }
00179
00180
00181 template<class T, class Key, class Hash>
00182 template<class TRef, class TableRef>
00183 inline
00184 typename StaticHashTable<T, Key, Hash>::template Iterator
00185 <
00186 TRef,
00187 TableRef
00188 >&
00189 StaticHashTable<T, Key, Hash>::Iterator
00190 <
00191 TRef,
00192 TableRef
00193 >::operator++()
00194 {
00195 const List<T>& localObjects = curStaticHashTable_.objects_[hashIndex_];
00196
00197 if (elementIndex_ == localObjects.size()-1)
00198 {
00199 elementIndex_ = 0;
00200
00201
00202 for
00203 (
00204 hashIndex_++;
00205 hashIndex_ < curStaticHashTable_.objects_.size();
00206 hashIndex_++
00207 )
00208 {
00209 if (curStaticHashTable_.objects_[hashIndex_].size() > 0)
00210 {
00211 break;
00212 }
00213 }
00214 }
00215 else
00216 {
00217 elementIndex_++;
00218 }
00219
00220 return *this;
00221 }
00222
00223
00224 template<class T, class Key, class Hash>
00225 template<class TRef, class TableRef>
00226 inline
00227 typename StaticHashTable<T, Key, Hash>::template Iterator
00228 <
00229 TRef,
00230 TableRef
00231 >
00232 StaticHashTable<T, Key, Hash>::Iterator
00233 <
00234 TRef,
00235 TableRef
00236 >::operator++
00237 (
00238 int
00239 )
00240 {
00241 iterator tmp = *this;
00242 ++*this;
00243 return tmp;
00244 }
00245
00246
00247 template<class T, class Key, class Hash>
00248 template<class TRef, class TableRef>
00249 inline
00250 const Key& StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
00251 key()
00252 {
00253 return curStaticHashTable_.keys_[hashIndex_][elementIndex_];
00254 }
00255
00256
00257 template<class T, class Key, class Hash>
00258 inline typename StaticHashTable<T, Key, Hash>::iterator
00259 StaticHashTable<T, Key, Hash>::begin()
00260 {
00261
00262 forAll(keys_, i)
00263 {
00264 if (keys_[i].size() > 0)
00265 {
00266 return iterator(*this, i, 0);
00267 }
00268 }
00269
00270 # ifdef FULLDEBUG
00271 if (debug)
00272 {
00273 Info<< "StaticHashTable is empty\n";
00274 }
00275 # endif
00276
00277 return StaticHashTable<T, Key, Hash>::endIter_;
00278 }
00279
00280
00281 template<class T, class Key, class Hash>
00282 inline const typename StaticHashTable<T, Key, Hash>::iterator&
00283 StaticHashTable<T, Key, Hash>::end()
00284 {
00285 return StaticHashTable<T, Key, Hash>::endIter_;
00286 }
00287
00288
00289 template<class T, class Key, class Hash>
00290 inline typename StaticHashTable<T, Key, Hash>::const_iterator
00291 StaticHashTable<T, Key, Hash>::begin() const
00292 {
00293
00294 forAll(keys_, i)
00295 {
00296 if (keys_[i].size() > 0)
00297 {
00298 return const_iterator(*this, i, 0);
00299 }
00300 }
00301
00302 # ifdef FULLDEBUG
00303 if (debug)
00304 {
00305 Info<< "StaticHashTable is empty\n";
00306 }
00307 # endif
00308
00309 return StaticHashTable<T, Key, Hash>::endConstIter_;
00310 }
00311
00312
00313 template<class T, class Key, class Hash>
00314 inline const typename StaticHashTable<T, Key, Hash>::const_iterator&
00315 StaticHashTable<T, Key, Hash>::end() const
00316 {
00317 return StaticHashTable<T, Key, Hash>::endConstIter_;
00318 }
00319
00320
00321
00322
00323 }
00324
00325