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