Newer
Older
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
-------------------------------------------------------------------------------
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * iterator base * * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
template<bool Const>
inline constexpr
Foam::HashTable<T, Key, Hash>::Iterator<Const>::Iterator() noexcept
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
:
entry_(nullptr),
container_(nullptr),
index_(0)
{}
template<class T, class Key, class Hash>
template<bool Const>
inline Foam::HashTable<T, Key, Hash>::Iterator<Const>::Iterator
(
table_type* tbl
)
:
entry_(nullptr),
container_(tbl),
index_(0)
{
if (container_ && container_->size_)
{
// Locate the first non-nullptr table entry
while
(
!(entry_ = container_->table_[index_])
&& ++index_ < container_->capacity_
)
{}
if (index_ >= container_->capacity_)
{
// Nothing found - make it an end iterator
entry_ = nullptr;
index_ = 0;
}
}
}
//
// Any changes here may need changes in iterator_erase() method too
//
template<class T, class Key, class Hash>
template<bool Const>
inline void
Foam::HashTable<T, Key, Hash>::Iterator<Const>::increment()
{
if (index_ < 0)
{
// Negative index is a special value from erase
//
// Saved as (-index-1), retrieved as (-(index-1)) but to with an
// extra (-1) to compensate for the ++ in the following while loop
index_ = -(index_+1) - 1;
}
else if (index_ < container_->capacity_ && entry_ && entry_->next_)
{
// Move to next element on the linked-list
entry_ = entry_->next_;
return;
}
// Move to the next non-nullptr table entry
while
(
++index_ < container_->capacity_
&& !(entry_ = container_->table_[index_])
)
{}
if (index_ >= container_->capacity_)
{
// Nothing found - make it an end iterator
entry_ = nullptr;
index_ = 0;
}
}
template<class T, class Key, class Hash>
template<bool Const>
inline bool
Foam::HashTable<T, Key, Hash>::Iterator<Const>::good() const noexcept
{
return entry_;
}
template<class T, class Key, class Hash>
template<bool Const>
inline bool
Foam::HashTable<T, Key, Hash>::Iterator<Const>::found() const noexcept
{
return entry_;
}
template<class T, class Key, class Hash>
template<bool Const>
inline const Key& Foam::HashTable<T, Key, Hash>::Iterator<Const>::key() const
{
return entry_->key();
}
template<class T, class Key, class Hash>
template<bool Const>
inline Foam::Ostream& Foam::HashTable<T, Key, Hash>::Iterator<Const>::print
(
Ostream& os
) const
{
if (entry_)
{
entry_->print(os);
}
return os;
}
template<class T, class Key, class Hash>
template<bool Const>
inline Foam::HashTable<T, Key, Hash>::Iterator<Const>::operator
bool() const noexcept
{
return entry_;
}
template<class T, class Key, class Hash>
template<bool Const>
template<bool Any>
inline bool Foam::HashTable<T, Key, Hash>::Iterator<Const>::operator==
(
const Iterator<Any>& iter
) const noexcept
{
return entry_ == iter.entry_;
}
template<class T, class Key, class Hash>
template<bool Const>
template<bool Any>
inline bool Foam::HashTable<T, Key, Hash>::Iterator<Const>::operator!=
(
const Iterator<Any>& iter
) const noexcept
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
{
return entry_ != iter.entry_;
}
// * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline typename Foam::HashTable<T, Key, Hash>::iterator&
Foam::HashTable<T, Key, Hash>::iterator::operator++()
{
this->increment();
return *this;
}
template<class T, class Key, class Hash>
inline typename Foam::HashTable<T, Key, Hash>::iterator
Foam::HashTable<T, Key, Hash>::iterator::operator++(int)
{
iterator iter(*this);
this->increment();
return iter;
}
// * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline typename Foam::HashTable<T, Key, Hash>::const_iterator&
Foam::HashTable<T, Key, Hash>::const_iterator::operator++()
{
this->increment();
return *this;
}
template<class T, class Key, class Hash>
inline typename Foam::HashTable<T, Key, Hash>::const_iterator
Foam::HashTable<T, Key, Hash>::const_iterator::operator++(int)
{
const_iterator iter(*this);
this->increment();
return iter;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline typename Foam::HashTable<T, Key, Hash>::iterator
Foam::HashTable<T, Key, Hash>::begin()
{
return iterator(Iterator<false>(this));
}
template<class T, class Key, class Hash>
inline typename Foam::HashTable<T, Key, Hash>::const_iterator
Foam::HashTable<T, Key, Hash>::begin() const
{
return const_iterator(Iterator<true>(this));
}
template<class T, class Key, class Hash>
inline typename Foam::HashTable<T, Key, Hash>::const_iterator
Foam::HashTable<T, Key, Hash>::cbegin() const
{
return const_iterator(Iterator<true>(this));
}
template<class T, class Key, class Hash>
inline typename Foam::HashTable<T, Key, Hash>::iterator
Foam::HashTable<T, Key, Hash>::end() noexcept
return iterator();
}
template<class T, class Key, class Hash>
inline typename Foam::HashTable<T, Key, Hash>::const_iterator
Foam::HashTable<T, Key, Hash>::end() const noexcept
return const_iterator();
}
template<class T, class Key, class Hash>
inline constexpr typename Foam::HashTable<T, Key, Hash>::const_iterator
Foam::HashTable<T, Key, Hash>::cend() const noexcept
return const_iterator();
}
// ************************************************************************* //