1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
28 #include "IOstreams.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 // * * * * * * * * * * * * * Private Member Classes * * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
40 template<class T, class Key, class Hash>
41 inline label StaticHashTable<T, Key, Hash>::size() const
47 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
49 template<class T, class Key, class Hash>
50 inline T& StaticHashTable<T, Key, Hash>::operator[](const Key& key)
52 iterator iter = find(key);
56 FatalErrorIn("StaticHashTable<T, Key, Hash>::operator[](const Key&)")
57 << key << " not found in table. Valid entries are "
65 template<class T, class Key, class Hash>
66 inline const T& StaticHashTable<T, Key, Hash>::operator[](const Key& key) const
68 const_iterator iter = find(key);
74 "StaticHashTable<T, Key, Hash>::operator[](const Key&) const"
75 ) << key << " not found in table. Valid entries are "
84 // * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
86 template<class T, class Key, class Hash>
87 template<class TRef, class TableRef>
88 inline StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
91 TableRef curStaticHashTable,
96 curStaticHashTable_(curStaticHashTable),
97 hashIndex_(hashIndex),
98 elementIndex_(elementIndex)
102 template<class T, class Key, class Hash>
103 template<class TRef, class TableRef>
104 inline StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
105 Iterator(const iterator& iter)
107 curStaticHashTable_(iter.curStaticHashTable_),
108 hashIndex_(iter.hashIndex_),
109 elementIndex_(iter.elementIndex_)
113 template<class T, class Key, class Hash>
114 template<class TRef, class TableRef>
115 inline void StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
116 operator=(const iterator& iter)
118 this->hashIndex_ = iter.hashIndex_;
119 this->elementIndex_ = iter.elementIndex_;
123 template<class T, class Key, class Hash>
124 template<class TRef, class TableRef>
125 inline bool StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
126 operator==(const iterator& iter) const
128 return hashIndex_ == iter.hashIndex_ && elementIndex_ == iter.elementIndex_;
131 template<class T, class Key, class Hash>
132 template<class TRef, class TableRef>
133 inline bool StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
134 operator==(const const_iterator& iter) const
136 return hashIndex_ == iter.hashIndex_ && elementIndex_ == iter.elementIndex_;
140 template<class T, class Key, class Hash>
141 template<class TRef, class TableRef>
142 inline bool StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
143 operator!=(const iterator& iter) const
145 return !operator==(iter);
148 template<class T, class Key, class Hash>
149 template<class TRef, class TableRef>
150 inline bool StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
151 operator!=(const const_iterator& iter) const
153 return !operator==(iter);
157 template<class T, class Key, class Hash>
158 template<class TRef, class TableRef>
159 inline TRef StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
162 return curStaticHashTable_.objects_[hashIndex_][elementIndex_];
166 template<class T, class Key, class Hash>
167 template<class TRef, class TableRef>
168 inline TRef StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
175 template<class T, class Key, class Hash>
176 template<class TRef, class TableRef>
178 typename StaticHashTable<T, Key, Hash>::template Iterator
183 StaticHashTable<T, Key, Hash>::Iterator
189 const List<T>& localObjects = curStaticHashTable_.objects_[hashIndex_];
191 if (elementIndex_ == localObjects.size()-1)
195 // Find first non-zero entry
199 hashIndex_ < curStaticHashTable_.objects_.size();
203 if (curStaticHashTable_.objects_[hashIndex_].size() > 0)
218 template<class T, class Key, class Hash>
219 template<class TRef, class TableRef>
221 typename StaticHashTable<T, Key, Hash>::template Iterator
226 StaticHashTable<T, Key, Hash>::Iterator
235 iterator tmp = *this;
241 template<class T, class Key, class Hash>
242 template<class TRef, class TableRef>
244 const Key& StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
247 return curStaticHashTable_.keys_[hashIndex_][elementIndex_];
251 template<class T, class Key, class Hash>
252 inline typename StaticHashTable<T, Key, Hash>::iterator
253 StaticHashTable<T, Key, Hash>::begin()
255 // Find first non-empty entry
258 if (keys_[i].size() > 0)
260 return iterator(*this, i, 0);
267 Info<< "StaticHashTable is empty\n";
271 return StaticHashTable<T, Key, Hash>::endIter_;
275 template<class T, class Key, class Hash>
276 inline const typename StaticHashTable<T, Key, Hash>::iterator&
277 StaticHashTable<T, Key, Hash>::end()
279 return StaticHashTable<T, Key, Hash>::endIter_;
283 template<class T, class Key, class Hash>
284 inline typename StaticHashTable<T, Key, Hash>::const_iterator
285 StaticHashTable<T, Key, Hash>::begin() const
287 // Find first non-empty entry
290 if (keys_[i].size() > 0)
292 return const_iterator(*this, i, 0);
299 Info<< "StaticHashTable is empty\n";
303 return StaticHashTable<T, Key, Hash>::endConstIter_;
307 template<class T, class Key, class Hash>
308 inline const typename StaticHashTable<T, Key, Hash>::const_iterator&
309 StaticHashTable<T, Key, Hash>::end() const
311 return StaticHashTable<T, Key, Hash>::endConstIter_;
315 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
317 } // End namespace Foam
319 // ************************************************************************* //