59 template <
typename Key >
65 template <
typename Key >
68 : set._inside_.cbeginSafe()} {
73 template <
typename Key >
80 template <
typename Key >
87 template <
typename Key >
94 template <
typename Key >
100 template <
typename Key >
108 template <
typename Key >
115 template <
typename Key >
123 template <
typename Key >
133 template <
typename Key >
140 template <
typename Key >
146 template <
typename Key >
154 template <
typename Key >
161 template <
typename Key >
165 return _ht_iter_.key();
169 template <
typename Key >
178 template <
typename Key >
188 template <
typename Key >
194 template <
typename Key >
201 template <
typename Key >
208 template <
typename Key >
215 template <
typename Key >
221 template <
typename Key >
229 template <
typename Key >
231 _ht_iter_ = std::move(from._ht_iter_);
236 template <
typename Key >
246 template <
typename Key >
253 template <
typename Key >
259 template <
typename Key >
266 template <
typename Key >
272 template <
typename Key >
280 template <
typename Key >
284 return &(_ht_iter_.key());
289 template <
typename Key >
299 template <
typename Key >
305 GUM_CONSTRUCTOR(
Set);
309 template <
typename Key >
312 GUM_CONSTRUCTOR(
Set);
313 for (
const auto& elt: list) {
319 template <
typename Key >
325 template <
typename Key >
331 template <
typename Key >
337 template <
typename Key >
353 template <
typename Key >
383 template <
typename Key >
385 _inside_ = std::move(from._inside_);
390 template <
typename Key >
395 if (
size() != h2.
size())
return false;
400 if (!h2.
exists(iter.key()))
return false;
407 template <
typename Key >
413 template <
typename Key >
419 template <
typename Key >
425 template <
typename Key >
431 template <
typename Key >
437 template <
typename Key >
443 template <
typename Key >
449 template <
typename Key >
455 template <
typename Key >
461 template <
typename Key >
467 template <
typename Key >
479 template <
typename Key >
481 _inside_.setResizePolicy(new_policy);
490 template <
typename Key >
496 template <
typename Key >
501 template <
typename Key >
503 if (this->
size() >= s.
size()) {
return false; }
505 for (
const auto& elt: *
this) {
506 if (!s.
contains(elt)) {
return false; }
511 template <
typename Key >
516 template <
typename Key >
518 if (this->
size() > s.
size()) {
return false; }
520 for (
const auto& elt: *
this) {
521 if (!s.
contains(elt)) {
return false; }
526 template <
typename Key >
532 template <
typename Key >
538 template <
typename Key >
556 template <
typename Key >
563 _inside_.insert(std::move(k),
true);
574 template <
typename Key >
575 template <
typename... Args >
577 insert(std::move(Key(std::forward< Args >(args)...)));
581 template <
typename Key >
592 template <
typename Key >
596 auto key = *this->
begin();
602 template <
typename Key >
614 template <
typename Key >
621 template <
typename Key >
628 template <
typename Key >
635 template <
typename Key >
641 template <
typename Key >
647 template <
typename Key >
656 if (h2.
exists(iter.key())) h_r.
insert(iter.key(),
true);
668 template <
typename Key >
672 for (
auto iter =
_inside_.beginSafe(); iter !=
_inside_.endSafe(); ++iter) {
681 template <
typename Key >
693 template <
typename Key >
700 if (!h_r.
exists(iter.key())) h_r.
insert(iter.key(),
true);
707 template <
typename Key >
715 if (!h2.
exists(iter.key())) h_r.
insert(iter.key(),
true);
721 template <
typename Key >
723 std::stringstream out;
727 for (iterator iter = begin(); iter != end(); ++iter) {
744 template <
typename Key >
751 template <
typename Key >
752 template <
typename NewKey >
757 if (size == 0) size = std::max(
Size(2), _inside_.size() / 2);
765 table.insert(iter.key(), f(iter.key()));
772 template <
typename Key >
773 template <
typename NewKey >
786 table.
insert(iter.key(), val);
793 template <
typename Key >
794 template <
typename NewKey >
809 template <
typename T >
812 for (
const auto& k: key) {
821 template <
typename T >
static Size castToSize(const Set< T > &key)
Returns the value of a key as a Size.
This class should be useless as only its specializations should be used.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
const_iterator cbegin() const
Returns an unsafe const_iterator pointing to the beginning of the hashtable.
const const_iterator & cend() const noexcept
Returns the unsafe const_iterator pointing to the end of the hashtable.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Size size() const noexcept
Returns the number of elements stored into the hashtable.
Generic doubly linked lists.
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Exception : the element we looked for cannot be found.
Safe iterators for the Set class.
const Key * operator->() const
Returns a pointer to the element pointed to by the iterator.
Position
An enumeration to position the iterator at the beginning or the end of the set.
bool operator==(const SetIteratorSafe< Key > &from) const noexcept
Indicates whether two iterators point toward the same element of a same set.
SetIteratorSafe< Key > & operator+=(Size i) noexcept
Makes the iterator point to i elements further in the set.
SetIteratorSafe()
Default constructor: the iterator points toward nothing.
~SetIteratorSafe() noexcept
Class destructor.
SetIteratorSafe< Key > & operator++() noexcept
Increments the iterator.
HashTableConstIteratorSafe< Key, bool > _ht_iter_
The underlying iterator for the set's hash table containing the data.
void clear() noexcept
makes the iterator point toward nothing (in particular, it is not related anymore to its current set)...
bool operator!=(const SetIteratorSafe< Key > &from) const noexcept
Indicates whether two iterators point to different elements or sets.
SetIteratorSafe< Key > & operator=(const SetIteratorSafe< Key > &from)
Assignment operator.
const Key & operator*() const
Returns the element pointed to by the iterator.
friend class Set< Key >
For efficiency, Set should be able to modify the hash table iterator.
SetIteratorSafe< Key > operator+(Size i) const
Returns a new iterator.
Unsafe iterators for the Set class.
SetIterator< Key > operator+(Size i) const noexcept
Returns a new iterator.
const Key * operator->() const
Returns a pointer to the element pointed to by the iterator.
SetIterator() noexcept
Default constructor: the iterator points toward nothing.
bool operator==(const SetIterator< Key > &from) const noexcept
Indicates whether two iterators point toward the same element of a same set.
void clear() noexcept
makes the iterator point toward nothing (in particular, it is not related anymore to its current set)...
~SetIterator() noexcept
Class destructor.
HashTableConstIterator< Key, bool > _ht_iter_
The underlying iterator for the set's hash table containing the data.
friend class Set< Key >
For efficiency, Set should be able to modify the hash table iterator.
Position
An enumeration to position the iterator at the beginning or the end of the set.
SetIterator< Key > & operator++() noexcept
Increments the iterator.
SetIterator< Key > & operator=(const SetIterator< Key > &from) noexcept
Assignment operator.
SetIterator< Key > & operator+=(Size i) noexcept
Makes the iterator point to i elements further in the set.
bool operator!=(const SetIterator< Key > &from) const noexcept
Indicates whether two iterators point to different elements or sets.
const Key & operator*() const
Returns the element pointed to by the iterator.
iterator begin() const
The usual unsafe begin iterator to parse the set.
SetIterator< Key > const_iterator
Types for STL compliance.
SetIteratorSafe< Key > const_iterator_safe
Types for STL compliance.
const iterator & end() const noexcept
The usual unsafe end iterator to parse the set.
const Set< Key > & operator*=(const Set< Key > &s2)
Intersection update operator.
HashTable< Key, bool > _inside_
A set of X's is actually a hash table whose keys are the X's.
Size size() const noexcept
Returns the number of elements in the set.
iterator_safe beginSafe() const
The usual safe begin iterator to parse the set.
List< NewKey > listMap(NewKey(*f)(const Key &)) const
A method to create a List of NewKey from the set.
Key popFirst()
Removes and returns an arbitrary element from the set.
const iterator_safe & endSafe() const noexcept
The usual safe end iterator to parse the set.
Set< Key > operator+(const Set< Key > &s2) const
Union operator.
Size capacity() const
Returns the capacity of the underlying hash table containing the set.
bool isSubsetOrEqual(const Set< Key > &s) const
bool isSupersetOrEqual(const Set< Key > &s) const
Set< Key > & operator=(const Set< Key > &from)
Copy operator.
friend class SetIteratorSafe< Key >
Friends to speed up access.
Set< Key > operator-(const Set< Key > &s2) const
Disjunction operator.
Set< Key > operator*(const Set< Key > &s2) const
Intersection operator.
const_iterator_safe cbeginSafe() const
The usual safe begin iterator to parse the set.
std::string toString() const
Prints the content of the set.
Set(Size capacity=HashTableConst::default_size, bool resize_policy=true)
Default constructor.
bool resizePolicy() const
Returns the current resizing policy of the underlying hash table.
SetIterator< Key > iterator
Types for STL compliance.
bool isStrictSubsetOf(const Set< Key > &s) const
SetIteratorSafe< Key > iterator_safe
Types for STL compliance.
const const_iterator & cend() const noexcept
The usual unsafe end iterator to parse the set.
void emplace(Args &&... args)
Emplace a new element in the set.
const Set< Key > & operator+=(const Set< Key > &s2)
Union update operator.
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
bool operator!=(const Set< Key > &s2) const
Mathematical inequality between two sets.
void setResizePolicy(const bool new_policy)
HashTable< Key, NewKey > hashMap(NewKey(*f)(const Key &), Size capacity=0) const
Creates a hashtable of NewKey from the set.
bool operator==(const Set< Key > &s2) const
Mathematical equality between two sets.
friend class SetIterator< Key >
bool isStrictSupersetOf(const Set< Key > &s) const
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Set< Key > & operator<<(const Key &k)
Adds a new element to the set (alias for insert).
void resize(Size new_capacity)
const_iterator cbegin() const
The usual unsafe begin iterator to parse the set.
void insert(const Key &k)
Inserts a new element into the set.
const const_iterator_safe & cendSafe() const noexcept
The usual safe end iterator to parse the set.
bool empty() const noexcept
Indicates whether the set is the empty set.
Set< Key > & operator>>(const Key &k)
Removes an element from the set (alias for erase).
void erase(const Key &k)
Erases an element from the set.
void clear()
Removes all the elements, if any, from the set.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
gum is the global namespace for all aGrUM entities
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
bool operator==(const HashTableIteratorSafe< Key, Val > &from) const noexcept
Checks whether two iterators are pointing toward equal elements.
static constexpr Size gold