Public Types | Public Member Functions | Private Attributes

chomp::homology::setunion< set1type, set2type > Class Template Reference

A union of two hashed sets. More...

#include <setunion.h>

List of all members.

Public Types

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

Public Member Functions

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

Private Attributes

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

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 61 of file setunion.h.


Member Typedef Documentation

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 65 of file setunion.h.


Constructor & Destructor Documentation

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 125 of file setunion.h.

                              : set1 (&_set1), set2 (&_set2)
{
        return;
} /* setunion::setunion */

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

The copy constructor.

Definition at line 139 of file setunion.h.

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

template<class set1type , class set2type >
chomp::homology::setunion< set1type, set2type >::~setunion (  )  [inline]

The destructor.

Definition at line 132 of file setunion.h.

{
        return;
} /* setunion::~setunion */


Member Function Documentation

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 187 of file setunion.h.

{
        return (set1 -> check (e) || set2 -> check (e));
} /* setunion::check */

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 180 of file setunion.h.

References chomp::homology::setunion< set1type, set2type >::set2, and chomp::homology::setunion< set1type, set2type >::size().

{
        return ((n >= 0) && (n < set1 -> size () + set2 -> size ()));
} /* setunion::checknum */

template<class set1type , class set2type >
bool chomp::homology::setunion< set1type, set2type >::empty (  )  const [inline]

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

Definition at line 217 of file setunion.h.

References chomp::homology::setunion< set1type, set2type >::set1, and chomp::homology::setunion< set1type, set2type >::set2.

{
        return (set1 -> empty () && set2 -> empty ());
} /* setunion::empty */

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 194 of file setunion.h.

References chomp::homology::setunion< set1type, set2type >::set1, chomp::homology::setunion< set1type, set2type >::set2, and chomp::homology::setunion< set1type, set2type >::size().

{
        int_t size1 = set1 -> size ();
        if (n < size1)
                return set1 -> get (n);
        else
                return set2 -> get (n - size1);
} /* setunion::get */

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

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

Definition at line 154 of file setunion.h.

References chomp::homology::setunion< set1type, set2type >::set1.

{
        return *set1;
} /* setunion::get1 */

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

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

Definition at line 160 of file setunion.h.

References chomp::homology::setunion< set1type, set2type >::set2.

{
        return *set2;
} /* setunion::get2 */

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 167 of file setunion.h.

{
        int_t n = set1 -> getnumber (e);
        if (n >= 0)
                return n;
        n = set2 -> getnumber (e);
        if (n >= 0)
                return set1 -> size () + n;
        else
                return n;
} /* setunion::getnumber */

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 147 of file setunion.h.

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

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 205 of file setunion.h.

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

template<class set1type , class set2type >
int_t chomp::homology::setunion< set1type, set2type >::size (  )  const [inline]

Returns the number of elements in the set union.

Definition at line 211 of file setunion.h.

References chomp::homology::setunion< set1type, set2type >::set1, and chomp::homology::setunion< set1type, set2type >::set2.

Referenced by chomp::homology::setunion< set1type, set2type >::checknum(), and chomp::homology::setunion< set1type, set2type >::get().

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


Member Data Documentation

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

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