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