Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:45:28

0001 //=======================================================================
0002 // Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
0003 // Copyright 2010 Thomas Claveirole
0004 // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek, Thomas Claveirole
0005 //
0006 // Distributed under the Boost Software License, Version 1.0. (See
0007 // accompanying file LICENSE_1_0.txt or copy at
0008 // http://www.boost.org/LICENSE_1_0.txt)
0009 //=======================================================================
0010 
0011 #ifndef BOOST_GRAPH_ADJACENCY_LIST_HPP
0012 #define BOOST_GRAPH_ADJACENCY_LIST_HPP
0013 
0014 #include <boost/config.hpp>
0015 
0016 #include <vector>
0017 #include <list>
0018 #include <set>
0019 
0020 #include <boost/unordered_set.hpp>
0021 
0022 #include <boost/scoped_ptr.hpp>
0023 
0024 #include <boost/graph/graph_traits.hpp>
0025 #include <boost/graph/graph_mutability_traits.hpp>
0026 #include <boost/graph/graph_selectors.hpp>
0027 #include <boost/property_map/property_map.hpp>
0028 #include <boost/mpl/if.hpp>
0029 #include <boost/mpl/and.hpp>
0030 #include <boost/mpl/not.hpp>
0031 #include <boost/mpl/bool.hpp>
0032 #include <boost/graph/detail/edge.hpp>
0033 #include <boost/type_traits/is_same.hpp>
0034 #include <boost/detail/workaround.hpp>
0035 #include <boost/graph/properties.hpp>
0036 #include <boost/graph/named_graph.hpp>
0037 
0038 namespace boost
0039 {
0040 
0041 //===========================================================================
0042 // Selectors for the VertexList and EdgeList template parameters of
0043 // adjacency_list, and the container_gen traits class which is used
0044 // to map the selectors to the container type used to implement the
0045 // graph.
0046 
0047 struct vecS
0048 {
0049 };
0050 struct listS
0051 {
0052 };
0053 struct setS
0054 {
0055 };
0056 struct mapS
0057 {
0058 };
0059 struct multisetS
0060 {
0061 };
0062 struct multimapS
0063 {
0064 };
0065 struct hash_setS
0066 {
0067 };
0068 struct hash_mapS
0069 {
0070 };
0071 struct hash_multisetS
0072 {
0073 };
0074 struct hash_multimapS
0075 {
0076 };
0077 
0078 template < class Selector, class ValueType > struct container_gen
0079 {
0080 };
0081 
0082 template < class ValueType > struct container_gen< listS, ValueType >
0083 {
0084     typedef std::list< ValueType > type;
0085 };
0086 
0087 template < class ValueType > struct container_gen< vecS, ValueType >
0088 {
0089     typedef std::vector< ValueType > type;
0090 };
0091 
0092 template < class ValueType > struct container_gen< mapS, ValueType >
0093 {
0094     typedef std::set< ValueType > type;
0095 };
0096 
0097 template < class ValueType > struct container_gen< setS, ValueType >
0098 {
0099     typedef std::set< ValueType > type;
0100 };
0101 
0102 template < class ValueType > struct container_gen< multisetS, ValueType >
0103 {
0104     typedef std::multiset< ValueType > type;
0105 };
0106 
0107 template < class ValueType > struct container_gen< multimapS, ValueType >
0108 {
0109     typedef std::multiset< ValueType > type;
0110 };
0111 
0112 template < class ValueType > struct container_gen< hash_setS, ValueType >
0113 {
0114     typedef boost::unordered_set< ValueType > type;
0115 };
0116 
0117 template < class ValueType > struct container_gen< hash_mapS, ValueType >
0118 {
0119     typedef boost::unordered_set< ValueType > type;
0120 };
0121 
0122 template < class ValueType > struct container_gen< hash_multisetS, ValueType >
0123 {
0124     typedef boost::unordered_multiset< ValueType > type;
0125 };
0126 
0127 template < class ValueType > struct container_gen< hash_multimapS, ValueType >
0128 {
0129     typedef boost::unordered_multiset< ValueType > type;
0130 };
0131 
0132 template < class StorageSelector > struct parallel_edge_traits
0133 {
0134 };
0135 
0136 template <> struct parallel_edge_traits< vecS >
0137 {
0138     typedef allow_parallel_edge_tag type;
0139 };
0140 
0141 template <> struct parallel_edge_traits< listS >
0142 {
0143     typedef allow_parallel_edge_tag type;
0144 };
0145 
0146 template <> struct parallel_edge_traits< setS >
0147 {
0148     typedef disallow_parallel_edge_tag type;
0149 };
0150 
0151 template <> struct parallel_edge_traits< multisetS >
0152 {
0153     typedef allow_parallel_edge_tag type;
0154 };
0155 
0156 template <> struct parallel_edge_traits< hash_setS >
0157 {
0158     typedef disallow_parallel_edge_tag type;
0159 };
0160 
0161 // mapS is obsolete, replaced with setS
0162 template <> struct parallel_edge_traits< mapS >
0163 {
0164     typedef disallow_parallel_edge_tag type;
0165 };
0166 
0167 template <> struct parallel_edge_traits< hash_mapS >
0168 {
0169     typedef disallow_parallel_edge_tag type;
0170 };
0171 
0172 template <> struct parallel_edge_traits< hash_multisetS >
0173 {
0174     typedef allow_parallel_edge_tag type;
0175 };
0176 
0177 template <> struct parallel_edge_traits< hash_multimapS >
0178 {
0179     typedef allow_parallel_edge_tag type;
0180 };
0181 
0182 namespace detail
0183 {
0184     template < class Directed > struct is_random_access
0185     {
0186         enum
0187         {
0188             value = false
0189         };
0190         typedef mpl::false_ type;
0191     };
0192     template <> struct is_random_access< vecS >
0193     {
0194         enum
0195         {
0196             value = true
0197         };
0198         typedef mpl::true_ type;
0199     };
0200 
0201 } // namespace detail
0202 
0203 template < typename Selector > struct is_distributed_selector : mpl::false_
0204 {
0205 };
0206 
0207 //===========================================================================
0208 // The adjacency_list_traits class, which provides a way to access
0209 // some of the associated types of an adjacency_list type without
0210 // having to first create the adjacency_list type. This is useful
0211 // when trying to create interior vertex or edge properties who's
0212 // value type is a vertex or edge descriptor.
0213 
0214 template < class OutEdgeListS = vecS, class VertexListS = vecS,
0215     class DirectedS = directedS, class EdgeListS = listS >
0216 struct adjacency_list_traits
0217 {
0218     typedef
0219         typename detail::is_random_access< VertexListS >::type is_rand_access;
0220     typedef typename DirectedS::is_bidir_t is_bidir;
0221     typedef typename DirectedS::is_directed_t is_directed;
0222 
0223     typedef typename mpl::if_< is_bidir, bidirectional_tag,
0224         typename mpl::if_< is_directed, directed_tag,
0225             undirected_tag >::type >::type directed_category;
0226 
0227     typedef typename parallel_edge_traits< OutEdgeListS >::type
0228         edge_parallel_category;
0229 
0230     typedef std::size_t vertices_size_type;
0231     typedef void* vertex_ptr;
0232     typedef typename mpl::if_< is_rand_access, vertices_size_type,
0233         vertex_ptr >::type vertex_descriptor;
0234     typedef detail::edge_desc_impl< directed_category, vertex_descriptor >
0235         edge_descriptor;
0236 
0237 private:
0238     // Logic to figure out the edges_size_type
0239     struct dummy
0240     {
0241     };
0242     typedef typename container_gen< EdgeListS, dummy >::type EdgeContainer;
0243     typedef typename DirectedS::is_bidir_t BidirectionalT;
0244     typedef typename DirectedS::is_directed_t DirectedT;
0245     typedef typename mpl::and_< DirectedT,
0246         typename mpl::not_< BidirectionalT >::type >::type on_edge_storage;
0247 
0248 public:
0249     typedef typename mpl::if_< on_edge_storage, std::size_t,
0250         typename EdgeContainer::size_type >::type edges_size_type;
0251 };
0252 
0253 } // namespace boost
0254 
0255 #include <boost/graph/detail/adjacency_list.hpp>
0256 
0257 namespace boost
0258 {
0259 
0260 //===========================================================================
0261 // The adjacency_list class.
0262 //
0263 
0264 template < class OutEdgeListS = vecS, // a Sequence or an AssociativeContainer
0265     class VertexListS = vecS, // a Sequence or a RandomAccessContainer
0266     class DirectedS = directedS, class VertexProperty = no_property,
0267     class EdgeProperty = no_property, class GraphProperty = no_property,
0268     class EdgeListS = listS >
0269 class adjacency_list
0270 : // Support for named vertices
0271   // This needs to be inherited from first to ensure it's initialized before the
0272   // "base" (i.e. detail::adj_list_gen), because the "base" might indirectly
0273   // call functions on it during its construction.
0274   public graph::maybe_named_graph<
0275       adjacency_list< OutEdgeListS, VertexListS, DirectedS, VertexProperty,
0276           EdgeProperty, GraphProperty, EdgeListS >,
0277       typename adjacency_list_traits< OutEdgeListS, VertexListS, DirectedS,
0278           EdgeListS >::vertex_descriptor,
0279       VertexProperty >,
0280  public detail::adj_list_gen<
0281       adjacency_list< OutEdgeListS, VertexListS, DirectedS, VertexProperty,
0282           EdgeProperty, GraphProperty, EdgeListS >,
0283       VertexListS, OutEdgeListS, DirectedS, VertexProperty, EdgeProperty,
0284       GraphProperty, EdgeListS >::type
0285 {
0286 public:
0287     typedef GraphProperty graph_property_type;
0288     typedef typename lookup_one_property< GraphProperty, graph_bundle_t >::type
0289         graph_bundled;
0290 
0291     typedef VertexProperty vertex_property_type;
0292     typedef
0293         typename lookup_one_property< VertexProperty, vertex_bundle_t >::type
0294             vertex_bundled;
0295 
0296     typedef EdgeProperty edge_property_type;
0297     typedef typename lookup_one_property< EdgeProperty, edge_bundle_t >::type
0298         edge_bundled;
0299 
0300 private:
0301     typedef adjacency_list self;
0302     typedef typename detail::adj_list_gen< self, VertexListS, OutEdgeListS,
0303         DirectedS, vertex_property_type, edge_property_type, GraphProperty,
0304         EdgeListS >::type Base;
0305 
0306 public:
0307     typedef typename Base::stored_vertex stored_vertex;
0308     typedef typename Base::vertices_size_type vertices_size_type;
0309     typedef typename Base::edges_size_type edges_size_type;
0310     typedef typename Base::degree_size_type degree_size_type;
0311     typedef typename Base::vertex_descriptor vertex_descriptor;
0312     typedef typename Base::edge_descriptor edge_descriptor;
0313     typedef OutEdgeListS out_edge_list_selector;
0314     typedef VertexListS vertex_list_selector;
0315     typedef DirectedS directed_selector;
0316     typedef EdgeListS edge_list_selector;
0317 
0318     adjacency_list(const GraphProperty& p = GraphProperty())
0319     : m_property(new graph_property_type(p))
0320     {
0321     }
0322 
0323     adjacency_list(const adjacency_list& x)
0324     : Base(x), m_property(new graph_property_type(*x.m_property))
0325     {
0326     }
0327 
0328     adjacency_list& operator=(const adjacency_list& x)
0329     {
0330         // TBD: probably should give the strong guarantee
0331         if (&x != this)
0332         {
0333             Base::operator=(x);
0334 
0335             // Copy/swap the ptr since we can't just assign it...
0336             property_ptr p(new graph_property_type(*x.m_property));
0337             m_property.swap(p);
0338         }
0339         return *this;
0340     }
0341 
0342     // Required by Mutable Graph
0343     adjacency_list(vertices_size_type num_vertices,
0344         const GraphProperty& p = GraphProperty())
0345     : Base(num_vertices), m_property(new graph_property_type(p))
0346     {
0347     }
0348 
0349     // Required by Iterator Constructible Graph
0350     template < class EdgeIterator >
0351     adjacency_list(EdgeIterator first, EdgeIterator last, vertices_size_type n,
0352         edges_size_type = 0, const GraphProperty& p = GraphProperty())
0353     : Base(n, first, last), m_property(new graph_property_type(p))
0354     {
0355     }
0356 
0357     template < class EdgeIterator, class EdgePropertyIterator >
0358     adjacency_list(EdgeIterator first, EdgeIterator last,
0359         EdgePropertyIterator ep_iter, vertices_size_type n, edges_size_type = 0,
0360         const GraphProperty& p = GraphProperty())
0361     : Base(n, first, last, ep_iter), m_property(new graph_property_type(p))
0362     {
0363     }
0364 
0365     void swap(adjacency_list& x)
0366     {
0367         // Is there a more efficient way to do this?
0368         adjacency_list tmp(x);
0369         x = *this;
0370         *this = tmp;
0371     }
0372 
0373     void clear()
0374     {
0375         this->clearing_graph();
0376         Base::clear();
0377     }
0378 
0379 #ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES
0380     // Directly access a vertex or edge bundle
0381     vertex_bundled& operator[](vertex_descriptor v)
0382     {
0383         return get(vertex_bundle, *this)[v];
0384     }
0385 
0386     const vertex_bundled& operator[](vertex_descriptor v) const
0387     {
0388         return get(vertex_bundle, *this)[v];
0389     }
0390 
0391     edge_bundled& operator[](edge_descriptor e)
0392     {
0393         return get(edge_bundle, *this)[e];
0394     }
0395 
0396     const edge_bundled& operator[](edge_descriptor e) const
0397     {
0398         return get(edge_bundle, *this)[e];
0399     }
0400 
0401     graph_bundled& operator[](graph_bundle_t) { return get_property(*this); }
0402 
0403     graph_bundled const& operator[](graph_bundle_t) const
0404     {
0405         return get_property(*this);
0406     }
0407 #endif
0408 
0409     //  protected:  (would be protected if friends were more portable)
0410     typedef scoped_ptr< graph_property_type > property_ptr;
0411     property_ptr m_property;
0412 };
0413 
0414 #define ADJLIST_PARAMS                                               \
0415     typename OEL, typename VL, typename D, typename VP, typename EP, \
0416         typename GP, typename EL
0417 #define ADJLIST adjacency_list< OEL, VL, D, VP, EP, GP, EL >
0418 
0419 template < ADJLIST_PARAMS, typename Tag, typename Value >
0420 inline void set_property(ADJLIST& g, Tag tag, Value const& value)
0421 {
0422     get_property_value(*g.m_property, tag) = value;
0423 }
0424 
0425 template < ADJLIST_PARAMS, typename Tag >
0426 inline typename graph_property< ADJLIST, Tag >::type& get_property(
0427     ADJLIST& g, Tag tag)
0428 {
0429     return get_property_value(*g.m_property, tag);
0430 }
0431 
0432 template < ADJLIST_PARAMS, typename Tag >
0433 inline typename graph_property< ADJLIST, Tag >::type const& get_property(
0434     ADJLIST const& g, Tag tag)
0435 {
0436     return get_property_value(*g.m_property, tag);
0437 }
0438 
0439 // dwa 09/25/00 - needed to be more explicit so reverse_graph would work.
0440 template < class Directed, class Vertex, class OutEdgeListS, class VertexListS,
0441     class DirectedS, class VertexProperty, class EdgeProperty,
0442     class GraphProperty, class EdgeListS >
0443 inline Vertex source(const detail::edge_base< Directed, Vertex >& e,
0444     const adjacency_list< OutEdgeListS, VertexListS, DirectedS, VertexProperty,
0445         EdgeProperty, GraphProperty, EdgeListS >&)
0446 {
0447     return e.m_source;
0448 }
0449 
0450 template < class Directed, class Vertex, class OutEdgeListS, class VertexListS,
0451     class DirectedS, class VertexProperty, class EdgeProperty,
0452     class GraphProperty, class EdgeListS >
0453 inline Vertex target(const detail::edge_base< Directed, Vertex >& e,
0454     const adjacency_list< OutEdgeListS, VertexListS, DirectedS, VertexProperty,
0455         EdgeProperty, GraphProperty, EdgeListS >&)
0456 {
0457     return e.m_target;
0458 }
0459 
0460 // Mutability Traits
0461 template < ADJLIST_PARAMS > struct graph_mutability_traits< ADJLIST >
0462 {
0463     typedef mutable_property_graph_tag category;
0464 };
0465 
0466 // Can't remove vertices from adjacency lists with VL==vecS
0467 template < typename OEL, typename D, typename VP, typename EP, typename GP,
0468     typename EL >
0469 struct graph_mutability_traits< adjacency_list< OEL, vecS, D, VP, EP, GP, EL > >
0470 {
0471     typedef add_only_property_graph_tag category;
0472 };
0473 #undef ADJLIST_PARAMS
0474 #undef ADJLIST
0475 
0476 } // namespace boost
0477 
0478 #endif // BOOST_GRAPH_ADJACENCY_LIST_HPP