Skip to content

Commit

Permalink
fix implementation of sizeOfsetcontaining
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas committed Oct 22, 2021
1 parent 78965e0 commit 7684ae0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions include/unionfind/unionfind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,21 @@ class UnionFind
return number_of_sets_;
}

[[nodiscard]] auto sizeOfSetContaining(std::size_t elem) const noexcept
[[nodiscard]] auto sizeOfSetContaining(std::size_t elem) noexcept
-> std::optional<std::size_t>
{
if(elem >= root_.size()) {
auto root_opt = find(elem);
if(!root_opt) {
return std::nullopt;
}

return size_[root_[elem]];
return size_[root_opt.value()];
}

[[nodiscard]] auto sizeOfSetContainingUnsafe(std::size_t elem) const noexcept
[[nodiscard]] auto sizeOfSetContainingUnsafe(std::size_t elem) noexcept
-> std::size_t
{
return size_[root_[elem]];
auto root = findUnsafe(elem);
return size_[root];
}


Expand Down

0 comments on commit 7684ae0

Please sign in to comment.