37#ifndef _CHOMP_STRUCT_SETUNION_H_
38#define _CHOMP_STRUCT_SETUNION_H_
47template <
class set1type,
class set2type>
59template <
class set1type,
class set2type>
67 setunion (
const set1type &_set1,
const set2type &_set2);
79 const set1type &
get1 ()
const;
82 const set2type &
get2 ()
const;
96 bool check (
const typename set1type::value_type &e)
const;
123template <
class set1type,
class set2type>
125 const set2type &_set2): set1 (&_set1), set2 (&_set2)
130template <
class set1type,
class set2type>
136template <
class set1type,
class set2type>
140 throw "Trying to use the copy constructor of a set union.";
144template <
class set1type,
class set2type>
148 throw "Trying to use the assignment operator of a set union.";
152template <
class set1type,
class set2type>
158template <
class set1type,
class set2type>
164template <
class set1type,
class set2type>
166 (
const typename set1type::value_type &e)
const
168 int_t n = set1 -> getnumber (e);
171 n = set2 -> getnumber (e);
173 return set1 -> size () + n;
178template <
class set1type,
class set2type>
181 return ((n >= 0) && (n < set1 -> size () + set2 -> size ()));
184template <
class set1type,
class set2type>
186 (
const typename set1type::value_type &e)
const
188 return (set1 -> check (e) || set2 -> check (e));
191template <
class set1type,
class set2type>
195 int_t size1 = set1 -> size ();
197 return set1 -> get (n);
199 return set2 -> get (n - size1);
202template <
class set1type,
class set2type>
209template <
class set1type,
class set2type>
212 return (set1 -> size () + set2 -> size ());
215template <
class set1type,
class set2type>
218 return (set1 -> empty () && set2 -> empty ());
224template <
class set1type,
class set2type>
226 const set2type &set2)
A union of two hashed sets.
setunion & operator=(const setunion< set1type, set2type > &s)
The assignment operator.
const set1type & get1() const
Returns a const reference to the first set in the union.
~setunion()
The destructor.
int_t getnumber(const typename set1type::value_type &e) const
Finds the given element and returns its number.
const set2type * set2
Reference to the second set.
bool empty() const
Returns true if both sets are empty. Otherwise returns false.
bool checknum(int_t n) const
Checks if the given number is an index of some element in the set union.
const set2type & get2() const
Returns a const reference to the second set in the union.
const setunion< set1type, set2type >::value_type & get(int_t n) const
Returns the element with the given number from the set union.
const set1type * set1
Reference to the first set.
const setunion< set1type, set2type >::value_type & operator[](int_t n) const
Returns the element with the given number from the set union.
bool check(const typename set1type::value_type &e) const
Checks if the given element is in the set union.
int_t size() const
Returns the number of elements in the set union.
set1type::value_type value_type
The type of the element of each of the sets.
setunion(const set1type &_set1, const set2type &_set2)
The only allowed constructor.
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.
setunion< set1type, set2type > makesetunion(const set1type &set1, const set2type &set2)
Creates an object which represents the union of two sets.
This namespace contains the entire CHomP library interface.