Fix tutorials: coupled/conjugateHeatFoam/conjugateCavity: fix Allrun file
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / containers / HashTables / HashSet / HashSet.H
blob7c073faab37017e21dd9f9ec2cc1d5ba2e34e844
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 Class
26     Foam::HashSet
28 Description
29     A HashTable with keys but without contents.
31 Typedef
32     Foam::wordHashSet
34 Description
35     A HashSet with (the default) word keys.
37 Typedef
38     Foam::labelHashSet
40 Description
41     A HashSet with label keys.
43 \*---------------------------------------------------------------------------*/
45 #ifndef HashSet_H
46 #define HashSet_H
48 #include "HashTable.H"
49 #include "nil.H"
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 namespace Foam
56 /*---------------------------------------------------------------------------*\
57                            Class HashSet Declaration
58 \*---------------------------------------------------------------------------*/
60 template<class Key=word, class Hash=string::hash>
61 class HashSet
63     public HashTable<nil, Key, Hash>
66 public:
68     typedef typename HashTable<nil, Key, Hash>::iterator iterator;
69     typedef typename HashTable<nil, Key, Hash>::const_iterator const_iterator;
72     // Constructors
74         //- Construct given initial size
75         explicit HashSet(const label size = 128)
76         :
77             HashTable<nil, Key, Hash>(size)
78         {}
80         //- Construct from Istream
81         explicit HashSet(Istream& is)
82         :
83             HashTable<nil, Key, Hash>(is)
84         {}
86         //- Construct from UList of Key
87         explicit HashSet(const UList<Key>& lst)
88         :
89             HashTable<nil, Key, Hash>(2*lst.size())
90         {
91             forAll(lst, i)
92             {
93                 insert(lst[i]);
94             }
95         }
97         //- Construct as copy
98         HashSet(const HashSet<Key, Hash>& hs)
99         :
100             HashTable<nil, Key, Hash>(hs)
101         {}
103         //- Construct by transferring the parameter contents
104         explicit HashSet(const Xfer<HashSet<Key, Hash> >& hs)
105         :
106             HashTable<nil, Key, Hash>(hs)
107         {}
109         //- Construct by transferring the parameter contents
110         explicit HashSet(const Xfer<HashTable<nil, Key, Hash> >& hs)
111         :
112             HashTable<nil, Key, Hash>(hs)
113         {}
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>&);
121     // Member Functions
123         // Edit
125         //- Insert a new entry
126         bool insert(const Key& key)
127         {
128             return HashTable<nil, Key, Hash>::insert(key, nil());
129         }
131         //- Same as insert (cannot overwrite nil content)
132         bool set(const Key& key)
133         {
134             return HashTable<nil, Key, Hash>::insert(key, nil());
135         }
138     // Member Operators
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)
162         {
163             this->operator|=(rhs);
164         }
166         //- Remove entries listed in the given HashSet from this HashSet
167         void operator-=(const HashSet<Key, Hash>&);
171 // Global Operators
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 #ifdef NoRepository
214 #   include "HashSet.C"
215 #endif
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 #endif
221 // ************************************************************************* //