6 #ifndef JLM_UTIL_HASHSET_HPP
7 #define JLM_UTIL_HASHSET_HPP
12 #include <unordered_set>
22 template<
typename ItemType,
typename HashFunctor = Hash<ItemType>>
25 using InternalSet = std::unordered_set<ItemType, HashFunctor>;
45 [[nodiscard]] ItemType *
48 return It_.operator->();
54 return It_.operator*();
91 typename InternalSet::const_iterator
It_;
98 template<class InputIt>
108 :
Set_(std::move(other.Set_))
111 HashSet(std::initializer_list<ItemType> initializerList)
112 :
Set_(initializerList)
115 template<
typename OtherHashFunctor>
116 explicit HashSet(
const std::unordered_set<ItemType, OtherHashFunctor> & other)
117 :
Set_(other.begin(), other.end())
130 Set_ = std::move(other.Set_);
152 return Set_.find(item) !=
Set_.end();
165 if (
Size() > other.Size())
170 for (
auto & item : other.Items())
172 if (!other.Contains(item))
186 [[nodiscard]] std::size_t
213 Set_.emplace(std::move(item));
214 return (size !=
Size());
238 const size_t sizeBefore =
Size();
239 for (
auto & item : other.
Items())
241 return sizeBefore !=
Size();
256 std::swap(*
this, other);
271 auto isContained = [&](
const ItemType & item)
290 std::swap(*
this, other);
311 auto isInOther = [&](
const ItemType & item)
320 for (
auto & item : other.
Set_)
334 return Set_.erase(item) != 0;
349 size_t numRemoved = 0;
350 auto it =
Set_.begin();
351 while (it !=
Set_.end())
387 if (
Size() != other.Size())
390 for (
auto & item :
Set_)
391 if (!other.Contains(item))
ItemConstIterator(const typename InternalSet::const_iterator &it)
InternalSet::const_iterator It_
const ItemType & operator*() const
ItemType * Item() const noexcept
ItemConstIterator & operator++()
ItemType * operator->() const
std::forward_iterator_tag iterator_category
bool operator!=(const ItemConstIterator &other) const
ItemConstIterator operator++(int)
bool operator==(const ItemConstIterator &other) const
std::ptrdiff_t difference_type
void DifferenceWith(const HashSet< ItemType > &other)
bool insert(ItemType item)
std::unordered_set< ItemType, HashFunctor > InternalSet
ItemConstIterator Erase(ItemConstIterator iterator)
size_t RemoveWhere(const F &match)
~HashSet() noexcept=default
std::size_t Size() const noexcept
HashSet & operator=(const HashSet &other)
bool IsSubsetOf(const HashSet< ItemType > &other) const noexcept
bool operator==(const HashSet< ItemType > &other) const noexcept
bool operator!=(const HashSet< ItemType > &other) const noexcept
HashSet & operator=(HashSet &&other) noexcept
HashSet(const HashSet &other)
bool Contains(const ItemType &item) const noexcept
void IntersectWith(const HashSet< ItemType > &other)
bool UnionWithAndClear(HashSet< ItemType > &other)
bool Remove(ItemType item)
HashSet(HashSet &&other) noexcept
HashSet(const std::unordered_set< ItemType, OtherHashFunctor > &other)
IteratorRange< ItemConstIterator > Items() const noexcept
HashSet(std::initializer_list< ItemType > initializerList)
bool IsEmpty() const noexcept
void IntersectWithAndClear(HashSet< ItemType > &other)
bool UnionWith(const HashSet< ItemType > &other)
jlm::rvsdg::Output * match(size_t nbits, const std::unordered_map< uint64_t, uint64_t > &mapping, uint64_t default_alternative, size_t nalternatives, jlm::rvsdg::Output *operand)