The Original CHomP Software
Public Types | Public Member Functions | Private Attributes | List of all members
chomp::homology::setunion< set1type, set2type > Class Template Reference

A union of two hashed sets. More...

#include <setunion.h>

Public Types

typedef set1type::value_type value_type
 The type of the element of each of the sets. More...
 

Public Member Functions

 setunion (const set1type &_set1, const set2type &_set2)
 The only allowed constructor. More...
 
 setunion (const setunion< set1type, set2type > &s)
 The copy constructor. More...
 
setunionoperator= (const setunion< set1type, set2type > &s)
 The assignment operator. More...
 
 ~setunion ()
 The destructor. More...
 
const set1type & get1 () const
 Returns a const reference to the first set in the union. More...
 
const set2type & get2 () const
 Returns a const reference to the second set in the union. More...
 
int_t getnumber (const typename set1type::value_type &e) const
 Finds the given element and returns its number. More...
 
bool checknum (int_t n) const
 Checks if the given number is an index of some element in the set union. More...
 
bool check (const typename set1type::value_type &e) const
 Checks if the given element is in the set union. More...
 
const setunion< set1type, set2type >::value_typeoperator[] (int_t n) const
 Returns the element with the given number from the set union. More...
 
const setunion< set1type, set2type >::value_typeget (int_t n) const
 Returns the element with the given number from the set union. More...
 
int_t size () const
 Returns the number of elements in the set union. More...
 
bool empty () const
 Returns true if both sets are empty. Otherwise returns false. More...
 

Private Attributes

const set1type * set1
 Reference to the first set. More...
 
const set2type * set2
 Reference to the second set. More...
 

Detailed Description

template<class set1type, class set2type>
class chomp::homology::setunion< set1type, set2type >

A union of two hashed sets.

Thanks to the template style definition, it can be used to define a union of unions of sets etc., although the efficiency of this solution decreases with the increasing recursion level.

Definition at line 60 of file setunion.h.

Member Typedef Documentation

◆ value_type

template<class set1type , class set2type >
typedef set1type::value_type chomp::homology::setunion< set1type, set2type >::value_type

The type of the element of each of the sets.

Definition at line 64 of file setunion.h.

Constructor & Destructor Documentation

◆ setunion() [1/2]

template<class set1type , class set2type >
chomp::homology::setunion< set1type, set2type >::setunion ( const set1type &  _set1,
const set2type &  _set2 
)
inline

The only allowed constructor.

Definition at line 124 of file setunion.h.

125 : set1 (&_set1), set2 (&_set2)
126{
127 return;
128} /* setunion::setunion */
const set2type * set2
Reference to the second set.
Definition: setunion.h:117
const set1type * set1
Reference to the first set.
Definition: setunion.h:114

◆ setunion() [2/2]

template<class set1type , class set2type >
chomp::homology::setunion< set1type, set2type >::setunion ( const setunion< set1type, set2type > &  s)
inline

The copy constructor.

Definition at line 137 of file setunion.h.

139{
140 throw "Trying to use the copy constructor of a set union.";
141 return;
142} /* setunion::setunion */

◆ ~setunion()

template<class set1type , class set2type >
chomp::homology::setunion< set1type, set2type >::~setunion
inline

The destructor.

Definition at line 131 of file setunion.h.

132{
133 return;
134} /* setunion::~setunion */

Member Function Documentation

◆ check()

template<class set1type , class set2type >
bool chomp::homology::setunion< set1type, set2type >::check ( const typename set1type::value_type &  e) const
inline

Checks if the given element is in the set union.

Returns true if yes, false if no.

Definition at line 185 of file setunion.h.

187{
188 return (set1 -> check (e) || set2 -> check (e));
189} /* setunion::check */
bool check(const typename set1type::value_type &e) const
Checks if the given element is in the set union.
Definition: setunion.h:186

◆ checknum()

template<class set1type , class set2type >
bool chomp::homology::setunion< set1type, set2type >::checknum ( int_t  n) const
inline

Checks if the given number is an index of some element in the set union.

That is, checks if the number is non-negative and strictly smaller than the number of elements in the set union. Returns true if yes, false if no.

Definition at line 179 of file setunion.h.

180{
181 return ((n >= 0) && (n < set1 -> size () + set2 -> size ()));
182} /* setunion::checknum */
int_t size() const
Returns the number of elements in the set union.
Definition: setunion.h:210

◆ empty()

template<class set1type , class set2type >
bool chomp::homology::setunion< set1type, set2type >::empty
inline

Returns true if both sets are empty. Otherwise returns false.

Definition at line 216 of file setunion.h.

217{
218 return (set1 -> empty () && set2 -> empty ());
219} /* setunion::empty */
bool empty() const
Returns true if both sets are empty. Otherwise returns false.
Definition: setunion.h:216

◆ get()

template<class set1type , class set2type >
const setunion< set1type, set2type >::value_type & chomp::homology::setunion< set1type, set2type >::get ( int_t  n) const
inline

Returns the element with the given number from the set union.

Definition at line 193 of file setunion.h.

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 */
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
int int_t
Index type for indexing arrays, counting cubes, etc.
Definition: config.h:115

◆ get1()

template<class set1type , class set2type >
const set1type & chomp::homology::setunion< set1type, set2type >::get1
inline

Returns a const reference to the first set in the union.

Definition at line 153 of file setunion.h.

154{
155 return *set1;
156} /* setunion::get1 */

◆ get2()

template<class set1type , class set2type >
const set2type & chomp::homology::setunion< set1type, set2type >::get2
inline

Returns a const reference to the second set in the union.

Definition at line 159 of file setunion.h.

160{
161 return *set2;
162} /* setunion::get2 */

◆ getnumber()

template<class set1type , class set2type >
int_t chomp::homology::setunion< set1type, set2type >::getnumber ( const typename set1type::value_type &  e) const
inline

Finds the given element and returns its number.

Returns -1 if the element is not in the union of the sets.

Definition at line 165 of file setunion.h.

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 */
int_t getnumber(const typename set1type::value_type &e) const
Finds the given element and returns its number.
Definition: setunion.h:166

◆ operator=()

template<class set1type , class set2type >
setunion< set1type, set2type > & chomp::homology::setunion< set1type, set2type >::operator= ( const setunion< set1type, set2type > &  s)
inline

The assignment operator.

Definition at line 145 of file setunion.h.

147{
148 throw "Trying to use the assignment operator of a set union.";
149 return *this;
150} /* setunion::setunion */

◆ operator[]()

template<class set1type , class set2type >
const setunion< set1type, set2type >::value_type & chomp::homology::setunion< set1type, set2type >::operator[] ( int_t  n) const
inline

Returns the element with the given number from the set union.

Definition at line 204 of file setunion.h.

205{
206 return get (n);
207} /* setunion::operator [] */

◆ size()

template<class set1type , class set2type >
int_t chomp::homology::setunion< set1type, set2type >::size
inline

Returns the number of elements in the set union.

Definition at line 210 of file setunion.h.

211{
212 return (set1 -> size () + set2 -> size ());
213} /* setunion::size */

Member Data Documentation

◆ set1

template<class set1type , class set2type >
const set1type* chomp::homology::setunion< set1type, set2type >::set1
private

Reference to the first set.

Definition at line 114 of file setunion.h.

◆ set2

template<class set1type , class set2type >
const set2type* chomp::homology::setunion< set1type, set2type >::set2
private

Reference to the second set.

Definition at line 117 of file setunion.h.


The documentation for this class was generated from the following file: