|
||
Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
hash_set_ex.hGo to the documentation of this file.00001 // $Id: hash_set_ex.h,v 1.3 2003/08/07 23:13:45 pnav Exp $ 00002 // ---------------------------------------------------------------------- 00003 // 00004 // C-Breeze 00005 // C Compiler Framework 00006 // 00007 // Copyright (c) 2000 University of Texas at Austin 00008 // 00009 // Samuel Z. Guyer 00010 // Daniel A. Jimenez 00011 // Calvin Lin 00012 // Charles Nevill 00013 // Paul Navratil 00014 // 00015 // Permission is hereby granted, free of charge, to any person 00016 // obtaining a copy of this software and associated documentation 00017 // files (the "Software"), to deal in the Software without 00018 // restriction, including without limitation the rights to use, copy, 00019 // modify, merge, publish, distribute, sublicense, and/or sell copies 00020 // of the Software, and to permit persons to whom the Software is 00021 // furnished to do so, subject to the following conditions: 00022 // 00023 // The above copyright notice and this permission notice shall be 00024 // included in all copies or substantial portions of the Software. 00025 // 00026 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00027 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00028 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00029 // NONINFRINGEMENT. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT 00030 // AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 00031 // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 00032 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00033 // THE SOFTWARE. 00034 // 00035 // We acknowledge the C-to-C Translator from MIT Laboratory for 00036 // Computer Science for inspiring parts of the C-Breeze design. 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 // because the template is really ugly - just define it 00048 #define TEMPL template < class Key, class Traits, class Allocator > 00049 #define TARGS < Key, Traits, Allocator > 00050 00051 // a better set class 00052 template < class Key, class Traits=less<Key>, class Allocator=allocator<Key> > 00053 class hash_set_ex : public set TARGS 00054 { 00055 public: 00056 // ctors 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 // set union operators 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 // set intersection operators 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 // set subtraction operators 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 // copy operator 00081 hash_set_ex& operator = ( const hash_set_ex & rhs ); 00082 00083 // comparison operators 00084 bool operator == ( const hash_set_ex & rhs ) const; 00085 bool operator != ( const hash_set_ex & rhs ) const; 00086 00087 // handy typedef 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 // set union operators 00093 TEMPL 00094 hash_set_ex TARGS hash_set_ex TARGS::operator | ( const hash_set_ex TARGS & rhs ) const 00095 { 00096 // just insert both of our sets 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 // insert all of their set 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 // insert our set and the one other thing 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 // insert the one other thing 00120 insert( single ); 00121 return (*this); 00122 } 00123 00124 // set intersection operators 00125 TEMPL 00126 hash_set_ex TARGS hash_set_ex TARGS::operator & ( const hash_set_ex TARGS & rhs ) const 00127 { 00128 // insert each thing in our set if it's in theirs 00129 hash_set_ex TARGS output; 00130 hash_set_ex_cp it = begin(); 00131 while ( it != end() ) 00132 { 00133 // add this if it's in rhs as well 00134 if ( rhs.find( *it ) != rhs.end() ) 00135 output.insert( *it ); 00136 00137 // next element 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 // insert each thing in our set if it's in theirs 00146 hash_set_ex TARGS temp; 00147 hash_set_ex_p it = begin(); 00148 while ( it != end() ) 00149 { 00150 // if this is in both sets, add it to output 00151 if ( rhs.find( *it ) != rhs.end() ) 00152 temp.insert( *it ); 00153 00154 ++it; 00155 } 00156 00157 // copy over from temp 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 // if this is in our set return it otherwise empty 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 // if this is in our set, set us to it, otherwise empty 00174 bool in = (find( single ) != end()); 00175 clear(); 00176 if ( in ) 00177 insert( single ); 00178 return (*this); 00179 } 00180 00181 // set subtraction operators 00182 TEMPL 00183 hash_set_ex TARGS hash_set_ex TARGS::operator - ( const hash_set_ex TARGS & rhs ) const 00184 { 00185 // copy us and remove all of their things 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 // remove all of their things 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 // copy us and remove the one thing 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 // remove the one thing 00213 erase( single ); 00214 return (*this); 00215 } 00216 00217 // copy operator 00218 TEMPL 00219 hash_set_ex TARGS& hash_set_ex TARGS::operator = ( const hash_set_ex TARGS & rhs ) 00220 { 00221 // copy us over 00222 clear(); 00223 insert( rhs.begin(), rhs.end() ); 00224 return (*this); 00225 } 00226 00227 // comparison operator 00228 TEMPL 00229 bool hash_set_ex TARGS::operator == ( const hash_set_ex TARGS & rhs ) const 00230 { 00231 // we are equal if we have the same size and every element in rhs is in us 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 // comparison operator 00242 TEMPL 00243 bool hash_set_ex TARGS::operator != ( const hash_set_ex TARGS & rhs ) const 00244 { 00245 // are we equal? 00246 return ( *this == rhs ? false : true ); 00247 } 00248 00249 #undef TEMPL 00250 #undef TARGS 00251 00252 #endif // _HASH_SET_EX_H |
Generated on February 1, 2006
Back to the C-Breeze home page