1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 template<class Key, class Hash>
34 template<class AnyType, class AnyHash>
35 Foam::HashSet<Key, Hash>::HashSet
37 const HashTable<AnyType, Key, AnyHash>& h
40 HashTable<nil, Key, Hash>(h.size())
44 typename HashTable<AnyType, Key, AnyHash>::const_iterator
50 this->insert(cit.key());
55 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57 template<class Key, class Hash>
58 Foam::label Foam::HashSet<Key, Hash>::insert(const UList<Key>& lst)
63 if (this->insert(lst[elemI]))
73 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
75 template<class Key, class Hash>
76 inline bool Foam::HashSet<Key, Hash>::operator[](const Key& key) const
78 return this->found(key);
82 template<class Key, class Hash>
83 bool Foam::HashSet<Key, Hash>::operator==(const HashSet<Key, Hash>& rhs) const
85 // Are all lhs elements in rhs?
86 for (const_iterator iter = this->cbegin(); iter != this->cend(); ++iter)
88 if (!rhs.found(iter.key()))
94 // Are all rhs elements in lhs?
95 for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
97 if (!this->found(iter.key()))
107 template<class Key, class Hash>
108 bool Foam::HashSet<Key, Hash>::operator!=(const HashSet<Key, Hash>& rhs) const
110 return !(operator==(rhs));
114 template<class Key, class Hash>
115 void Foam::HashSet<Key, Hash>::operator|=(const HashSet<Key, Hash>& rhs)
117 // Add rhs elements into lhs
118 for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
120 this->insert(iter.key());
125 template<class Key, class Hash>
126 void Foam::HashSet<Key, Hash>::operator&=(const HashSet<Key, Hash>& rhs)
128 // Remove elements not also found in rhs
129 for (iterator iter = this->begin(); iter != this->end(); ++iter)
131 if (!rhs.found(iter.key()))
139 template<class Key, class Hash>
140 void Foam::HashSet<Key, Hash>::operator^=(const HashSet<Key, Hash>& rhs)
142 // Add missed rhs elements, remove duplicate elements
143 for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
145 if (this->found(iter.key()))
147 this->erase(iter.key());
151 this->insert(iter.key());
157 // same as HashTable::erase()
158 template<class Key, class Hash>
159 void Foam::HashSet<Key, Hash>::operator-=(const HashSet<Key, Hash>& rhs)
161 // Remove rhs elements from lhs
162 for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
164 this->erase(iter.key());
169 /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
171 template<class Key, class Hash>
172 Foam::HashSet<Key, Hash>
175 const HashSet<Key, Hash>& hash1,
176 const HashSet<Key, Hash>& hash2
179 HashSet<Key, Hash> out(hash1);
185 template<class Key, class Hash>
186 Foam::HashSet<Key, Hash>
189 const HashSet<Key, Hash>& hash1,
190 const HashSet<Key, Hash>& hash2
193 HashSet<Key, Hash> out(hash1);
199 template<class Key, class Hash>
200 Foam::HashSet<Key, Hash>
203 const HashSet<Key, Hash>& hash1,
204 const HashSet<Key, Hash>& hash2
207 HashSet<Key, Hash> out(hash1);
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 // ************************************************************************* //