60 template <
typename Key >
66 template <
typename Key >
68 _ht_iter_{pos ==
Position::END ? from._inside_.cendSafe() : from._inside_.cbeginSafe()} {
73 template <
typename Key >
80 template <
typename Key >
87 template <
typename Key >
94 template <
typename Key >
100 template <
typename Key >
105 template <
typename Key >
112 template <
typename Key >
120 template <
typename Key >
130 template <
typename Key >
137 template <
typename Key >
144 template <
typename Key >
149 template <
typename Key >
157 template <
typename Key >
166 template <
typename Key >
176 template <
typename Key >
182 template <
typename Key >
184 _ht_iter_{pos ==
Position::END ? from._inside_.cend() : from._inside_.cbegin()} {
189 template <
typename Key >
196 template <
typename Key >
203 template <
typename Key >
209 template <
typename Key >
214 template <
typename Key >
221 template <
typename Key >
231 template <
typename Key >
238 template <
typename Key >
245 template <
typename Key >
249 template <
typename Key >
257 template <
typename Key >
266 template <
typename Key >
276 template <
typename Key >
282 GUM_CONSTRUCTOR(
Set);
286 template <
typename Key >
290 for (
const auto& elt: list) {
296 template <
typename Key >
302 template <
typename Key >
308 template <
typename Key >
314 template <
typename Key >
330 template <
typename Key >
360 template <
typename Key >
362 if (
this != &from) {
_inside_ = std::move(from._inside_); }
367 template <
typename Key >
372 if (
size() != h2.
size()) {
return false; }
377 if (!h2.
exists(iter.key())) {
return false; }
384 template <
typename Key >
390 template <
typename Key >
396 template <
typename Key >
402 template <
typename Key >
408 template <
typename Key >
414 template <
typename Key >
420 template <
typename Key >
426 template <
typename Key >
432 template <
typename Key >
438 template <
typename Key >
450 template <
typename Key >
452 _inside_.setResizePolicy(new_policy);
461 template <
typename Key >
467 template <
typename Key >
472 template <
typename Key >
474 if (this->
size() >= s.
size()) {
return false; }
476 for (
const auto& elt: *
this) {
477 if (!s.
contains(elt)) {
return false; }
482 template <
typename Key >
487 template <
typename Key >
491 for (
const auto& elt: *
this) {
492 if (!s.
contains(elt)) {
return false; }
497 template <
typename Key >
503 template <
typename Key >
509 template <
typename Key >
527 template <
typename Key >
534 _inside_.insert(std::move(k),
true);
545 template <
typename Key >
546 template <
typename... Args >
548 insert(std::move(Key(std::forward< Args >(args)...)));
552 template <
typename Key >
563 template <
typename Key >
567 auto key = *this->
begin();
573 template <
typename Key >
585 template <
typename Key >
592 template <
typename Key >
594 insert(std::move(k));
599 template <
typename Key >
606 template <
typename Key >
612 template <
typename Key >
618 template <
typename Key >
624 if (size() < h2.
size()) {
627 if (h2.
exists(iter.key())) h_r.
insert(iter.key(),
true);
631 if (_inside_.exists(iter.key())) h_r.
insert(iter.key(),
true);
639 template <
typename Key >
643 for (
auto iter =
_inside_.beginSafe(); iter !=
_inside_.endSafe(); ++iter) {
652 template <
typename Key >
664 template <
typename Key >
671 if (!h_r.
exists(iter.key())) h_r.
insert(iter.key(),
true);
678 template <
typename Key >
686 if (!h2.
exists(iter.key())) h_r.
insert(iter.key(),
true);
692 template <
typename Key >
694 std::stringstream out;
698 for (iterator iter = begin(); iter != end(); ++iter) {
715 template <
typename Key >
722 template <
typename Key >
723 template <
typename NewKey >
736 table.insert(iter.key(), f(iter.key()));
743 template <
typename Key >
744 template <
typename NewKey >
757 table.
insert(iter.key(), val);
764 template <
typename Key >
765 template <
typename NewKey >
780 template <
typename T >
782 auto h =
static_cast< Size >(0);
783 for (
const auto& k: key) {
792 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.
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.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
Size size() const noexcept
Returns the number of elements stored into the hashtable.
const_iterator cbegin() const
Returns an unsafe const_iterator pointing to the beginning of 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.
SetIteratorSafe()
Default constructor: the iterator points toward nothing.
Position
An enumeration to position the iterator at the beginning or the end of the set.
void clear() noexcept
makes the iterator point toward nothing (in particular, it is not related anymore to its current set)...
const Key * operator->() const
Returns a pointer to the element pointed to by the iterator.
SetIteratorSafe< Key > operator+(Size i) const
Returns a new iterator.
SetIteratorSafe< Key > & operator=(const SetIteratorSafe< Key > &from)
Assignment operator.
SetIteratorSafe< Key > & operator++() noexcept
Increments the iterator.
bool operator==(const SetIteratorSafe< Key > &from) const noexcept
Indicates whether two iterators point toward the same element of a same set.
HashTableConstIteratorSafe< Key, bool > _ht_iter_
The underlying iterator for the set's hash table containing the data.
SetIteratorSafe< Key > & operator+=(Size i) noexcept
Makes the iterator point to i elements further in the set.
friend class Set< Key >
For efficiency, Set should be able to modify the hash table iterator.
const Key & operator*() const
Returns the element pointed to by the iterator.
~SetIteratorSafe() noexcept
Class destructor.
Unsafe iterators for the Set class.
SetIterator< Key > & operator++() noexcept
Increments the iterator.
const Key * operator->() const
Returns a pointer to the element pointed to by the iterator.
bool operator==(const SetIterator< Key > &iter) 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< Key > operator+(Size nb) const noexcept
Returns a new iterator.
SetIterator< Key > & operator+=(Size nb) noexcept
Makes the iterator point to i elements further in the set.
~SetIterator() noexcept
Class destructor.
HashTableConstIterator< Key, bool > _ht_iter_
The underlying iterator for the set's hash table containing the data.
SetIterator() noexcept
Default constructor: the iterator points toward nothing.
SetIterator< Key > & operator=(const SetIterator< Key > &iter) noexcept
Assignment operator.
const Key & operator*() const
Returns the element pointed to by the iterator.
Position
An enumeration to position the iterator at the beginning or the end of the set.
friend class Set< Key >
For efficiency, Set should be able to modify the hash table iterator.
Set(Size capacity=HashTableConst::default_size, bool resize_policy=true)
Default constructor.
bool isSupersetOrEqual(const Set< Key > &s) const
SetIterator< Key > const_iterator
Types for STL compliance.
SetIteratorSafe< Key > const_iterator_safe
Types for STL compliance.
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.
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
static const const_iterator_safe & cendSafe() noexcept
The usual safe end iterator to parse the set.
static const iterator & end() noexcept
The usual unsafe end 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.
bool isSubsetOrEqual(const Set< Key > &s) const
const_iterator cbegin() const
The usual unsafe begin iterator to parse the set.
Set< Key > operator+(const Set< Key > &s2) const
Union operator.
void setResizePolicy(const bool new_policy)
void resize(Size new_capacity)
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
void clear()
Removes all the elements, if any, from the set.
bool resizePolicy() const
Returns the current resizing policy of the underlying hash table.
Set< Key > & operator<<(const Key &k)
Adds a new element to the set (alias for insert).
bool empty() const noexcept
Indicates whether the set is the empty set.
Size capacity() const
Returns the capacity of the underlying hash table containing the set.
bool isStrictSupersetOf(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.
SetIterator< Key > iterator
Types for STL compliance.
const_iterator_safe cbeginSafe() const
The usual safe begin iterator to parse the set.
SetIteratorSafe< Key > iterator_safe
Types for STL compliance.
iterator begin() const
The usual unsafe begin iterator to parse the set.
void emplace(Args &&... args)
Emplace a new element in the set.
void insert(const Key &k)
Inserts a new element into the set.
const Set< Key > & operator+=(const Set< Key > &s2)
Union update operator.
bool isStrictSubsetOf(const Set< Key > &s) const
iterator_safe beginSafe() const
The usual safe begin iterator to parse the set.
HashTable< Key, NewKey > hashMap(NewKey(*f)(const Key &), Size capacity=0) const
Creates a hashtable of NewKey from the set.
Set< Key > & operator>>(const Key &k)
Removes an element from the set (alias for erase).
bool operator==(const Set< Key > &s2) const
Mathematical equality between two sets.
friend class SetIterator< Key >
void erase(const Key &k)
Erases an element from the set.
Size size() const noexcept
Returns the number of elements in the set.
static const iterator_safe & endSafe() noexcept
The usual safe end iterator to parse the set.
std::string toString() const
Prints the content of the set.
static const const_iterator & cend() noexcept
The usual unsafe end iterator to parse the set.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
bool contains(std::string_view s, std::string_view needle)
true if needle in s
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
static constexpr Size gold