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
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef StaticHashTable_H
00042 #define StaticHashTable_H
00043
00044 #include "label.H"
00045 #include "word.H"
00046 #include "className.H"
00047
00048
00049
00050 namespace Foam
00051 {
00052
00053
00054
00055 template<class T>
00056 class List;
00057
00058 template<class T, class Key, class Hash> class StaticHashTable;
00059
00060 template<class T, class Key, class Hash> Istream& operator>>
00061 (
00062 Istream&,
00063 StaticHashTable<T, Key, Hash>&
00064 );
00065
00066 template<class T, class Key, class Hash> Ostream& operator<<
00067 (
00068 Ostream&,
00069 const StaticHashTable<T, Key, Hash>&
00070 );
00071
00072
00073
00074
00075
00076
00077 TemplateName(StaticHashTable);
00078
00079
00080
00081
00082
00083
00084 template<class T, class Key=word, class Hash=string::hash>
00085 class StaticHashTable
00086 :
00087 public StaticHashTableName
00088 {
00089
00090
00091
00092 List<List<Key> > keys_;
00093
00094
00095 List<List<T> > objects_;
00096
00097
00098 label nElmts_;
00099
00100 public:
00101
00102
00103
00104
00105 template<class TRef, class TableRef>
00106 class Iterator;
00107
00108 typedef Iterator
00109 <
00110 T&,
00111 StaticHashTable<T, Key, Hash>&
00112 > iterator;
00113
00114 typedef Iterator
00115 <
00116 const T&,
00117 const StaticHashTable<T, Key, Hash>&
00118 > const_iterator;
00119
00120
00121
00122
00123 friend class Iterator
00124 <
00125 T&,
00126 StaticHashTable<T, Key, Hash>&
00127 >;
00128
00129 friend class Iterator
00130 <
00131 const T&,
00132 const StaticHashTable<T, Key, Hash>&
00133 >;
00134
00135
00136
00137
00138
00139 StaticHashTable(const label size);
00140
00141
00142 StaticHashTable(Istream&, const label size);
00143
00144
00145 StaticHashTable(const StaticHashTable<T, Key, Hash>&);
00146
00147
00148
00149
00150 ~StaticHashTable();
00151
00152
00153
00154
00155
00156
00157
00158 inline label size() const;
00159
00160
00161 bool found(const Key& key) const;
00162
00163
00164
00165 iterator find(const Key& key);
00166
00167
00168
00169 const_iterator find(const Key& key) const;
00170
00171
00172 List<Key> toc() const;
00173
00174
00175
00176
00177
00178 bool insert(const Key& key, const T& newElmt);
00179
00180
00181 bool erase(const iterator& it);
00182
00183
00184 bool erase(const Key& key);
00185
00186
00187 void resize(const label newSize);
00188
00189
00190 void clear();
00191
00192
00193
00194 void transfer(StaticHashTable<T, Key, Hash>&);
00195
00196
00197
00198
00199
00200 inline T& operator[](const Key& key);
00201
00202
00203 inline const T& operator[](const Key& key) const;
00204
00205
00206 void operator=(const StaticHashTable<T, Key, Hash>&);
00207
00208
00209
00210
00211
00212 typedef T value_type;
00213
00214
00215
00216 typedef T& reference;
00217
00218
00219
00220
00221 typedef const T& const_reference;
00222
00223
00224 typedef label size_type;
00225
00226
00227
00228
00229 template<class TRef, class TableRef>
00230 class Iterator
00231 {
00232 friend class StaticHashTable;
00233
00234 # ifndef __INTEL_COMPILER
00235 template<class TRef2, class TableRef2>
00236 friend class Iterator;
00237 # endif
00238
00239
00240
00241
00242 TableRef curStaticHashTable_;
00243
00244
00245 label hashIndex_;
00246
00247
00248 label elementIndex_;
00249
00250 public:
00251
00252
00253
00254
00255 inline Iterator
00256 (
00257 TableRef curStaticHashTable,
00258 label hashIndex_,
00259 label elementIndex_
00260 );
00261
00262
00263 inline Iterator(const iterator&);
00264
00265
00266
00267
00268 inline void operator=(const iterator& iter);
00269
00270 inline bool operator==(const iterator& iter) const;
00271 inline bool operator==(const const_iterator& iter) const;
00272
00273 inline bool operator!=(const iterator& iter) const;
00274 inline bool operator!=(const const_iterator& iter) const;
00275
00276 inline TRef operator*();
00277 inline TRef operator()();
00278
00279 inline Iterator& operator++();
00280 inline Iterator operator++(int);
00281
00282 inline const Key& key();
00283 };
00284
00285
00286
00287 inline iterator begin();
00288
00289
00290 inline const iterator& end();
00291
00292
00293 inline const_iterator begin() const;
00294
00295
00296 inline const const_iterator& end() const;
00297
00298
00299
00300
00301 friend Istream& operator>> <T, Key, Hash>
00302 (
00303 Istream&,
00304 StaticHashTable<T, Key, Hash>&
00305 );
00306
00307 friend Ostream& operator<< <T, Key, Hash>
00308 (
00309 Ostream&,
00310 const StaticHashTable<T, Key, Hash>&
00311 );
00312
00313
00314 private:
00315
00316
00317 iterator endIter_;
00318
00319
00320 const_iterator endConstIter_;
00321 };
00322
00323
00324
00325
00326 }
00327
00328
00329
00330 # include "StaticHashTableI.H"
00331
00332
00333
00334 #ifndef NoStaticHashTableC
00335 #ifdef NoRepository
00336 # include "StaticHashTable.C"
00337 #endif
00338 #endif
00339
00340
00341
00342 #endif
00343
00344