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.
36 A HashSet with (the default) word keys.
42 A HashSet with default word keys.
44 \*---------------------------------------------------------------------------*/
49 #include "HashTable.H"
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 /*---------------------------------------------------------------------------*\
58 Class HashSet Declaration
59 \*---------------------------------------------------------------------------*/
61 template<class Key=word, class Hash=string::hash>
64 public HashTable<nil, Key, Hash>
69 typedef typename HashTable<nil, Key, Hash>::iterator iterator;
70 typedef typename HashTable<nil, Key, Hash>::const_iterator const_iterator;
75 //- Construct given initial size
76 explicit HashSet(const label size = 128)
78 HashTable<nil, Key, Hash>(size)
81 //- Construct from Istream
82 explicit HashSet(Istream& is)
84 HashTable<nil, Key, Hash>(is)
87 //- Construct from UList of Key
88 explicit HashSet(const UList<Key>& lst)
90 HashTable<nil, Key, Hash>(2*lst.size())
99 HashSet(const HashSet<Key, Hash>& hs)
101 HashTable<nil, Key, Hash>(hs)
104 //- Construct by transferring the parameter contents
105 explicit HashSet(const Xfer<HashSet<Key, Hash> >& hs)
107 HashTable<nil, Key, Hash>(hs)
110 //- Construct by transferring the parameter contents
111 explicit HashSet(const Xfer<HashTable<nil, Key, Hash> >& hs)
113 HashTable<nil, Key, Hash>(hs)
116 //- Construct from the keys of another HashTable,
117 // the type of values held is arbitrary.
118 template<class AnyType, class AnyHash>
119 HashSet(const HashTable<AnyType, Key, AnyHash>&);
126 //- Insert a new entry
127 bool insert(const Key& key)
129 return HashTable<nil, Key, Hash>::insert(key, nil());
132 //- Same as insert (cannot overwrite nil content)
133 bool set(const Key& key)
135 return HashTable<nil, Key, Hash>::insert(key, nil());
141 //- Return true if the entry exists, same as found()
142 inline bool operator[](const Key&) const;
144 //- Equality. Two hashtables are equal when their contents are equal.
145 // Independent of table size or order.
146 bool operator==(const HashSet<Key, Hash>&) const;
148 //- The opposite of the equality operation.
149 bool operator!=(const HashSet<Key, Hash>&) const;
152 //- Combine entries from HashSets
153 void operator|=(const HashSet<Key, Hash>&);
155 //- Only retain entries found in both HashSets
156 void operator&=(const HashSet<Key, Hash>&);
158 //- Only retain unique entries (xor)
159 void operator^=(const HashSet<Key, Hash>&);
161 //- Add entries listed in the given HashSet to this HashSet
162 inline void operator+=(const HashSet<Key, Hash>& rhs)
164 this->operator|=(rhs);
167 //- Remove entries listed in the given HashSet from this HashSet
168 void operator-=(const HashSet<Key, Hash>&);
174 //- Combine entries from HashSets
175 template<class Key, class Hash>
176 HashSet<Key,Hash> operator|
178 const HashSet<Key,Hash>& hash1,
179 const HashSet<Key,Hash>& hash2
183 //- Create a HashSet that only contains entries found in both HashSets
184 template<class Key, class Hash>
185 HashSet<Key,Hash> operator&
187 const HashSet<Key,Hash>& hash1,
188 const HashSet<Key,Hash>& hash2
192 //- Create a HashSet that only contains unique entries (xor)
193 template<class Key, class Hash>
194 HashSet<Key,Hash> operator^
196 const HashSet<Key,Hash>& hash1,
197 const HashSet<Key,Hash>& hash2
201 //- A HashSet with word keys.
202 typedef HashSet<> wordHashSet;
204 //- A HashSet with label keys.
205 typedef HashSet<label, Hash<label> > labelHashSet;
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 } // End namespace Foam
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 # include "HashSet.C"
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222 // ************************************************************************* //