33 #include "../exceptions/WOutOfBounds.h"
34 #include "WUnionFind.h"
39 for(
size_t i = 0; i < size; ++i )
49 throw WOutOfBounds( std::string(
"Element index in UnionFind greater than overall elements!" ) );
64 throw WOutOfBounds( std::string(
"Element index in UnionFind greater than overall elements!" ) );
71 size_t ci =
find( i );
72 size_t cj =
find( j );
84 std::map< size_t, std::set< size_t > > sets;
85 size_t maxSetSizeSoFar = 0;
86 size_t maxSetElement = 0;
89 size_t cE =
find( i );
90 sets[ cE ].insert( i );
91 if( sets[ cE ].size() > maxSetSizeSoFar )
93 maxSetSizeSoFar = sets[ cE ].size();
97 return std::shared_ptr< std::set< size_t > >(
new std::set< size_t >( sets[ maxSetElement ] ) );
Indicates invalid element access of a container.
std::shared_ptr< std::set< size_t > > getMaxSet()
Computes the set with maximum number of elements.
WUnionFind(size_t size)
Creates a new union find datastructure with size elements where each element is initialized as a sing...
void merge(size_t i, size_t j)
Merges two components (iow: makes a union) where the given elements are members of.
size_t find(size_t x)
Find the canonical element of the given element and do path compression.
std::vector< size_t > m_component
Stores for each index its ID.