00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef _HASH_SET_EX_H
00041 #define _HASH_SET_EX_H
00042
00043 #include <set>
00044 #include <memory>
00045 using namespace std;
00046
00047
00048 #define TEMPL template < class Key, class Traits, class Allocator >
00049 #define TARGS < Key, Traits, Allocator >
00050
00051
00052 template < class Key, class Traits=less<Key>, class Allocator=allocator<Key> >
00053 class hash_set_ex : public set TARGS
00054 {
00055 public:
00056
00057 hash_set_ex( ) {}
00058 explicit hash_set_ex( const Traits& _Comp ) : set TARGS( _Comp ) {}
00059 explicit hash_set_ex( const Traits& _Comp, const Allocator& _Al ) : set TARGS( _Comp, _Al ) {}
00060 hash_set_ex( const hash_set_ex& _Right ) : set TARGS( _Right ) {}
00061
00062
00063 hash_set_ex operator | ( const hash_set_ex & rhs ) const;
00064 hash_set_ex& operator |= ( const hash_set_ex & rhs );
00065 hash_set_ex operator | ( const Key & single ) const;
00066 hash_set_ex& operator |= ( const Key & single );
00067
00068
00069 hash_set_ex operator & ( const hash_set_ex & rhs ) const;
00070 hash_set_ex& operator &= ( const hash_set_ex & rhs );
00071 hash_set_ex operator & ( const Key & single ) const;
00072 hash_set_ex& operator &= ( const Key & single );
00073
00074
00075 hash_set_ex operator - ( const hash_set_ex & rhs ) const;
00076 hash_set_ex& operator -= ( const hash_set_ex & rhs );
00077 hash_set_ex operator - ( const Key & single ) const;
00078 hash_set_ex& operator -= ( const Key & single );
00079
00080
00081 hash_set_ex& operator = ( const hash_set_ex & rhs );
00082
00083
00084 bool operator == ( const hash_set_ex & rhs ) const;
00085 bool operator != ( const hash_set_ex & rhs ) const;
00086
00087
00088 typedef typename hash_set_ex::iterator hash_set_ex_p;
00089 typedef typename hash_set_ex::const_iterator hash_set_ex_cp;
00090 };
00091
00092
00093 TEMPL
00094 hash_set_ex TARGS hash_set_ex TARGS::operator | ( const hash_set_ex TARGS & rhs ) const
00095 {
00096
00097 hash_set_ex TARGS output( *this );
00098 output.insert( rhs.begin(), rhs.end() );
00099 return output;
00100 }
00101 TEMPL
00102 hash_set_ex TARGS& hash_set_ex TARGS::operator |= ( const hash_set_ex TARGS & rhs )
00103 {
00104
00105 insert( rhs.begin(), rhs.end() );
00106 return (*this);
00107 }
00108 TEMPL
00109 hash_set_ex TARGS hash_set_ex TARGS::operator | ( const Key & single ) const
00110 {
00111
00112 hash_set_ex TARGS output( *this );
00113 output.insert( single );
00114 return output;
00115 }
00116 TEMPL
00117 hash_set_ex TARGS& hash_set_ex TARGS::operator |= ( const Key & single )
00118 {
00119
00120 insert( single );
00121 return (*this);
00122 }
00123
00124
00125 TEMPL
00126 hash_set_ex TARGS hash_set_ex TARGS::operator & ( const hash_set_ex TARGS & rhs ) const
00127 {
00128
00129 hash_set_ex TARGS output;
00130 hash_set_ex_cp it = begin();
00131 while ( it != end() )
00132 {
00133
00134 if ( rhs.find( *it ) != rhs.end() )
00135 output.insert( *it );
00136
00137
00138 ++it;
00139 }
00140 return output;
00141 }
00142 TEMPL
00143 hash_set_ex TARGS& hash_set_ex TARGS::operator &= ( const hash_set_ex TARGS & rhs )
00144 {
00145
00146 hash_set_ex TARGS temp;
00147 hash_set_ex_p it = begin();
00148 while ( it != end() )
00149 {
00150
00151 if ( rhs.find( *it ) != rhs.end() )
00152 temp.insert( *it );
00153
00154 ++it;
00155 }
00156
00157
00158 *this = temp;
00159 return (*this);
00160 }
00161 TEMPL
00162 hash_set_ex TARGS hash_set_ex TARGS::operator & ( const Key & single ) const
00163 {
00164
00165 hash_set_ex TARGS output;
00166 if ( find( single ) != end() )
00167 output.insert( single );
00168 return output;
00169 }
00170 TEMPL
00171 hash_set_ex TARGS& hash_set_ex TARGS::operator &= ( const Key & single )
00172 {
00173
00174 bool in = (find( single ) != end());
00175 clear();
00176 if ( in )
00177 insert( single );
00178 return (*this);
00179 }
00180
00181
00182 TEMPL
00183 hash_set_ex TARGS hash_set_ex TARGS::operator - ( const hash_set_ex TARGS & rhs ) const
00184 {
00185
00186 hash_set_ex TARGS output( *this );
00187 hash_set_ex_cp it = rhs.begin();
00188 while ( it != rhs.end() )
00189 output.erase( *(it++) );
00190 return output;
00191 }
00192 TEMPL
00193 hash_set_ex TARGS& hash_set_ex TARGS::operator -= ( const hash_set_ex TARGS & rhs )
00194 {
00195
00196 hash_set_ex_cp it = rhs.begin();
00197 while ( it != rhs.end() )
00198 erase( *(it++) );
00199 return (*this);
00200 }
00201 TEMPL
00202 hash_set_ex TARGS hash_set_ex TARGS::operator - ( const Key & single ) const
00203 {
00204
00205 hash_set_ex TARGS output( *this );
00206 output.erase( single );
00207 return output;
00208 }
00209 TEMPL
00210 hash_set_ex TARGS& hash_set_ex TARGS::operator -= ( const Key & single )
00211 {
00212
00213 erase( single );
00214 return (*this);
00215 }
00216
00217
00218 TEMPL
00219 hash_set_ex TARGS& hash_set_ex TARGS::operator = ( const hash_set_ex TARGS & rhs )
00220 {
00221
00222 clear();
00223 insert( rhs.begin(), rhs.end() );
00224 return (*this);
00225 }
00226
00227
00228 TEMPL
00229 bool hash_set_ex TARGS::operator == ( const hash_set_ex TARGS & rhs ) const
00230 {
00231
00232 if ( size() != rhs.size() )
00233 return false;
00234 hash_set_ex_cp it = rhs.begin();
00235 while ( it != rhs.end() )
00236 if ( find( *(it++) ) == end() )
00237 return false;
00238 return true;
00239 }
00240
00241
00242 TEMPL
00243 bool hash_set_ex TARGS::operator != ( const hash_set_ex TARGS & rhs ) const
00244 {
00245
00246 return ( *this == rhs ? false : true );
00247 }
00248
00249 #undef TEMPL
00250 #undef TARGS
00251
00252 #endif // _HASH_SET_EX_H