00001 #ifndef _PG_VERTEX_SETS_HPP_
00002 #define _PG_VERTEX_SETS_HPP_
00003
00004 namespace ParGraph
00005 {
00006
00008 template< class Graph >
00009 class SetWrapper
00010 {
00011 public:
00012 typedef std::set< typename Graph::KnownVertex > set_type;
00013 private:
00014 set_type data;
00015 Graph & g;
00016
00017 public:
00018 SetWrapper( Graph & _g ) : data(), g(_g) {}
00019
00020 pair<typename set_type::iterator, bool> insert( VertexID_t v )
00021 {
00022 return insert( g.get_known_vertex( v ) );
00023 }
00024
00025
00026
00027
00028 typedef typename set_type::value_type value_type;
00029 typedef typename set_type::key_type key_type;
00030 typedef typename set_type::value_compare value_compare;
00031 typedef typename set_type::key_compare key_compare;
00032 typedef typename set_type::pointer pointer;
00033 typedef typename set_type::reference reference;
00034 typedef typename set_type::const_reference const_reference;
00035 typedef typename set_type::size_type size_type;
00036 typedef typename set_type::difference_type difference_type;
00037 typedef typename set_type::iterator iterator;
00038 typedef typename set_type::const_iterator const_iterator;
00039 typedef typename set_type::reverse_iterator reverse_iterator;
00040 typedef typename set_type::const_reverse_iterator const_reverse_iterator;
00041
00042 iterator begin() const { return data.begin(); }
00043 iterator end() const { return data.end(); }
00044 reverse_iterator rbegin() const { return data.rbegin(); }
00045 reverse_iterator rend() const { return data.rend(); }
00046 size_type size() const { return data.size(); }
00047 size_type max_size() const { return data.max_size(); }
00048 bool empty() const { return data.empty(); }
00049 key_compare key_comp() const { return data.key_comp(); }
00050 value_compare value_comp() const { return data.value_comp(); }
00051 void swap( SetWrapper & s ) { data.swap( s.data ); }
00052 pair<iterator, bool> insert(value_type v)
00053 {
00054 pair<iterator, bool> r_val = data.insert( v );
00055 if( r_val.second == true )
00056 g.ink_known_vertex_counter( v );
00057 return r_val;
00058 }
00059 iterator insert( iterator pos, value_type v)
00060 {
00061 size_type presize = data.size();
00062 iterator r_val = data.insert( pos, v );
00063 if( presize != data.size() )
00064 g.ink_known_vertex_counter( v );
00065 return r_val;
00066 }
00067 template <class InputIterator>
00068 void insert(InputIterator it_begin, InputIterator it_end )
00069 {
00070 for( InputIterator it = it_begin ; it != it_end ; it++ )
00071 insert( *it );
00072 }
00073 size_type erase(const key_type& v)
00074 {
00075 if( data.erase( v ) > 0 )
00076 g.dek_known_vertex_counter( v );
00077 return 1;
00078 }
00079 void erase(iterator it)
00080 {
00081 g.dek_known_vertex_counter( *it );
00082 data.erase( it );
00083 }
00084 void erase(iterator first, iterator last)
00085 {
00086 for(; first != last ; first++ )
00087 {
00088 g.dek_known_vertex_counter( *first );
00089 data.erase( first );
00090 }
00091 }
00092 void clear()
00093 {
00094 for( iterator it = data.begin() ; it != data.end() ; it++ )
00095 g.dek_known_vertex_counter( *it );
00096 data.clear();
00097 }
00098 iterator find(key_type v) { return data.find(v); }
00099 size_type count(key_type v) const { return data.count(v); }
00100 iterator lower_bound(key_type v) const { return data.lower_bound(v); }
00101 iterator upper_bound(key_type v) const { return data.upper_bound(v); }
00102 std::pair< iterator, iterator > equal_range(key_type v) const { return data.equal_range(v); }
00103 };
00104
00105
00106
00108 template< class Graph >
00109 typename Graph::VertexSetHandle
00110 add_vertex_set( Graph & g )
00111 {
00112 g.registered_vertex_sets.push_front( SetWrapper<Graph>(g) );
00113 return g.registered_vertex_sets.begin();
00114 }
00115
00117 template< class Graph >
00118 void
00119 remove_vertex_set( Graph & g, typename Graph::VertexSetHandle h )
00120 {
00121 g.registered_vertex_sets.erase( h );
00122 }
00123
00125 template< class VertexSetHandle >
00126 void
00127 copy( VertexSetHandle h1, VertexSetHandle h2 )
00128 {
00129 (*h2).clear();
00130 (*h2).insert( (*h1).begin(), (*h1).end() );
00131 }
00132
00134 template< class VertexSetHandle, class Set >
00135 void
00136 copy( VertexSetHandle h1, Set & h2 )
00137 {
00138 h2.clear();
00139 h2.insert( (*h1).begin(), (*h1).end() );
00140 }
00141
00143 template< class KV, class VertexSetHandle >
00144 bool
00145 is_inside( KV v, VertexSetHandle h )
00146 {
00147 return h->find(v) != h->end();
00148 }
00149
00150 }
00151
00152 #endif // _PG_VERTEX_SETS_HPP_