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,
200 bool resize_policy =
true);
206 Set(std::initializer_list< Key > list);
212 Set(
const Set< Key, Alloc >& aHT);
219 template <
typename OtherAlloc >
220 Set(
const Set< Key, OtherAlloc >& aHT);
226 Set(Set< Key, Alloc >&& aHT);
244 Set< Key, Alloc >& operator=(
const Set< Key, Alloc >& from);
252 template <
typename OtherAlloc >
253 Set< Key, Alloc >& operator=(
const Set< Key, OtherAlloc >& from);
260 Set< Key, Alloc >& operator=(Set< Key, Alloc >&& from);
268 template <
typename OtherAlloc >
269 bool operator==(
const Set< Key, OtherAlloc >& s2)
const;
277 template <
typename OtherAlloc >
278 bool operator!=(
const Set< Key, OtherAlloc >& s2)
const;
287 template <
typename OtherAlloc >
288 const Set< Key, Alloc >& operator*=(
const Set< Key, OtherAlloc >& s2);
297 template <
typename OtherAlloc >
298 Set< Key, Alloc > operator*(
const Set< Key, OtherAlloc >& s2)
const;
307 template <
typename OtherAlloc >
308 const Set< Key, Alloc >& operator+=(
const Set< Key, OtherAlloc >& s2);
317 template <
typename OtherAlloc >
318 Set< Key, Alloc > operator+(
const Set< Key, OtherAlloc >& s2)
const;
328 template <
typename OtherAlloc >
329 Set< Key, Alloc > operator-(
const Set< Key, OtherAlloc >& s2)
const;
336 Set< Key, Alloc >& operator<<(
const Key& k);
343 Set< Key, Alloc >& operator<<(Key&& k);
350 Set< Key, Alloc >& operator>>(
const Key& k);
364 void insert(
const Key& k);
372 void insert(Key&& k);
384 template <
typename... Args >
385 void emplace(Args&&... args);
394 void erase(
const Key& k);
402 void erase(
const iterator_safe& k);
413 Size size()
const noexcept;
419 bool contains(
const Key& k)
const;
424 template <
typename OtherAlloc >
425 bool isProperSubsetOf(
const Set< Key, OtherAlloc >& s)
const;
430 template <
typename OtherAlloc >
431 bool isProperSupersetOf(
const Set< Key, OtherAlloc >& s)
const;
436 template <
typename OtherAlloc >
437 bool isSubsetOrEqual(
const Set< Key, OtherAlloc >& s)
const;
442 template <
typename OtherAlloc >
443 bool isSupersetOrEqual(
const Set< Key, OtherAlloc >& s)
const;
449 bool exists(
const Key& k)
const;
455 bool empty()
const noexcept;
461 std::string toString()
const;
473 iterator_safe beginSafe()
const;
479 const_iterator_safe cbeginSafe()
const;
485 const iterator_safe& endSafe()
const noexcept;
491 const const_iterator_safe& cendSafe()
const noexcept;
497 iterator begin()
const;
503 const_iterator cbegin()
const;
509 const iterator& end()
const noexcept;
515 const const_iterator& cend()
const noexcept;
552 static const iterator& end4Statics();
589 static const const_iterator& constEnd4Statics();
626 static const iterator_safe& endSafe4Statics();
663 static const const_iterator_safe& constEndSafe4Statics();
680 Size capacity()
const;
689 void resize(Size new_capacity);
701 void setResizePolicy(
const bool new_policy);
708 bool resizePolicy()
const;
728 template <
typename NewKey,
730 =
typename Alloc::
template rebind< NewKey >::other >
731 HashTable< Key, NewKey, NewAlloc > hashMap(NewKey (*f)(
const Key&),
732 Size capacity = 0)
const;
747 template <
typename NewKey,
749 =
typename Alloc::
template rebind< NewKey >::other >
750 HashTable< Key, NewKey, NewAlloc > hashMap(
const NewKey& val,
751 Size size = 0)
const;
761 template <
typename NewKey,
763 =
typename Alloc::
template rebind< NewKey >::other >
764 List< NewKey, NewAlloc > listMap(NewKey (*f)(
const Key&))
const;
771 friend class SetIterator< Key >;
772 friend class SetIteratorSafe< Key >;
773 template <
typename K,
typename A >
778 HashTable< Key,
bool, Alloc > inside__;
781 Set(
const HashTable< Key,
bool, Alloc >& h);
821 template <
typename Key >
822 class SetIteratorSafe {
826 using iterator_category = std::forward_iterator_tag;
827 using value_type = Key;
828 using reference = value_type&;
829 using const_reference =
const value_type&;
830 using pointer = value_type*;
831 using const_pointer =
const value_type*;
832 using difference_type = std::ptrdiff_t;
865 template <
typename Alloc >
866 SetIteratorSafe(
const Set< Key, Alloc >& from, Position pos = BEGIN);
872 SetIteratorSafe(
const SetIteratorSafe< Key >& from);
878 explicit SetIteratorSafe(
const SetIterator< Key >& from);
884 SetIteratorSafe(SetIteratorSafe< Key >&& from);
889 ~SetIteratorSafe()
noexcept;
902 SetIteratorSafe< Key >& operator=(
const SetIteratorSafe< Key >& from);
909 SetIteratorSafe< Key >& operator=(
const SetIterator< Key >& from);
916 SetIteratorSafe< Key >& operator=(SetIteratorSafe< Key >&& from)
noexcept;
922 SetIteratorSafe< Key >& operator++()
noexcept;
929 SetIteratorSafe< Key >& operator+=(Size i)
noexcept;
936 SetIteratorSafe< Key > operator+(Size i)
const;
944 bool operator!=(
const SetIteratorSafe< Key >& from)
const noexcept;
952 bool operator==(
const SetIteratorSafe< Key >& from)
const noexcept;
963 const Key& operator*()
const;
974 const Key* operator->()
const;
986 void clear()
noexcept;
992 template <
typename K,
typename A >
996 HashTableConstIteratorSafe< Key,
bool > ht_iter__;
1039 template <
typename Key >
1044 using iterator_category = std::forward_iterator_tag;
1045 using value_type = Key;
1046 using reference = value_type&;
1047 using const_reference =
const value_type&;
1048 using pointer = value_type*;
1049 using const_pointer =
const value_type*;
1050 using difference_type = std::ptrdiff_t;
1071 SetIterator()
noexcept;
1083 template <
typename Alloc >
1084 SetIterator(
const Set< Key, Alloc >& from, Position pos = BEGIN);
1090 SetIterator(
const SetIterator< Key >& from)
noexcept;
1096 SetIterator(SetIterator< Key >&& from)
noexcept;
1101 ~SetIterator()
noexcept;
1114 SetIterator< Key >& operator=(
const SetIterator< Key >& from)
noexcept;
1121 SetIterator< Key >& operator=(SetIterator< Key >&& from)
noexcept;
1127 SetIterator< Key >& operator++()
noexcept;
1134 SetIterator< Key >& operator+=(Size i)
noexcept;
1141 SetIterator< Key > operator+(Size i)
const noexcept;
1149 bool operator!=(
const SetIterator< Key >& from)
const noexcept;
1157 bool operator==(
const SetIterator< Key >& from)
const noexcept;
1168 const Key& operator*()
const;
1179 const Key* operator->()
const;
1191 void clear()
noexcept;
1197 template <
typename K,
typename A >
1199 friend class SetIteratorSafe< Key >;
1202 HashTableConstIterator< Key,
bool > ht_iter__;
1207 template <
typename Key,
typename Alloc >
1208 std::ostream& operator<<(std::ostream&,
const Set< Key, Alloc >&);
1212 template <
typename T,
typename Alloc >
1213 class HashFunc< Set< T, Alloc > >:
public HashFuncBase< Set< T, Alloc > > {
1220 static Size castToSize(
const Set< T, Alloc >& key);
1223 virtual Size operator()(
const Set< T, Alloc >& key)
const override final;
1229 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1230 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1231 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1232 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1233 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1234 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1235 extern template class gum::Set<
int >;
1242 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1243 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1244 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1245 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1246 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1247 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1248 extern template class gum::Set<
long >;
1255 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1256 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1257 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1258 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1259 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1260 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1261 extern template class gum::Set<
unsigned int >;
1268 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1269 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1270 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1271 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1272 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1273 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1274 extern template class gum::Set<
unsigned long >;
1282 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1283 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1284 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1285 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1286 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1287 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1288 extern template class gum::Set<
double >;
1295 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1296 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1297 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1298 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1299 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1300 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 1301 extern template class gum::Set< std::string >;
1311 #include <agrum/tools/core/set_tpl.h>