claw::math::ordered_set< K, Comp > Class Template Reference

A class to manage sets of ordered items. More...

#include <ordered_set.hpp>

Inheritance diagram for claw::math::ordered_set< K, Comp >:
claw::avl< K, Comp >

List of all members.

Public Types

typedef super::const_iterator const_iterator
typedef super::value_type value_type
typedef super::referent_type referent_type
typedef super::const_reference const_reference

Public Member Functions

ordered_setoperator*= (const ordered_set &that)
 Intersection.
ordered_setoperator+= (const ordered_set &that)
 Union.
ordered_setoperator-= (const ordered_set &that)
 Difference.
ordered_setoperator/= (const ordered_set &that)
 Symetric difference.
bool operator> (const ordered_set &that) const
 Inclusion.
bool operator>= (const ordered_set &that) const
 Inclusion or equality.
bool operator< (const ordered_set &that) const
 Inclusion.
bool operator<= (const ordered_set &that) const
 Inclusion or equality.
ordered_setintersection (const ordered_set &that)
 Intersection.
ordered_setjoin (const ordered_set &that)
 Union.
ordered_setdifference (const ordered_set &that)
 Difference.
ordered_setsymetric_difference (const ordered_set &that)
 Symetric difference.
bool contains (const ordered_set &that) const
 Inclusion or equality.
bool strictly_contains (const ordered_set &that) const
 Inclusion.

Private Types

typedef avl< K, Comp > super

Static Private Attributes

static Comp s_key_comp
 Function object used to compare keys.

Detailed Description

template<class K, class Comp = std::less<K>>
class claw::math::ordered_set< K, Comp >

A class to manage sets of ordered items.

Author:
Julien Jorge

Definition at line 44 of file ordered_set.hpp.


Member Typedef Documentation

template<class K, class Comp = std::less<K>>
typedef super::const_iterator claw::math::ordered_set< K, Comp >::const_iterator

Reimplemented from claw::avl< K, Comp >.

Definition at line 51 of file ordered_set.hpp.

template<class K, class Comp = std::less<K>>
typedef super::const_reference claw::math::ordered_set< K, Comp >::const_reference

Reimplemented from claw::avl< K, Comp >.

Definition at line 54 of file ordered_set.hpp.

template<class K, class Comp = std::less<K>>
typedef super::referent_type claw::math::ordered_set< K, Comp >::referent_type

Reimplemented from claw::avl< K, Comp >.

Definition at line 53 of file ordered_set.hpp.

template<class K, class Comp = std::less<K>>
typedef avl<K, Comp> claw::math::ordered_set< K, Comp >::super [private]

Definition at line 48 of file ordered_set.hpp.

template<class K, class Comp = std::less<K>>
typedef super::value_type claw::math::ordered_set< K, Comp >::value_type

Reimplemented from claw::avl< K, Comp >.

Definition at line 52 of file ordered_set.hpp.


Member Function Documentation

template<class K , class Comp >
bool claw::math::ordered_set< K, Comp >::contains ( const ordered_set< K, Comp > &  that  )  const [inline]

Inclusion or equality.

Parameters:
that The instance that should be contained.
Returns:
true if that is included in this.

Definition at line 223 of file ordered_set.tpp.

References claw::avl< K, Comp >::begin(), claw::avl< K, Comp >::end(), claw::math::ordered_set< K, Comp >::s_key_comp, and claw::avl< K, Comp >::size().

Referenced by claw::math::ordered_set< K, Comp >::operator<=(), and claw::math::ordered_set< K, Comp >::operator>=().

00224 {
00225   bool ok = super::size() >= that.size();
00226   const_iterator it_this( super::begin() );
00227   const_iterator it_that( that.begin() );
00228 
00229   while ( ok && (it_that != that.end()) && (it_this != super::end()) )
00230     if ( s_key_comp( *it_this, *it_that ) )
00231       ++it_this;
00232     else if ( s_key_comp( *it_that, *it_this ) )
00233       ok = false;
00234     else
00235       {
00236         ++it_this;
00237         ++it_that;
00238       }
00239 
00240   return it_that == that.end();
00241 } // ordered_set::contains()

template<class K , class Comp >
claw::math::ordered_set< K, Comp > & claw::math::ordered_set< K, Comp >::difference ( const ordered_set< K, Comp > &  that  )  [inline]

Difference.

Parameters:
that The instance from which to remove items.

Definition at line 184 of file ordered_set.tpp.

References claw::avl< K, Comp >::begin(), claw::avl< K, Comp >::end(), claw::avl< K, Comp >::erase(), and claw::avl< K, Comp >::find().

Referenced by claw::math::ordered_set< K, Comp >::operator-=(), and claw::math::ordered_set< K, Comp >::symetric_difference().

00185 {
00186   std::list<K> remove_us;
00187   const_iterator it;
00188   
00189   for (it=super::begin(); it!=super::end(); ++it)
00190     if ( that.find( *it ) != that.end() )
00191       remove_us.push_front( *it );
00192 
00193   typename std::list<K>::const_iterator remove_it;
00194 
00195   for (remove_it=remove_us.begin(); remove_it!=remove_us.end(); ++remove_it)
00196     super::erase( *remove_it );
00197 
00198   return *this;
00199 } // ordered_set::difference()

template<class K , class Comp >
claw::math::ordered_set< K, Comp > & claw::math::ordered_set< K, Comp >::intersection ( const ordered_set< K, Comp > &  that  )  [inline]

Intersection.

Parameters:
that The instance to intersect from.

Definition at line 143 of file ordered_set.tpp.

References claw::avl< K, Comp >::begin(), claw::avl< K, Comp >::end(), claw::avl< K, Comp >::erase(), and claw::avl< K, Comp >::find().

Referenced by claw::math::ordered_set< K, Comp >::operator*=().

00144 {
00145   std::list<K> remove_us;
00146   const_iterator it;
00147   
00148   for (it=super::begin(); it!=super::end(); ++it)
00149     if ( that.find( *it ) == that.end() )
00150       remove_us.push_front( *it );
00151 
00152   typename std::list<K>::const_iterator remove_it;
00153 
00154   for (remove_it=remove_us.begin(); remove_it!=remove_us.end(); ++remove_it)
00155     super::erase( *remove_it );
00156 
00157   return *this;
00158 } // ordered_set::intersection()

template<class K , class Comp >
claw::math::ordered_set< K, Comp > & claw::math::ordered_set< K, Comp >::join ( const ordered_set< K, Comp > &  that  )  [inline]

Union.

Parameters:
that The instance to join with.

Definition at line 167 of file ordered_set.tpp.

References claw::avl< K, Comp >::begin(), claw::avl< K, Comp >::end(), and claw::avl< K, Comp >::insert().

Referenced by claw::math::ordered_set< K, Comp >::operator+=(), and claw::math::ordered_set< K, Comp >::symetric_difference().

00168 {
00169   const_iterator it;
00170   
00171   for (it=that.begin(); it!=that.end(); ++it)
00172     super::insert( *it );
00173 
00174   return *this;
00175 } // ordered_set::join()

template<class K , class Comp >
claw::math::ordered_set< K, Comp > & claw::math::ordered_set< K, Comp >::operator*= ( const ordered_set< K, Comp > &  that  )  [inline]

Intersection.

Parameters:
that The instance to intersect from.

Definition at line 43 of file ordered_set.tpp.

References claw::math::ordered_set< K, Comp >::intersection().

00044 {
00045   return intersection( that );
00046 } // ordered_set::operator*=()

template<class K , class Comp >
claw::math::ordered_set< K, Comp > & claw::math::ordered_set< K, Comp >::operator+= ( const ordered_set< K, Comp > &  that  )  [inline]

Union.

Parameters:
that The instance to join with.

Definition at line 55 of file ordered_set.tpp.

References claw::math::ordered_set< K, Comp >::join().

00056 {
00057   return join( that );
00058 } // ordered_set::operator+=()

template<class K , class Comp >
claw::math::ordered_set< K, Comp > & claw::math::ordered_set< K, Comp >::operator-= ( const ordered_set< K, Comp > &  that  )  [inline]

Difference.

Parameters:
that The instance from which to remove items.

Definition at line 67 of file ordered_set.tpp.

References claw::math::ordered_set< K, Comp >::difference().

00068 {
00069   return difference( that );
00070 } // ordered_set::operator-=()

template<class K , class Comp >
claw::math::ordered_set< K, Comp > & claw::math::ordered_set< K, Comp >::operator/= ( const ordered_set< K, Comp > &  that  )  [inline]

Symetric difference.

Parameters:
that The instance to differ from.

Definition at line 79 of file ordered_set.tpp.

References claw::math::ordered_set< K, Comp >::symetric_difference().

00080 {
00081   return symetric_difference( that );
00082 } // ordered_set::operator/=()

template<class K , class Comp >
bool claw::math::ordered_set< K, Comp >::operator< ( const ordered_set< K, Comp > &  that  )  const [inline]

Inclusion.

Parameters:
that The instance that should contain.
Returns:
true if that is strictly included in this.

Reimplemented from claw::avl< K, Comp >.

Definition at line 118 of file ordered_set.tpp.

References claw::math::ordered_set< K, Comp >::strictly_contains().

00119 {
00120   return that.strictly_contains( *this );
00121 } // ordered_set::operator<()

template<class K , class Comp >
bool claw::math::ordered_set< K, Comp >::operator<= ( const ordered_set< K, Comp > &  that  )  const [inline]

Inclusion or equality.

Parameters:
that The instance that should be contained.
Returns:
true if that is included in this.

Reimplemented from claw::avl< K, Comp >.

Definition at line 131 of file ordered_set.tpp.

References claw::math::ordered_set< K, Comp >::contains().

00132 {
00133   return that.contains( *this );
00134 } // ordered_set::operator<=()

template<class K , class Comp >
bool claw::math::ordered_set< K, Comp >::operator> ( const ordered_set< K, Comp > &  that  )  const [inline]

Inclusion.

Parameters:
that The instance that should be contained.
Returns:
true if that is strictly included in this.

Reimplemented from claw::avl< K, Comp >.

Definition at line 92 of file ordered_set.tpp.

References claw::math::ordered_set< K, Comp >::strictly_contains().

00093 {
00094   return strictly_contains( that );
00095 } // ordered_set::operator>()

template<class K , class Comp >
bool claw::math::ordered_set< K, Comp >::operator>= ( const ordered_set< K, Comp > &  that  )  const [inline]

Inclusion or equality.

Parameters:
that The instance that should be contained.
Returns:
true if that is included in this.

Reimplemented from claw::avl< K, Comp >.

Definition at line 105 of file ordered_set.tpp.

References claw::math::ordered_set< K, Comp >::contains().

00106 {
00107   return contains( that );
00108 } // ordered_set::operator>=()

template<class K , class Comp >
bool claw::math::ordered_set< K, Comp >::strictly_contains ( const ordered_set< K, Comp > &  that  )  const [inline]

Inclusion.

Parameters:
that The instance that should contain.
Returns:
true if that is strictly included in this.

Definition at line 252 of file ordered_set.tpp.

References claw::avl< K, Comp >::size().

Referenced by claw::math::ordered_set< K, Comp >::operator<(), and claw::math::ordered_set< K, Comp >::operator>().

00253 {
00254   return contains(that) && ( super::size() > that.size() );
00255 } // ordered_set::strictly_contains()

template<class K , class Comp >
claw::math::ordered_set< K, Comp > & claw::math::ordered_set< K, Comp >::symetric_difference ( const ordered_set< K, Comp > &  that  )  [inline]

Symetric difference.

Parameters:
that The instance to differ from.

Definition at line 208 of file ordered_set.tpp.

References claw::math::ordered_set< K, Comp >::difference(), and claw::math::ordered_set< K, Comp >::join().

Referenced by claw::math::ordered_set< K, Comp >::operator/=().

00209 {
00210   ordered_set<K, Comp> my_copy(*this), his_copy(that);
00211 
00212   return difference( that ).join( his_copy.difference(my_copy) );
00213 } // ordered_set::symetric_difference()


Member Data Documentation

template<class K, class Comp = std::less<K>>
Comp claw::math::ordered_set< K, Comp >::s_key_comp [inline, static, private]

Function object used to compare keys.

Definition at line 77 of file ordered_set.hpp.

Referenced by claw::math::ordered_set< K, Comp >::contains().


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

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1