fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / containers / HashTables / HashSet / HashSet.H
blobeb5736c34285ce6395b050d97b039c4138e00b51
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
33     Foam::labelHashSet
35 Description
36     A HashSet with (the default) word keys.
38 Typedef
39     Foam::HashSet
41 Description
42     A HashSet with default word keys.
44 \*---------------------------------------------------------------------------*/
46 #ifndef HashSet_H
47 #define HashSet_H
49 #include "HashTable.H"
50 #include "nil.H"
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 namespace Foam
57 /*---------------------------------------------------------------------------*\
58                            Class HashSet Declaration
59 \*---------------------------------------------------------------------------*/
61 template<class Key=word, class Hash=string::hash>
62 class HashSet
64     public HashTable<nil, Key, Hash>
67 public:
69     typedef typename HashTable<nil, Key, Hash>::iterator iterator;
70     typedef typename HashTable<nil, Key, Hash>::const_iterator const_iterator;
73     // Constructors
75         //- Construct given initial size
76         explicit HashSet(const label size = 128)
77         :
78             HashTable<nil, Key, Hash>(size)
79         {}
81         //- Construct from Istream
82         explicit HashSet(Istream& is)
83         :
84             HashTable<nil, Key, Hash>(is)
85         {}
87         //- Construct from UList of Key
88         explicit HashSet(const UList<Key>& lst)
89         :
90             HashTable<nil, Key, Hash>(2*lst.size())
91         {
92             forAll(lst, i)
93             {
94                 insert(lst[i]);
95             }
96         }
98         //- Construct as copy
99         HashSet(const HashSet<Key, Hash>& hs)
100         :
101             HashTable<nil, Key, Hash>(hs)
102         {}
104         //- Construct by transferring the parameter contents
105         explicit HashSet(const Xfer<HashSet<Key, Hash> >& hs)
106         :
107             HashTable<nil, Key, Hash>(hs)
108         {}
110         //- Construct by transferring the parameter contents
111         explicit HashSet(const Xfer<HashTable<nil, Key, Hash> >& hs)
112         :
113             HashTable<nil, Key, Hash>(hs)
114         {}
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>&);
122     // Member Functions
124         // Edit
126         //- Insert a new entry
127         bool insert(const Key& key)
128         {
129             return HashTable<nil, Key, Hash>::insert(key, nil());
130         }
132         //- Same as insert (cannot overwrite nil content)
133         bool set(const Key& key)
134         {
135             return HashTable<nil, Key, Hash>::insert(key, nil());
136         }
139     // Member Operators
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)
163         {
164             this->operator|=(rhs);
165         }
167         //- Remove entries listed in the given HashSet from this HashSet
168         void operator-=(const HashSet<Key, Hash>&);
172 // Global Operators
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 #ifdef NoRepository
215 #   include "HashSet.C"
216 #endif
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 #endif
222 // ************************************************************************* //