1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 \*---------------------------------------------------------------------------*/
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 template<class Key, class Hash>
35 template<class AnyType>
36 Foam::HashSet<Key, Hash>::HashSet(const HashTable<AnyType, Key, Hash>& h)
38 HashTable<nil, Key, Hash>(h.size())
42 typename HashTable<AnyType, Key, Hash>::const_iterator cit = h.cbegin();
52 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
54 template<class Key, class Hash>
55 inline bool Foam::HashSet<Key, Hash>::operator[](const Key& key) const
61 template<class Key, class Hash>
62 bool Foam::HashSet<Key, Hash>::operator==(const HashSet<Key, Hash>& rhs) const
64 // Are all lhs elements in rhs?
65 for (const_iterator iter = this->cbegin(); iter != this->cend(); ++iter)
67 if (!rhs.found(iter.key()))
73 // Are all rhs elements in lhs?
74 for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
76 if (!found(iter.key()))
86 template<class Key, class Hash>
87 bool Foam::HashSet<Key, Hash>::operator!=(const HashSet<Key, Hash>& rhs) const
89 return !(operator==(rhs));
93 template<class Key, class Hash>
94 void Foam::HashSet<Key, Hash>::operator|=(const HashSet<Key, Hash>& rhs)
96 // Add rhs elements into lhs
97 for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
104 template<class Key, class Hash>
105 void Foam::HashSet<Key, Hash>::operator&=(const HashSet<Key, Hash>& rhs)
107 // Remove elements not also found in rhs
108 for (iterator iter = this->cbegin(); iter != this->cend(); ++iter)
110 if (!rhs.found(iter.key()))
118 template<class Key, class Hash>
119 void Foam::HashSet<Key, Hash>::operator^=(const HashSet<Key, Hash>& rhs)
121 // Add missed rhs elements, remove duplicate elements
122 for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
124 if (found(iter.key()))
136 // same as HashTable::erase()
137 template<class Key, class Hash>
138 void Foam::HashSet<Key, Hash>::operator-=(const HashSet<Key, Hash>& rhs)
140 // Remove rhs elements from lhs
141 for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
148 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
150 /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
152 template<class Key, class Hash>
153 Foam::HashSet<Key, Hash>
156 const HashSet<Key, Hash>& hash1,
157 const HashSet<Key, Hash>& hash2
160 HashSet<Key, Hash> out(hash1);
166 template<class Key, class Hash>
167 Foam::HashSet<Key, Hash>
170 const HashSet<Key, Hash>& hash1,
171 const HashSet<Key, Hash>& hash2
174 HashSet<Key, Hash> out(hash1);
180 template<class Key, class Hash>
181 Foam::HashSet<Key, Hash>
184 const HashSet<Key, Hash>& hash1,
185 const HashSet<Key, Hash>& hash2
188 HashSet<Key, Hash> out(hash1);
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 // ************************ vim: set sw=4 sts=4 et: ************************ //