2008-09-16

boost::iterator_property_map

iterator_property_map is an adapter which adapts the random access container to the property map.

When a graph algorithm needs a temporary property map and its result is not required to be saved in the graph, it's convenient to use this adapter to adapt the standard container and feed it into algorithm.

typedef RankVector::iterator RankRAIter;
typedef std::vector<VertexDescriptor> ParentVector;
typedef ParentVector::iterator ParentRAIter;

typedef boost::iterator_property_map<RankRAIter, IndexMap,
std::iterator_traits<RankRAIter>::value_type,
std::iterator_traits<RankRAIter>::reference> RankMap;

typedef boost::iterator_property_map<ParentRAIter, IndexMap,
std::iterator_traits<ParentRAIter>::value_type,
std::iterator_traits<ParentRAIter>::reference> ParentMap;

RankVector ranks( d_numOfVertices );
ParentVector parents( d_numOfVertices );
boost::disjoint_sets<RankMap, ParentMap> dset(
boost::make_iterator_property_map(
anks.begin(), boost::get( boost::vertex_index, g ), ranks[0] ),
boost::make_iterator_property_map(
parents.begin(), boost::get( boost::vertex_index, g ),
parents[0] )
);

沒有留言:

張貼留言