6 #ifndef JLM_UTIL_DISJOINTSET_HPP
7 #define JLM_UTIL_DISJOINTSET_HPP
12 #include <unordered_map>
13 #include <unordered_set>
112 static std::unique_ptr<Set>
115 return std::unique_ptr<Set>(
new Set(
value));
125 while (parent != child)
139 return value_ == other.value_;
197 SetIterator(
const typename std::unordered_set<const Set *>::const_iterator & it)
243 typename std::unordered_set<const Set *>::const_iterator
it_;
282 roots_ = std::move(other.roots_);
283 values_ = std::move(other.values_);
291 for (
auto & element : elements)
299 return values_.find(element)->second.get();
302 auto s =
values_.find(element)->second.get();
348 find(
const T & element)
const noexcept
352 return values_.find(element)->second->root();
366 return find(element);
375 auto root1 =
find(e1);
376 auto root2 =
find(e2);
383 auto size1 = root1->size_;
384 auto size2 = root2->size_;
386 std::swap(root1, root2);
389 std::swap(root1->next_, root2->next_);
392 root2->parent_ = root1;
393 root1->size_ = size1 + size2;
406 std::unordered_map<T, std::unique_ptr<Set>>
values_;
MemberIterator & operator++()
MemberIterator(const Set *node)
bool operator!=(const MemberIterator &other) const
pointer operator->() const
bool operator==(const MemberIterator &other) const
std::ptrdiff_t difference_type
std::forward_iterator_tag iterator_category
reference operator*() const
MemberIterator operator++(int)
SetIterator & operator++()
const Set & operator*() const
bool operator==(const SetIterator &other) const
SetIterator(const typename std::unordered_set< const Set * >::const_iterator &it)
std::forward_iterator_tag iterator_category
bool operator!=(const SetIterator &other) const
ptrdiff_t difference_type
std::unordered_set< const Set * >::const_iterator it_
const Set * operator->() const
SetIterator operator++(int)
bool is_root() const noexcept
Set & operator=(Set &&other)=delete
bool operator!=(const Set &other) const noexcept
size_t nmembers() const noexcept
MemberIterator begin() const
Set & operator=(const Set &)=delete
MemberIterator end() const
const Set * root() const noexcept
const T & value() const noexcept
bool operator==(const Set &other) const noexcept
static std::unique_ptr< Set > create(const T &value)
bool empty() const noexcept
DisjointSet & operator=(const DisjointSet &other)
const Set * merge(const T &e1, const T &e2)
void insert(const std::vector< T > &elements)
size_t nvalues() const noexcept
size_t nsets() const noexcept
const Set * find(const T &element) const noexcept
DisjointSet(const std::vector< T > &elements)
std::unordered_map< T, std::unique_ptr< Set > > values_
constexpr DisjointSet()=default
DisjointSet(DisjointSet &&other)
const Set * find_or_insert(const T &element) noexcept
DisjointSet(const DisjointSet &other)
DisjointSet & operator=(DisjointSet &&other)
const Set * insert(const T &element)
SetIterator begin() const
bool contains(const T &element) const
std::unordered_set< const Set * > roots_