FreeFOAM The Cross-Platform CFD Toolkit
HashSet.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #ifndef HashSet_C
27 #define HashSet_C
28 
29 #include "HashSet.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class Key, class Hash>
34 template<class AnyType, class AnyHash>
36 (
38 )
39 :
41 {
42  for
43  (
45  cit = h.cbegin();
46  cit != h.cend();
47  ++cit
48  )
49  {
50  insert(cit.key());
51  }
52 }
53 
54 
55 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
56 
57 template<class Key, class Hash>
58 inline bool Foam::HashSet<Key, Hash>::operator[](const Key& key) const
59 {
60  return found(key);
61 }
62 
63 
64 template<class Key, class Hash>
66 {
67  // Are all lhs elements in rhs?
68  for (const_iterator iter = this->cbegin(); iter != this->cend(); ++iter)
69  {
70  if (!rhs.found(iter.key()))
71  {
72  return false;
73  }
74  }
75 
76  // Are all rhs elements in lhs?
77  for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
78  {
79  if (!found(iter.key()))
80  {
81  return false;
82  }
83  }
84 
85  return true;
86 }
87 
88 
89 template<class Key, class Hash>
91 {
92  return !(operator==(rhs));
93 }
94 
95 
96 template<class Key, class Hash>
98 {
99  // Add rhs elements into lhs
100  for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
101  {
102  insert(iter.key());
103  }
104 }
105 
106 
107 template<class Key, class Hash>
109 {
110  // Remove elements not also found in rhs
111  for (iterator iter = this->begin(); iter != this->end(); ++iter)
112  {
113  if (!rhs.found(iter.key()))
114  {
115  erase(iter);
116  }
117  }
118 }
119 
120 
121 template<class Key, class Hash>
123 {
124  // Add missed rhs elements, remove duplicate elements
125  for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
126  {
127  if (found(iter.key()))
128  {
129  erase(iter.key());
130  }
131  else
132  {
133  insert(iter.key());
134  }
135  }
136 }
137 
138 
139 // same as HashTable::erase()
140 template<class Key, class Hash>
142 {
143  // Remove rhs elements from lhs
144  for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
145  {
146  erase(iter.key());
147  }
148 }
149 
150 
151 /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
152 
153 template<class Key, class Hash>
155 Foam::operator|
156 (
157  const HashSet<Key, Hash>& hash1,
158  const HashSet<Key, Hash>& hash2
159 )
160 {
161  HashSet<Key, Hash> out(hash1);
162  out |= hash2;
163  return out;
164 }
165 
166 
167 template<class Key, class Hash>
169 Foam::operator&
170 (
171  const HashSet<Key, Hash>& hash1,
172  const HashSet<Key, Hash>& hash2
173 )
174 {
175  HashSet<Key, Hash> out(hash1);
176  out &= hash2;
177  return out;
178 }
179 
180 
181 template<class Key, class Hash>
183 Foam::operator^
184 (
185  const HashSet<Key, Hash>& hash1,
186  const HashSet<Key, Hash>& hash2
187 )
188 {
189  HashSet<Key, Hash> out(hash1);
190  out ^= hash2;
191  return out;
192 }
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 #endif
197 
198 // ************************ vim: set sw=4 sts=4 et: ************************ //