1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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
29 A HashTable with keys but without contents.
35 A HashSet with (the default) word keys.
41 A HashSet with label keys.
43 \*---------------------------------------------------------------------------*/
48 #include "HashTable.H"
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 /*---------------------------------------------------------------------------*\
57 Class HashSet Declaration
58 \*---------------------------------------------------------------------------*/
60 template<class Key=word, class Hash=string::hash>
63 public HashTable<nil, Key, Hash>
68 typedef typename HashTable<nil, Key, Hash>::iterator iterator;
69 typedef typename HashTable<nil, Key, Hash>::const_iterator const_iterator;
74 //- Construct given initial size
75 explicit HashSet(const label size = 128)
77 HashTable<nil, Key, Hash>(size)
80 //- Construct from Istream
81 explicit HashSet(Istream& is)
83 HashTable<nil, Key, Hash>(is)
86 //- Construct from UList of Key
87 explicit HashSet(const UList<Key>& lst)
89 HashTable<nil, Key, Hash>(2*lst.size())
98 HashSet(const HashSet<Key, Hash>& hs)
100 HashTable<nil, Key, Hash>(hs)
103 //- Construct by transferring the parameter contents
104 explicit HashSet(const Xfer<HashSet<Key, Hash> >& hs)
106 HashTable<nil, Key, Hash>(hs)
109 //- Construct by transferring the parameter contents
110 explicit HashSet(const Xfer<HashTable<nil, Key, Hash> >& hs)
112 HashTable<nil, Key, Hash>(hs)
115 //- Construct from the keys of another HashTable,
116 // the type of values held is arbitrary.
117 template<class AnyType, class AnyHash>
118 HashSet(const HashTable<AnyType, Key, AnyHash>&);
125 //- Insert a new entry
126 bool insert(const Key& key)
128 return HashTable<nil, Key, Hash>::insert(key, nil());
131 //- Same as insert (cannot overwrite nil content)
132 bool set(const Key& key)
134 return HashTable<nil, Key, Hash>::insert(key, nil());
140 //- Return true if the entry exists, same as found()
141 inline bool operator[](const Key&) const;
143 //- Equality. Two hashtables are equal when their contents are equal.
144 // Independent of table size or order.
145 bool operator==(const HashSet<Key, Hash>&) const;
147 //- The opposite of the equality operation.
148 bool operator!=(const HashSet<Key, Hash>&) const;
151 //- Combine entries from HashSets
152 void operator|=(const HashSet<Key, Hash>&);
154 //- Only retain entries found in both HashSets
155 void operator&=(const HashSet<Key, Hash>&);
157 //- Only retain unique entries (xor)
158 void operator^=(const HashSet<Key, Hash>&);
160 //- Add entries listed in the given HashSet to this HashSet
161 inline void operator+=(const HashSet<Key, Hash>& rhs)
163 this->operator|=(rhs);
166 //- Remove entries listed in the given HashSet from this HashSet
167 void operator-=(const HashSet<Key, Hash>&);
173 //- Combine entries from HashSets
174 template<class Key, class Hash>
175 HashSet<Key,Hash> operator|
177 const HashSet<Key,Hash>& hash1,
178 const HashSet<Key,Hash>& hash2
182 //- Create a HashSet that only contains entries found in both HashSets
183 template<class Key, class Hash>
184 HashSet<Key,Hash> operator&
186 const HashSet<Key,Hash>& hash1,
187 const HashSet<Key,Hash>& hash2
191 //- Create a HashSet that only contains unique entries (xor)
192 template<class Key, class Hash>
193 HashSet<Key,Hash> operator^
195 const HashSet<Key,Hash>& hash1,
196 const HashSet<Key,Hash>& hash2
200 //- A HashSet with word keys.
201 typedef HashSet<> wordHashSet;
203 //- A HashSet with label keys.
204 typedef HashSet<label, Hash<label> > labelHashSet;
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 } // End namespace Foam
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 # include "HashSet.C"
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 // ************************************************************************* //