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
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 HashSet(const label size = 128)
77 HashTable<nil, Key, Hash>(size)
80 //- Construct from Istream
83 HashTable<nil, Key, Hash>(is)
86 //- Construct from UList of Key
87 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 HashSet(const Xfer<HashSet<Key, Hash> >& hs)
106 HashTable<nil, Key, Hash>(hs)
109 //- Construct by transferring the parameter contents
110 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>
118 HashSet(const HashTable<AnyType, Key, Hash>&);
124 //- Insert a new entry
125 bool insert(const Key& key)
127 return HashTable<nil, Key, Hash>::insert(key, nil());
130 //- Same as insert (cannot overwrite nil content)
131 bool set(const Key& key)
133 return HashTable<nil, Key, Hash>::insert(key, nil());
138 //- Return true if the entry exists, same as found()
139 inline bool operator[](const Key&) const;
141 //- Equality. Two hashtables are equal when their contents are equal.
142 // Independent of table size or order.
143 bool operator==(const HashSet<Key, Hash>&) const;
145 //- The opposite of the equality operation.
146 bool operator!=(const HashSet<Key, Hash>&) const;
149 //- Combine entries from HashSets
150 void operator|=(const HashSet<Key, Hash>&);
152 //- Only retain entries found in both HashSets
153 void operator&=(const HashSet<Key, Hash>&);
155 //- Only retain unique entries (xor)
156 void operator^=(const HashSet<Key, Hash>&);
158 //- Add entries listed in the given HashSet to this HashSet
159 inline void operator+=(const HashSet<Key, Hash>& rhs)
161 this->operator|=(rhs);
164 //- Remove entries listed in the given HashSet from this HashSet
165 void operator-=(const HashSet<Key, Hash>&);
172 //- Combine entries from HashSets
173 template<class Key, class Hash>
174 HashSet<Key,Hash> operator|
176 const HashSet<Key,Hash>& hash1,
177 const HashSet<Key,Hash>& hash2
181 //- Create a HashSet that only contains entries found in both HashSets
182 template<class Key, class Hash>
183 HashSet<Key,Hash> operator&
185 const HashSet<Key,Hash>& hash1,
186 const HashSet<Key,Hash>& hash2
190 //- Create a HashSet that only contains unique entries (xor)
191 template<class Key, class Hash>
192 HashSet<Key,Hash> operator^
194 const HashSet<Key,Hash>& hash1,
195 const HashSet<Key,Hash>& hash2
199 //- A HashSet with word keys.
200 typedef HashSet<> wordHashSet;
202 //- A HashSet with label keys.
203 typedef HashSet<label, Hash<label> > labelHashSet;
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 } // End namespace Foam
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 # include "HashSet.C"
216 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 // ************************************************************************* //