2424
2525using namespace solidity ::util;
2626
27- ContiguousDisjointSet::ContiguousDisjointSet (size_t const _numNodes):
27+ template <typename ValueType>
28+ ContiguousDisjointSet<ValueType>::ContiguousDisjointSet(size_t const _numNodes):
2829 m_parents (_numNodes),
2930 m_neighbors(_numNodes),
3031 m_sizes(_numNodes, static_cast <value_type>(1 )),
@@ -35,9 +36,11 @@ ContiguousDisjointSet::ContiguousDisjointSet(size_t const _numNodes):
3536 std::iota (m_neighbors.begin (), m_neighbors.end (), 0 );
3637}
3738
38- size_t ContiguousDisjointSet::numSets () const { return m_numSets; }
39+ template <typename ValueType>
40+ size_t ContiguousDisjointSet<ValueType>::numSets() const { return m_numSets; }
3941
40- ContiguousDisjointSet::value_type ContiguousDisjointSet::find (value_type const _element) const
42+ template <typename ValueType>
43+ typename ContiguousDisjointSet<ValueType>::value_type ContiguousDisjointSet<ValueType>::find(value_type const _element) const
4144{
4245 solAssert (_element < m_parents.size ());
4346 // path halving
@@ -50,7 +53,8 @@ ContiguousDisjointSet::value_type ContiguousDisjointSet::find(value_type const _
5053 return rootElement;
5154}
5255
53- void ContiguousDisjointSet::merge (value_type const _x, value_type const _y, bool const _mergeBySize)
56+ template <typename ValueType>
57+ void ContiguousDisjointSet<ValueType>::merge(value_type const _x, value_type const _y, bool const _mergeBySize)
5458{
5559 auto xRoot = find (_x);
5660 auto yRoot = find (_y);
@@ -69,17 +73,20 @@ void ContiguousDisjointSet::merge(value_type const _x, value_type const _y, bool
6973 --m_numSets;
7074}
7175
72- bool ContiguousDisjointSet::sameSubset (value_type const _x, value_type const _y) const
76+ template <typename ValueType>
77+ bool ContiguousDisjointSet<ValueType>::sameSubset(value_type const _x, value_type const _y) const
7378{
7479 return find (_x) == find (_y);
7580}
7681
77- ContiguousDisjointSet::size_type ContiguousDisjointSet::sizeOfSubset (value_type const _x) const
82+ template <typename ValueType>
83+ typename ContiguousDisjointSet<ValueType>::size_type ContiguousDisjointSet<ValueType>::sizeOfSubset(value_type const _x) const
7884{
7985 return m_sizes[find (_x)];
8086}
8187
82- std::set<ContiguousDisjointSet::value_type> ContiguousDisjointSet::subset (value_type const _x) const
88+ template <typename ValueType>
89+ std::set<typename ContiguousDisjointSet<ValueType>::value_type> ContiguousDisjointSet<ValueType>::subset(value_type const _x) const
8390{
8491 solAssert (_x < m_parents.size ());
8592 std::set<value_type> result{_x};
@@ -92,7 +99,8 @@ std::set<ContiguousDisjointSet::value_type> ContiguousDisjointSet::subset(value_
9299 return result;
93100}
94101
95- std::vector<std::set<ContiguousDisjointSet::value_type>> ContiguousDisjointSet::subsets () const
102+ template <typename ValueType>
103+ std::vector<std::set<typename ContiguousDisjointSet<ValueType>::value_type>> ContiguousDisjointSet<ValueType>::subsets() const
96104{
97105 std::vector<std::set<value_type>> result;
98106 std::vector<std::uint8_t > visited (m_parents.size (), false );
@@ -107,3 +115,5 @@ std::vector<std::set<ContiguousDisjointSet::value_type>> ContiguousDisjointSet::
107115 }
108116 return result;
109117}
118+
119+ template class solidity ::util::ContiguousDisjointSet<std::uint32_t >;
0 commit comments