Skip to content

Commit

Permalink
Parameterize the index map type, some code style & doc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yi-ji committed Jun 20, 2020
1 parent 77a27e4 commit e38cfc8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
8 changes: 4 additions & 4 deletions doc/link_cut_trees.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h3>Example</h3>

<pre>
...
link_cut_trees&lt;ElementParentMap, ElementChildMap&gt; lct(p, l, r);
link_cut_trees&lt;ElementParentMap, ElementChildMap&gt; lct(parent_map, left_child_map, right_child_map);

for (ui = vertices(G).first; ui != vertices(G).second; ++ui)
lct.make_tree(*ui);
Expand Down Expand Up @@ -88,7 +88,7 @@ <h3>Members</h3>
</tr>

<tr>
<td><tt>link_cut_trees(const disjoint_sets&amp; c)</tt></td>
<td><tt>link_cut_trees(const link_cut_trees&amp; c)</tt></td>

<td>Copy constructor.</td>
</tr>
Expand Down Expand Up @@ -188,8 +188,8 @@ <h3>Members</h3>
height="31" width="88"></a></p>

<p>Revised
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->07
October, 2019<!--webbot bot="Timestamp" endspan i-checksum="38508" --></p>
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->
June, 2020<!--webbot bot="Timestamp" endspan i-checksum="38508" --></p>

<table summary="">
<tr valign="top">
Expand Down
9 changes: 5 additions & 4 deletions include/boost/graph/link_cut_trees.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace boost
public:
inline link_cut_trees(ElementParentMap p, ElementChildMap l, ElementChildMap r) : parent(p), left(l), right(r) {}

inline link_cut_trees(const link_cut_trees<ElementParentMap, ElementChildMap> &c)
inline link_cut_trees(const link_cut_trees &c)
: parent(c.parent), left(c.left), right(c.right) {}

template <class Element>
Expand Down Expand Up @@ -222,14 +222,15 @@ namespace boost
};


template <class ID = identity_property_map, class InverseID = boost::unordered_map<typename property_traits<ID>::value_type, typename property_traits<ID>::key_type> >
template <class ID = identity_property_map,
class InverseID = boost::unordered_map<typename property_traits<ID>::value_type, typename property_traits<ID>::key_type>,
class IndexMapContainer = boost::unordered_map<typename property_traits<ID>::value_type, typename property_traits<ID>::value_type> >
class link_cut_trees_with_storage :
public link_cut_trees<associative_property_map<boost::unordered_map<typename property_traits<ID>::value_type, typename property_traits<ID>::value_type> > >
public link_cut_trees<associative_property_map<IndexMapContainer> >
{
public:
typedef typename property_traits<ID>::key_type Vertex;
typedef typename property_traits<ID>::value_type Index;
typedef boost::unordered_map<Index, Index> IndexMapContainer;
typedef associative_property_map<IndexMapContainer> IndexMap;
typedef link_cut_trees<IndexMap> LCT;

Expand Down
22 changes: 22 additions & 0 deletions test/link_cut_trees_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,26 @@ BOOST_AUTO_TEST_CASE(link_cut_trees_test5)
}
link_cut_trees_t lct(id, inverse_id);
test_link_cut_trees<link_cut_trees_t, std::string>(lct, elements);
}

BOOST_AUTO_TEST_CASE(link_cut_trees_test6)
{
typedef associative_property_map< std::map<std::string, int> > id_map_t;
typedef vector_property_map<std::string> inverse_id_map_t;
typedef link_cut_trees_with_storage<id_map_t, inverse_id_map_t, typename std::map<int, int> > link_cut_trees_t;
std::vector<std::string> elements;
std::vector<int> numbers(100);
std::map<std::string, int> id_map;
id_map_t id(id_map);
inverse_id_map_t inverse_id;
boost::range::iota(numbers, -49);
BOOST_FOREACH(int i, numbers)
{
std::string i_str = lexical_cast<std::string, int>(i);
elements.push_back(i_str);
put(id, i_str, i+49);
put(inverse_id, i+49, i_str);
}
link_cut_trees_t lct(id, inverse_id);
test_link_cut_trees<link_cut_trees_t, std::string>(lct, elements);
}

0 comments on commit e38cfc8

Please sign in to comment.