31 #include <initializer_list> 36 #include <agrum/tools/core/debug.h> 37 #include <agrum/tools/core/hashTable.h> 38 #include <agrum/tools/core/list.h> 42 #ifndef DOXYGEN_SHOULD_SKIP_THIS 44 template <
typename Key >
45 class SetIteratorSafe;
46 template <
typename Key >
48 template <
typename Key,
typename Alloc >
51 template <
typename Key >
52 using SetConstIterator = SetIterator< Key >;
53 template <
typename Key >
54 using SetConstIteratorSafe = SetIteratorSafe< Key >;
68 class SetIteratorStaticEnd {
74 static const SetIteratorSafe<
int >* _SetIterEndSafe_;
80 static const SetIterator<
int >* _SetIterEnd_;
86 static const SetIteratorSafe<
int >* endSafe4Statics();
92 static const SetIteratorSafe<
int >* constEndSafe4Statics();
98 static const SetIterator<
int >* end4Statics();
104 static const SetIterator<
int >* constEnd4Statics();
107 template <
typename Key,
typename Alloc >
163 template <
typename Key,
typename Alloc = std::allocator< Key > >
168 using value_type = Key;
169 using reference = Key&;
170 using const_reference =
const Key&;
171 using pointer = Key*;
172 using const_pointer =
const Key*;
173 using size_type = std::size_t;
174 using difference_type = std::ptrdiff_t;
175 using allocator_type = Alloc;
176 using iterator = SetIterator< Key >;
177 using const_iterator = SetIterator< Key >;
178 using iterator_safe = SetIteratorSafe< Key >;
179 using const_iterator_safe = SetIteratorSafe< Key >;
199 explicit Set(Size capacity = HashTableConst::default_size,
bool resize_policy =
true);
205 Set(std::initializer_list< Key > list);
211 Set(
const Set< Key, Alloc >& aHT);
218 template <
typename OtherAlloc >
219 Set(
const Set< Key, OtherAlloc >& aHT);
225 Set(Set< Key, Alloc >&& aHT);
243 Set< Key, Alloc >& operator=(
const Set< Key, Alloc >& from);
251 template <
typename OtherAlloc >
252 Set< Key, Alloc >& operator=(
const Set< Key, OtherAlloc >& from);
259 Set< Key, Alloc >& operator=(Set< Key, Alloc >&& from);
267 template <
typename OtherAlloc >
268 bool operator==(
const Set< Key, OtherAlloc >& s2)
const;
276 template <
typename OtherAlloc >
277 bool operator!=(
const Set< Key, OtherAlloc >& s2)
const;
286 template <
typename OtherAlloc >
287 const Set< Key, Alloc >& operator*=(
const Set< Key, OtherAlloc >& s2);
296 template <
typename OtherAlloc >
297 Set< Key, Alloc > operator*(
const Set< Key, OtherAlloc >& s2)
const;
306 template <
typename OtherAlloc >
307 const Set< Key, Alloc >& operator+=(
const Set< Key, OtherAlloc >& s2);
316 template <
typename OtherAlloc >
317 Set< Key, Alloc > operator+(
const Set< Key, OtherAlloc >& s2)
const;
327 template <
typename OtherAlloc >
328 Set< Key, Alloc > operator-(
const Set< Key, OtherAlloc >& s2)
const;
335 Set< Key, Alloc >& operator<<(
const Key& k);
342 Set< Key, Alloc >& operator<<(Key&& k);
349 Set< Key, Alloc >& operator>>(
const Key& k);
363 void insert(
const Key& k);
371 void insert(Key&& k);
383 template <
typename... Args >
384 void emplace(Args&&... args);
393 void erase(
const Key& k);
401 void erase(
const iterator_safe& k);
412 Size size()
const noexcept;
418 bool contains(
const Key& k)
const;
423 template <
typename OtherAlloc >
424 bool isProperSubsetOf(
const Set< Key, OtherAlloc >& s)
const;
429 template <
typename OtherAlloc >
430 bool isProperSupersetOf(
const Set< Key, OtherAlloc >& s)
const;
435 template <
typename OtherAlloc >
436 bool isSubsetOrEqual(
const Set< Key, OtherAlloc >& s)
const;
441 template <
typename OtherAlloc >
442 bool isSupersetOrEqual(
const Set< Key, OtherAlloc >& s)
const;
448 bool exists(
const Key& k)
const;
454 bool empty()
const noexcept;
460 std::string toString()
const;
472 iterator_safe beginSafe()
const;
478 const_iterator_safe cbeginSafe()
const;
484 const iterator_safe& endSafe()
const noexcept;
490 const const_iterator_safe& cendSafe()
const noexcept;
496 iterator begin()
const;
502 const_iterator cbegin()
const;
508 const iterator& end()
const noexcept;
514 const const_iterator& cend()
const noexcept;
551 static const iterator& end4Statics();
588 static const const_iterator& constEnd4Statics();
625 static const iterator_safe& endSafe4Statics();
662 static const const_iterator_safe& constEndSafe4Statics();
679 Size capacity()
const;
688 void resize(Size new_capacity);
700 void setResizePolicy(
const bool new_policy);
707 bool resizePolicy()
const;
727 template <
typename NewKey,
728 typename NewAlloc =
typename Alloc::
template rebind< NewKey >::other >
729 HashTable< Key, NewKey, NewAlloc > hashMap(NewKey (*f)(
const Key&), Size capacity = 0)
const;
744 template <
typename NewKey,
745 typename NewAlloc =
typename Alloc::
template rebind< NewKey >::other >
746 HashTable< Key, NewKey, NewAlloc > hashMap(
const NewKey& val, Size size = 0)
const;
756 template <
typename NewKey,
757 typename NewAlloc =
typename Alloc::
template rebind< NewKey >::other >
758 List< NewKey, NewAlloc > listMap(NewKey (*f)(
const Key&))
const;
765 friend class SetIterator< Key >;
766 friend class SetIteratorSafe< Key >;
767 template <
typename K,
typename A >
772 HashTable< Key,
bool, Alloc > _inside_;
775 Set(
const HashTable< Key,
bool, Alloc >& h);
815 template <
typename Key >
816 class SetIteratorSafe {
820 using iterator_category = std::forward_iterator_tag;
821 using value_type = Key;
822 using reference = value_type&;
823 using const_reference =
const value_type&;
824 using pointer = value_type*;
825 using const_pointer =
const value_type*;
826 using difference_type = std::ptrdiff_t;
859 template <
typename Alloc >
860 SetIteratorSafe(
const Set< Key, Alloc >& from, Position pos = BEGIN);
866 SetIteratorSafe(
const SetIteratorSafe< Key >& from);
872 explicit SetIteratorSafe(
const SetIterator< Key >& from);
878 SetIteratorSafe(SetIteratorSafe< Key >&& from);
883 ~SetIteratorSafe()
noexcept;
896 SetIteratorSafe< Key >& operator=(
const SetIteratorSafe< Key >& from);
903 SetIteratorSafe< Key >& operator=(
const SetIterator< Key >& from);
910 SetIteratorSafe< Key >& operator=(SetIteratorSafe< Key >&& from)
noexcept;
916 SetIteratorSafe< Key >& operator++()
noexcept;
923 SetIteratorSafe< Key >& operator+=(Size i)
noexcept;
930 SetIteratorSafe< Key > operator+(Size i)
const;
938 bool operator!=(
const SetIteratorSafe< Key >& from)
const noexcept;
946 bool operator==(
const SetIteratorSafe< Key >& from)
const noexcept;
957 const Key& operator*()
const;
968 const Key* operator->()
const;
980 void clear()
noexcept;
986 template <
typename K,
typename A >
990 HashTableConstIteratorSafe< Key,
bool > _ht_iter_;
1033 template <
typename Key >
1038 using iterator_category = std::forward_iterator_tag;
1039 using value_type = Key;
1040 using reference = value_type&;
1041 using const_reference =
const value_type&;
1042 using pointer = value_type*;
1043 using const_pointer =
const value_type*;
1044 using difference_type = std::ptrdiff_t;
1065 SetIterator()
noexcept;
1077 template <
typename Alloc >
1078 SetIterator(
const Set< Key, Alloc >& from, Position pos = BEGIN);
1084 SetIterator(
const SetIterator< Key >& from)
noexcept;
1090 SetIterator(SetIterator< Key >&& from)
noexcept;
1095 ~SetIterator()
noexcept;
1108 SetIterator< Key >& operator=(
const SetIterator< Key >& from)
noexcept;
1115 SetIterator< Key >& operator=(SetIterator< Key >&& from)
noexcept;
1121 SetIterator< Key >& operator++()
noexcept;
1128 SetIterator< Key >& operator+=(Size i)
noexcept;
1135 SetIterator< Key > operator+(Size i)
const noexcept;
1143 bool operator!=(
const SetIterator< Key >& from)
const noexcept;
1151 bool operator==(
const SetIterator< Key >& from)
const noexcept;
1162 const Key& operator*()
const;
1173 const Key* operator->()
const;
1185 void clear()
noexcept;
1191 template <
typename K,
typename A >
1193 friend class SetIteratorSafe< Key >;
1196 HashTableConstIterator< Key,
bool > _ht_iter_;
1201 template <
typename Key,
typename Alloc >
1202 std::ostream& operator<<(std::ostream&,
const Set< Key, Alloc >&);
1206 template <
typename T,
typename Alloc >
1207 class HashFunc< Set< T, Alloc > >:
public HashFuncBase< Set< T, Alloc > > {
1214 static Size castToSize(
const Set< T, Alloc >& key);
1217 virtual Size operator()(
const Set< T, Alloc >& key)
const override final;
1223 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1224 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1225 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1226 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1227 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1228 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1229 extern template class gum::Set<
int >;
1236 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1237 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1238 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1239 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1240 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1241 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1242 extern template class gum::Set<
long >;
1249 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1250 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1251 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1252 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1253 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1254 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1255 extern template class gum::Set<
unsigned int >;
1262 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1263 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1264 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1265 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1266 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1267 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1268 extern template class gum::Set<
unsigned long >;
1276 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1277 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1278 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1279 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1280 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1281 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1282 extern template class gum::Set<
double >;
1289 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1290 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1291 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1292 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1293 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1294 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1295 extern template class gum::Set< std::string >;
1305 #include <agrum/tools/core/set_tpl.h>