The Original CHomP Software
setunion.h
Go to the documentation of this file.
1
3
17
18// Copyright (C) 1997-2020 by Pawel Pilarczyk.
19//
20// This file is part of my research software package. This is free software:
21// you can redistribute it and/or modify it under the terms of the GNU
22// General Public License as published by the Free Software Foundation,
23// either version 3 of the License, or (at your option) any later version.
24//
25// This software is distributed in the hope that it will be useful,
26// but WITHOUT ANY WARRANTY; without even the implied warranty of
27// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28// GNU General Public License for more details.
29//
30// You should have received a copy of the GNU General Public License
31// along with this software; see the file "license.txt". If not,
32// please, see <https://www.gnu.org/licenses/>.
33
34// Started on April 22, 2008. Last revision: April 23, 2008.
35
36
37#ifndef _CHOMP_STRUCT_SETUNION_H_
38#define _CHOMP_STRUCT_SETUNION_H_
39
40#include "chomp/system/config.h"
41
42namespace chomp {
43namespace homology {
44
45
46// class templates defined within this header file (in this order):
47template <class set1type, class set2type>
48class setunion;
49
50
51// --------------------------------------------------
52// ------------------- set union --------------------
53// --------------------------------------------------
54
59template <class set1type, class set2type>
61{
62public:
64 typedef typename set1type::value_type value_type;
65
67 setunion (const set1type &_set1, const set2type &_set2);
68
71
74
76 ~setunion ();
77
79 const set1type &get1 () const;
80
82 const set2type &get2 () const;
83
86 int_t getnumber (const typename set1type::value_type &e) const;
87
92 bool checknum (int_t n) const;
93
96 bool check (const typename set1type::value_type &e) const;
97
100 operator [] (int_t n) const;
101
104 const;
105
107 int_t size () const;
108
110 bool empty () const;
111
112private:
114 const set1type *set1;
115
117 const set2type *set2;
118
119}; /* class setunion */
120
121// --------------------------------------------------
122
123template <class set1type, class set2type>
124inline setunion<set1type,set2type>::setunion (const set1type &_set1,
125 const set2type &_set2): set1 (&_set1), set2 (&_set2)
126{
127 return;
128} /* setunion::setunion */
129
130template <class set1type, class set2type>
132{
133 return;
134} /* setunion::~setunion */
135
136template <class set1type, class set2type>
139{
140 throw "Trying to use the copy constructor of a set union.";
141 return;
142} /* setunion::setunion */
143
144template <class set1type, class set2type>
147{
148 throw "Trying to use the assignment operator of a set union.";
149 return *this;
150} /* setunion::setunion */
151
152template <class set1type, class set2type>
153inline const set1type &setunion<set1type,set2type>::get1 () const
154{
155 return *set1;
156} /* setunion::get1 */
157
158template <class set1type, class set2type>
159inline const set2type &setunion<set1type,set2type>::get2 () const
160{
161 return *set2;
162} /* setunion::get2 */
163
164template <class set1type, class set2type>
166 (const typename set1type::value_type &e) const
167{
168 int_t n = set1 -> getnumber (e);
169 if (n >= 0)
170 return n;
171 n = set2 -> getnumber (e);
172 if (n >= 0)
173 return set1 -> size () + n;
174 else
175 return n;
176} /* setunion::getnumber */
177
178template <class set1type, class set2type>
180{
181 return ((n >= 0) && (n < set1 -> size () + set2 -> size ()));
182} /* setunion::checknum */
183
184template <class set1type, class set2type>
186 (const typename set1type::value_type &e) const
187{
188 return (set1 -> check (e) || set2 -> check (e));
189} /* setunion::check */
190
191template <class set1type, class set2type>
192inline const typename setunion<set1type,set2type>::value_type &
194{
195 int_t size1 = set1 -> size ();
196 if (n < size1)
197 return set1 -> get (n);
198 else
199 return set2 -> get (n - size1);
200} /* setunion::get */
201
202template <class set1type, class set2type>
203inline const typename setunion<set1type,set2type>::value_type &
205{
206 return get (n);
207} /* setunion::operator [] */
208
209template <class set1type, class set2type>
211{
212 return (set1 -> size () + set2 -> size ());
213} /* setunion::size */
214
215template <class set1type, class set2type>
217{
218 return (set1 -> empty () && set2 -> empty ());
219} /* setunion::empty */
220
221// --------------------------------------------------
222
224template <class set1type, class set2type>
225inline setunion<set1type,set2type> makesetunion (const set1type &set1,
226 const set2type &set2)
227{
228 return setunion<set1type,set2type> (set1, set2);
229} /* makesetunion */
230
231// Assigns the union of two sets to a single set using the assignment
232// operator and the "add" function.
233//template <class set1type, class set2type>
234//inline set1type &operator = (set1type &set1,
235// const setunion<set1type,set2type> &set2)
236//{
237// set1 = set2. get1 ();
238// set1. add (set2. get2 ());
239// return set1;
240//} /* operator = */
241
242
243} // namespace homology
244} // namespace chomp
245
246#endif // _CHOMP_STRUCT_SETUNION_H_
247
249
A union of two hashed sets.
Definition: setunion.h:61
setunion & operator=(const setunion< set1type, set2type > &s)
The assignment operator.
Definition: setunion.h:146
const set1type & get1() const
Returns a const reference to the first set in the union.
Definition: setunion.h:153
~setunion()
The destructor.
Definition: setunion.h:131
int_t getnumber(const typename set1type::value_type &e) const
Finds the given element and returns its number.
Definition: setunion.h:166
const set2type * set2
Reference to the second set.
Definition: setunion.h:117
bool empty() const
Returns true if both sets are empty. Otherwise returns false.
Definition: setunion.h:216
bool checknum(int_t n) const
Checks if the given number is an index of some element in the set union.
Definition: setunion.h:179
const set2type & get2() const
Returns a const reference to the second set in the union.
Definition: setunion.h:159
const setunion< set1type, set2type >::value_type & get(int_t n) const
Returns the element with the given number from the set union.
Definition: setunion.h:193
const set1type * set1
Reference to the first set.
Definition: setunion.h:114
const setunion< set1type, set2type >::value_type & operator[](int_t n) const
Returns the element with the given number from the set union.
Definition: setunion.h:204
bool check(const typename set1type::value_type &e) const
Checks if the given element is in the set union.
Definition: setunion.h:186
int_t size() const
Returns the number of elements in the set union.
Definition: setunion.h:210
set1type::value_type value_type
The type of the element of each of the sets.
Definition: setunion.h:64
setunion(const set1type &_set1, const set2type &_set2)
The only allowed constructor.
Definition: setunion.h:124
This file contains some precompiler definitions which indicate the operating system and/or compiler u...
int int_t
Index type for indexing arrays, counting cubes, etc.
Definition: config.h:115
setunion< set1type, set2type > makesetunion(const set1type &set1, const set2type &set2)
Creates an object which represents the union of two sets.
Definition: setunion.h:225
This namespace contains the entire CHomP library interface.
Definition: bitmaps.h:51