aGrUM  0.14.1
gum::Set< Key, Alloc > Class Template Reference

Representation of a setA Set is a structure that contains arbitrary elements. More...

#include <agrum/core/set.h>

+ Collaboration diagram for gum::Set< Key, Alloc >:

Public Member Functions

template<typename OtherAlloc >
INLINE Set (const Set< Key, OtherAlloc > &s)
 
template<typename OtherAlloc >
INLINE bool operator!= (const Set< Key, OtherAlloc > &s2) const
 
template<typename OtherAlloc >
INLINE bool isSubsetOf (const Set< Key, OtherAlloc > &s) const
 
template<typename OtherAlloc >
INLINE bool isSupersetOf (const Set< Key, OtherAlloc > &s) const
 
template<typename... Args>
INLINE void emplace (Args &&... args)
 
Constructors / Destructors
 Set (Size capacity=HashTableConst::default_size, bool resize_policy=true)
 Default constructor. More...
 
 Set (std::initializer_list< Key > list)
 Initializer list constructor. More...
 
 Set (const Set< Key, Alloc > &aHT)
 Copy constructor. More...
 
template<typename OtherAlloc >
 Set (const Set< Key, OtherAlloc > &aHT)
 Generalized copy constructor. More...
 
 Set (Set< Key, Alloc > &&aHT)
 Move constructor. More...
 
 ~Set ()
 Class destructor. More...
 
Operators
Set< Key, Alloc > & operator= (const Set< Key, Alloc > &from)
 Copy operator. More...
 
template<typename OtherAlloc >
Set< Key, Alloc > & operator= (const Set< Key, OtherAlloc > &from)
 Generalized copy operator. More...
 
Set< Key, Alloc > & operator= (Set< Key, Alloc > &&from)
 Move operator. More...
 
template<typename OtherAlloc >
bool operator== (const Set< Key, OtherAlloc > &s2) const
 Mathematical equality between two sets. More...
 
template<typename OtherAlloc >
bool operator!= (const Set< Key, OtherAlloc > &s2) const
 Mathematical inequality between two sets. More...
 
template<typename OtherAlloc >
const Set< Key, Alloc > & operator*= (const Set< Key, OtherAlloc > &s2)
 Intersection update operator. More...
 
template<typename OtherAlloc >
Set< Key, Alloc > operator* (const Set< Key, OtherAlloc > &s2) const
 Intersection operator. More...
 
template<typename OtherAlloc >
const Set< Key, Alloc > & operator+= (const Set< Key, OtherAlloc > &s2)
 Union update operator. More...
 
template<typename OtherAlloc >
Set< Key, Alloc > operator+ (const Set< Key, OtherAlloc > &s2) const
 Union operator. More...
 
template<typename OtherAlloc >
Set< Key, Alloc > operator- (const Set< Key, OtherAlloc > &s2) const
 Disjunction operator. More...
 
Set< Key, Alloc > & operator<< (const Key &k)
 Adds a new element to the set (alias for insert). More...
 
Set< Key, Alloc > & operator<< (Key &&k)
 Adds a new element to the set (alias for insert). More...
 
Set< Key, Alloc > & operator>> (const Key &k)
 Removes an element from the set (alias for erase). More...
 
Accessors / Modifiers
void insert (const Key &k)
 Inserts a new element into the set. More...
 
void insert (Key &&k)
 Inserts a new element into the set. More...
 
template<typename... Args>
void emplace (Args &&... args)
 Emplace a new element in the set. More...
 
void erase (const Key &k)
 Erases an element from the set. More...
 
void erase (const iterator_safe &k)
 Erases an element from the set. More...
 
void clear ()
 Removes all the elements, if any, from the set. More...
 
Size size () const noexcept
 Returns the number of elements in the set. More...
 
bool contains (const Key &k) const
 Indicates whether a given elements belong to the set. More...
 
template<typename OtherAlloc >
bool isSubsetOf (const Set< Key, OtherAlloc > &s) const
 
template<typename OtherAlloc >
bool isSupersetOf (const Set< Key, OtherAlloc > &s) const
 
bool exists (const Key &k) const
 Indicates whether a given elements belong to the set. More...
 
bool empty () const noexcept
 Indicates whether the set is the empty set. More...
 
std::string toString () const
 Prints the content of the set. More...
 
Fine tuning
Size capacity () const
 Returns the capacity of the underlying hash table containing the set. More...
 
void resize (Size new_capacity)
 Changes the size of the underlying hash table containing the set. More...
 
void setResizePolicy (const bool new_policy)
 Enables the user to change dynamically the resizing policy of the underlying hash table. More...
 
bool resizePolicy () const
 Returns the current resizing policy of the underlying hash table. More...
 
Mapper
template<typename NewKey , typename NewAlloc = typename Alloc::template rebind< NewKey >::other>
HashTable< Key, NewKey, NewAlloc > hashMap (NewKey(*f)(const Key &), Size capacity=0) const
 Creates a hashtable of NewKey from the set. More...
 
template<typename NewKey , typename NewAlloc = typename Alloc::template rebind< NewKey >::other>
HashTable< Key, NewKey, NewAlloc > hashMap (const NewKey &val, Size size=0) const
 Creates a hash table of NewKey from the set. More...
 
template<typename NewKey , typename NewAlloc = typename Alloc::template rebind< NewKey >::other>
List< NewKey, NewAlloc > listMap (NewKey(*f)(const Key &)) const
 A method to create a List of NewKey from the set. More...
 

Public Types

using value_type = Key
 Types for STL compliance. More...
 
using reference = Key &
 Types for STL compliance. More...
 
using const_reference = const Key &
 Types for STL compliance. More...
 
using pointer = Key *
 Types for STL compliance. More...
 
using const_pointer = const Key *
 Types for STL compliance. More...
 
using size_type = std::size_t
 Types for STL compliance. More...
 
using difference_type = std::ptrdiff_t
 Types for STL compliance. More...
 
using allocator_type = Alloc
 Types for STL compliance. More...
 
using iterator = SetIterator< Key >
 Types for STL compliance. More...
 
using const_iterator = SetIterator< Key >
 Types for STL compliance. More...
 
using iterator_safe = SetIteratorSafe< Key >
 Types for STL compliance. More...
 
using const_iterator_safe = SetIteratorSafe< Key >
 Types for STL compliance. More...
 

Friends

class SetIterator< Key >
 Friends to speed up access. More...
 
class SetIteratorSafe< Key >
 Friends to speed up access. More...
 
template<typename K , typename A >
class Set
 Friends to speed up access. More...
 

Iterators

iterator_safe beginSafe () const
 The usual safe begin iterator to parse the set. More...
 
const_iterator_safe cbeginSafe () const
 The usual safe begin iterator to parse the set. More...
 
const iterator_safeendSafe () const noexcept
 The usual safe end iterator to parse the set. More...
 
const const_iterator_safecendSafe () const noexcept
 The usual safe end iterator to parse the set. More...
 
iterator begin () const
 The usual unsafe begin iterator to parse the set. More...
 
const_iterator cbegin () const
 The usual unsafe begin iterator to parse the set. More...
 
const iteratorend () const noexcept
 The usual unsafe end iterator to parse the set. More...
 
const const_iteratorcend () const noexcept
 The usual unsafe end iterator to parse the set. More...
 
static const iteratorend4Statics ()
 Returns the end iterator for other classes' statics (read the detailed description of this method). More...
 
static const const_iteratorconstEnd4Statics ()
 Returns the end iterator for other classes' statics (read the detailed description of this method). More...
 
static const iterator_safeendSafe4Statics ()
 Returns the end iterator for other classes' statics (read the detailed description of this method). More...
 
static const const_iterator_safeconstEndSafe4Statics ()
 Returns the end iterator for other classes' statics (read the detailed description of this method). More...
 

Detailed Description

template<typename Key, typename Alloc = std::allocator< Key >>
class gum::Set< Key, Alloc >

Representation of a set

A Set is a structure that contains arbitrary elements.

Note that, as in mathematics, an element cannot appear twice in a given set. Sets have unsafe and safe iterators. The safe iterators (SetIteratorSafe<> a.k.a. Set<>::iterator_safe are slightly slower than the unsafe ones (SetIterator<> a.k.a. Set<>::iterator) but they guarantee that even if they point to a deleted element, using their operators ++ or * cannot produce a segfault. In such cases, they simply raise an exception. On the contrary, unsafe iterators should never be used on elements that can be deleted because, as in the STL, they will most probably produce a segfault.

Usage example:
// creation of a set with 10 elements
Set<int> set;
for (int i = 0; i< 10; ++i)
set<<i;
Set<int> set2 { 1, 2, 3 };
// parse the set
for (const auto iter = set.begin (); iter != set.end (); ++iter) {
// display the values
cerr << *iter << endl;
}
// use an iterator to point the element we wish to erase
Set<int>::iterator iter = set.begin ();
set.erase ( iter );
// check whether two iterators point toward the same element
Set<int>::iterator iter1 = set.begin();
Set<int>::iterator iter2 = set.end();
if (iter1 != iter2)
cerr << "iter1 and iter2 point toward different elements";
Template Parameters
KeyThe elements type.
AllocThe elements allocator.

Definition at line 162 of file set.h.

Member Typedef Documentation

◆ allocator_type

template<typename Key, typename Alloc = std::allocator< Key >>
using gum::Set< Key, Alloc >::allocator_type = Alloc

Types for STL compliance.

Definition at line 173 of file set.h.

◆ const_iterator

template<typename Key, typename Alloc = std::allocator< Key >>
using gum::Set< Key, Alloc >::const_iterator = SetIterator< Key >

Types for STL compliance.

Definition at line 175 of file set.h.

◆ const_iterator_safe

template<typename Key, typename Alloc = std::allocator< Key >>
using gum::Set< Key, Alloc >::const_iterator_safe = SetIteratorSafe< Key >

Types for STL compliance.

Definition at line 177 of file set.h.

◆ const_pointer

template<typename Key, typename Alloc = std::allocator< Key >>
using gum::Set< Key, Alloc >::const_pointer = const Key*

Types for STL compliance.

Definition at line 170 of file set.h.

◆ const_reference

template<typename Key, typename Alloc = std::allocator< Key >>
using gum::Set< Key, Alloc >::const_reference = const Key&

Types for STL compliance.

Definition at line 168 of file set.h.

◆ difference_type

template<typename Key, typename Alloc = std::allocator< Key >>
using gum::Set< Key, Alloc >::difference_type = std::ptrdiff_t

Types for STL compliance.

Definition at line 172 of file set.h.

◆ iterator

template<typename Key, typename Alloc = std::allocator< Key >>
using gum::Set< Key, Alloc >::iterator = SetIterator< Key >

Types for STL compliance.

Definition at line 174 of file set.h.

◆ iterator_safe

template<typename Key, typename Alloc = std::allocator< Key >>
using gum::Set< Key, Alloc >::iterator_safe = SetIteratorSafe< Key >

Types for STL compliance.

Definition at line 176 of file set.h.

◆ pointer

template<typename Key, typename Alloc = std::allocator< Key >>
using gum::Set< Key, Alloc >::pointer = Key*

Types for STL compliance.

Definition at line 169 of file set.h.

◆ reference

template<typename Key, typename Alloc = std::allocator< Key >>
using gum::Set< Key, Alloc >::reference = Key&

Types for STL compliance.

Definition at line 167 of file set.h.

◆ size_type

template<typename Key, typename Alloc = std::allocator< Key >>
using gum::Set< Key, Alloc >::size_type = std::size_t

Types for STL compliance.

Definition at line 171 of file set.h.

◆ value_type

template<typename Key, typename Alloc = std::allocator< Key >>
using gum::Set< Key, Alloc >::value_type = Key

Types for STL compliance.

Definition at line 166 of file set.h.

Constructor & Destructor Documentation

◆ Set() [1/7]

template<typename Key , typename Alloc >
INLINE gum::Set< Key, Alloc >::Set ( Size  capacity = HashTableConst::default_size,
bool  resize_policy = true 
)
explicit

Default constructor.

Sets rely on hashtables to store their items. The optional parameters of this constructor enable a fine memory management of these hashtables.

Parameters
capacityThe number of slots allocated to the hashtable (see the HashTable default constructor)
resize_policyEnables the hashtable to resize itself automatically when its number of elements is sufficiently high that it induces slow retrievals of elements.

Definition at line 316 of file set_tpl.h.

316  :
317  // create the hash table without key uniqueness policy (as we will
318  // check
319  // ourselves the uniqueness of Keys before inserting new elements)
320  __inside(capacity, resize_policy, false) {
321  GUM_CONSTRUCTOR(Set);
322 
323  // make sure the end() iterator is constructed properly
324  endSafe4Statics();
325  end4Statics();
326  }
Size capacity() const
Returns the capacity of the underlying hash table containing the set.
Definition: set_tpl.h:543
static const iterator & end4Statics()
Returns the end iterator for other classes&#39; statics (read the detailed description of this method)...
Definition: set_tpl.h:302
static const iterator_safe & endSafe4Statics()
Returns the end iterator for other classes&#39; statics (read the detailed description of this method)...
Definition: set_tpl.h:288
friend class Set
Friends to speed up access.
Definition: set.h:760
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764

◆ Set() [2/7]

template<typename Key, typename Alloc >
INLINE gum::Set< Key, Alloc >::Set ( std::initializer_list< Key >  list)

Initializer list constructor.

Parameters
listThe initializer list.

Definition at line 330 of file set_tpl.h.

330  :
331  __inside(Size(list.size()) / 2, true, false) {
332  GUM_CONSTRUCTOR(Set);
333  for (const auto& elt : list) {
334  insert(elt);
335  }
336 
337  // make sure the end() iterator is constructed properly
338  endSafe4Statics();
339  end4Statics();
340  }
static const iterator & end4Statics()
Returns the end iterator for other classes&#39; statics (read the detailed description of this method)...
Definition: set_tpl.h:302
static const iterator_safe & endSafe4Statics()
Returns the end iterator for other classes&#39; statics (read the detailed description of this method)...
Definition: set_tpl.h:288
friend class Set
Friends to speed up access.
Definition: set.h:760
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:610

◆ Set() [3/7]

template<typename Key, typename Alloc>
INLINE gum::Set< Key, Alloc >::Set ( const Set< Key, Alloc > &  aHT)

Copy constructor.

Parameters
aHTThe gum::Set to copy.

Definition at line 344 of file set_tpl.h.

344  :
345  __inside(s.__inside) {
346  GUM_CONS_CPY(Set);
347  }
friend class Set
Friends to speed up access.
Definition: set.h:760
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764

◆ Set() [4/7]

template<typename Key, typename Alloc = std::allocator< Key >>
template<typename OtherAlloc >
gum::Set< Key, Alloc >::Set ( const Set< Key, OtherAlloc > &  aHT)

Generalized copy constructor.

Parameters
aHTThe gum::Set to copy.
Template Parameters
OtherAllocThe other gum::Set allocator.

◆ Set() [5/7]

template<typename Key, typename Alloc>
INLINE gum::Set< Key, Alloc >::Set ( Set< Key, Alloc > &&  aHT)

Move constructor.

Parameters
aHTThe gum::Set to move.

Definition at line 359 of file set_tpl.h.

359  :
360  __inside(std::move(s.__inside)) {
361  GUM_CONS_MOV(Set);
362  }
friend class Set
Friends to speed up access.
Definition: set.h:760
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764

◆ ~Set()

template<typename Key, typename Alloc = std::allocator< Key >>
gum::Set< Key, Alloc >::~Set ( )

Class destructor.

◆ Set() [6/7]

template<typename Key, typename Alloc = std::allocator< Key >>
gum::Set< Key, Alloc >::Set ( const HashTable< Key, bool, Alloc > &  h)
private

Convert a hash table into a set of keys.

◆ Set() [7/7]

template<typename Key, typename Alloc = std::allocator< Key >>
template<typename OtherAlloc >
INLINE gum::Set< Key, Alloc >::Set ( const Set< Key, OtherAlloc > &  s)

Definition at line 352 of file set_tpl.h.

352  :
353  __inside(s.__inside) {
354  GUM_CONS_CPY(Set);
355  }
friend class Set
Friends to speed up access.
Definition: set.h:760
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764

Member Function Documentation

◆ begin()

template<typename Key , typename Alloc >
INLINE Set< Key, Alloc >::iterator gum::Set< Key, Alloc >::begin ( ) const

The usual unsafe begin iterator to parse the set.

Returns
Returns the usual unsafe begin iterator to parse the set.

Definition at line 514 of file set_tpl.h.

Referenced by gum::StaticTriangulation::__computeMaxPrimeMergings(), gum::StaticTriangulation::__triangulate(), gum::prm::StructuredInference< GUM_SCALAR >::_marginal(), gum::BarrenNodesFinder::barrenNodes(), and gum::prm::eliminateNode().

514  {
515  return SetIterator< Key >{*this};
516  }
friend class SetIterator< Key >
Friends to speed up access.
Definition: set.h:757
+ Here is the caller graph for this function:

◆ beginSafe()

template<typename Key , typename Alloc >
INLINE Set< Key, Alloc >::iterator_safe gum::Set< Key, Alloc >::beginSafe ( ) const

The usual safe begin iterator to parse the set.

Returns
Returns The usual safe begin iterator to parse the set.

Definition at line 485 of file set_tpl.h.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::__updateNodeSet(), gum::BayesNetFragment< GUM_SCALAR >::_installCPT(), gum::LeafAggregator::addLeaf(), gum::BarrenNodesFinder::barrenNodes(), gum::ArcGraphPart::eraseChildren(), gum::ArcGraphPart::eraseParents(), gum::LeafAggregator::removeLeaf(), gum::VariableSelector::select(), gum::ArcGraphPart::unvirtualizedEraseChildren(), gum::ArcGraphPart::unvirtualizedEraseParents(), gum::IMDDI< AttributeSelection, isScalar >::updateGraph(), and gum::LeafAggregator::updateLeaf().

485  {
486  return SetIteratorSafe< Key >{*this};
487  }
friend class SetIteratorSafe< Key >
Friends to speed up access.
Definition: set.h:758
+ Here is the caller graph for this function:

◆ capacity()

template<typename Key , typename Alloc >
INLINE Size gum::Set< Key, Alloc >::capacity ( ) const

Returns the capacity of the underlying hash table containing the set.

The method runs in constant time.

Returns
Returns the capacity of the underlying hash table containing the set.

Definition at line 543 of file set_tpl.h.

Referenced by gum::Set< gum::Potential< GUM_SCALAR > * >::capacity(), and gum::Set< gum::Potential< GUM_SCALAR > * >::operator=().

543  {
544  return __inside.capacity();
545  }
Size capacity() const noexcept
Returns the number of slots in the &#39;nodes&#39; vector of the hashtable.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
+ Here is the caller graph for this function:

◆ cbegin()

template<typename Key , typename Alloc >
INLINE Set< Key, Alloc >::const_iterator gum::Set< Key, Alloc >::cbegin ( ) const

The usual unsafe begin iterator to parse the set.

Returns
Returns the usual unsafe begin iterator to parse the set.

Definition at line 521 of file set_tpl.h.

Referenced by gum::DefaultPartialOrderedEliminationSequenceStrategy::nextNodeToEliminate().

521  {
522  return SetIterator< Key >{*this};
523  }
friend class SetIterator< Key >
Friends to speed up access.
Definition: set.h:757
+ Here is the caller graph for this function:

◆ cbeginSafe()

template<typename Key , typename Alloc >
INLINE Set< Key, Alloc >::const_iterator_safe gum::Set< Key, Alloc >::cbeginSafe ( ) const

The usual safe begin iterator to parse the set.

Returns
Returns the usual safe begin iterator to parse the set.

Definition at line 492 of file set_tpl.h.

Referenced by gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNode(), and gum::NodeDatabase< AttributeSelection, isScalar >::NodeDatabase().

492  {
493  return SetIteratorSafe< Key >{*this};
494  }
friend class SetIteratorSafe< Key >
Friends to speed up access.
Definition: set.h:758
+ Here is the caller graph for this function:

◆ cend()

template<typename Key , typename Alloc >
INLINE const Set< Key, Alloc >::const_iterator & gum::Set< Key, Alloc >::cend ( ) const
noexcept

The usual unsafe end iterator to parse the set.

Returns
Returns the usual unsafe end iterator to parse the set.

Definition at line 536 of file set_tpl.h.

Referenced by gum::DefaultPartialOrderedEliminationSequenceStrategy::nextNodeToEliminate().

536  {
537  return *(reinterpret_cast< const SetIterator< Key >* >(
538  SetIteratorStaticEnd::__SetIterEnd));
539  }
friend class SetIterator< Key >
Friends to speed up access.
Definition: set.h:757
+ Here is the caller graph for this function:

◆ cendSafe()

template<typename Key , typename Alloc >
INLINE const Set< Key, Alloc >::const_iterator_safe & gum::Set< Key, Alloc >::cendSafe ( ) const
noexcept

The usual safe end iterator to parse the set.

Returns
Returns the usual safe end iterator to parse the set.

Definition at line 507 of file set_tpl.h.

Referenced by gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNode(), and gum::NodeDatabase< AttributeSelection, isScalar >::NodeDatabase().

507  {
508  return *(reinterpret_cast< const SetIteratorSafe< Key >* >(
509  SetIteratorStaticEnd::__SetIterEndSafe));
510  }
friend class SetIteratorSafe< Key >
Friends to speed up access.
Definition: set.h:758
+ Here is the caller graph for this function:

◆ clear()

template<typename Key , typename Alloc >
INLINE void gum::Set< Key, Alloc >::clear ( )

Removes all the elements, if any, from the set.

Definition at line 372 of file set_tpl.h.

Referenced by gum::MarginalTargetedInference< GUM_SCALAR >::__setAllMarginalTargets(), gum::IMDDI< AttributeSelection, isScalar >::__updateNodeSet(), gum::MarginalTargetedInference< GUM_SCALAR >::_setTargetedMode(), gum::PartialOrderedEliminationSequenceStrategy::clear(), gum::StaticTriangulation::clear(), gum::Set< gum::Potential< GUM_SCALAR > * >::clear(), gum::ArcGraphPart::clearArcs(), gum::EdgeGraphPart::clearEdges(), gum::BayesNetInference< GUM_SCALAR >::eraseAllEvidence(), gum::MarginalTargetedInference< GUM_SCALAR >::eraseAllTargets(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::BayesBall::requisiteNodes(), gum::dSeparation::requisiteNodes(), gum::PartialOrderedEliminationSequenceStrategy::setPartialOrder(), gum::ITI< AttributeSelection, isScalar >::updateGraph(), and gum::LeafAggregator::updateLeaf().

372  {
373  // first we remove all the elements from the hashtable actually containing
374  // the elements of the set. Note that, doing so, all the hashtable iterators
375  // will be updated as well. In turn, this will imply that, whenever an
376  // operation will be performed on a SetIteratorSafe, this will raise an
377  // exception.
378  __inside.clear();
379 
380  // Note that actually there is no need to update the end iterator as this
381  // one
382  // is not affected by changes within hashtables (adding/deleting elements).
383  // Hence, for speedup, we do not update the end iterator
384  }
void clear()
Removes all the elements in the hash table.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
+ Here is the caller graph for this function:

◆ constEnd4Statics()

template<typename Key , typename Alloc >
INLINE const SetIterator< Key > & gum::Set< Key, Alloc >::constEnd4Statics ( )
static

Returns the end iterator for other classes' statics (read the detailed description of this method).

To reduce the Sets memory consumption (which are heavily used in aGrUM) while allowing fast for(iter=begin(); iter!=end();++iter) loops, end iterators are created just once as a static member of a non-template Set. While this scheme is efficient and it works quite effectively when manipulating sets, it has a drawback: other classes with static members using the Set's end() iterator may fail to work due to the well known "static initialization order fiasco" (see Marshall Cline's C++ FAQ for more details about this C++ feature). OK, so what is the problem? Consider a class, say X, containing a Set that stores all its elements in a convenient way. To reduce memory consumption, X::end iterator is a static member that is initialized with a Set::end iterator. If the compiler decides to initialize X::end before initializing Set::end, then X::end will be in an incoherent state. Unfortunately, we cannot know for sure in which order static members will be initialized (the order is a compiler's decision). Hence, we shall enfore the fact that Set::end is initialized before X::end. Using method Set::end4Statics will ensure this fact: it uses the C++ "construct on first use" idiom (see the C++ FAQ) that ensures that the order fiasco is avoided. More precisely, end4Statics uses a global variable that is the very end iterator used by all Sets. Now, this induces a small overhead. So, we also provide a Set::end() method that returns the Set::end iterator without this small overhead, but assuming that function end4Statics has already been called once (which is always the case) when a Set has been created.

So, to summarize: when initializing static members, use constEnd4Statics() rather than cend(). In all the other cases, use simply the usual method cend().

Returns
Returns the end iterator for other classes' statics (read the detailed description of this method).

Definition at line 309 of file set_tpl.h.

309  {
310  return *(reinterpret_cast< const SetIterator< Key >* >(
311  SetIteratorStaticEnd::constEnd4Statics()));
312  }
friend class SetIterator< Key >
Friends to speed up access.
Definition: set.h:757

◆ constEndSafe4Statics()

template<typename Key , typename Alloc >
INLINE const SetIteratorSafe< Key > & gum::Set< Key, Alloc >::constEndSafe4Statics ( )
static

Returns the end iterator for other classes' statics (read the detailed description of this method).

To reduce the Sets memory consumption (which are heavily used in aGrUM) while allowing fast for(iter=begin(); iter!=end();++iter) loops, end iterators are created just once as a static member of a non-template Set. While this scheme is efficient and it works quite effectively when manipulating sets, it has a drawback: other classes with static members using the Set's end() iterator may fail to work due to the well known "static initialization order fiasco" (see Marshall Cline's C++ FAQ for more details about this C++ feature). OK, so what is the problem? Consider a class, say X, containing a Set that stores all its elements in a convenient way. To reduce memory consumption, X::end iterator is a static member that is initialized with a Set::end iterator. If the compiler decides to initialize X::end before initializing Set::end, then X::end will be in an incoherent state. Unfortunately, we cannot know for sure in which order static members will be initialized (the order is a compiler's decision). Hence, we shall enfore the fact that Set::end is initialized before X::end. Using method Set::end4Statics will ensure this fact: it uses the C++ "construct on first use" idiom (see the C++ FAQ) that ensures that the order fiasco is avoided. More precisely, end4Statics uses a global variable that is the very end iterator used by all Sets. Now, this induces a small overhead. So, we also provide a Set::end() method that returns the Set::end iterator without this small overhead, but assuming that function end4Statics has already been called once (which is always the case) when a Set has been created.

So, to summarize: when initializing static members, use constEndSafe4Statics() rather than cendSafe(). In all the other cases, use simply the usual method cendSafe ().

Returns
Returns the end iterator for other classes' statics (read the detailed description of this method).

Definition at line 295 of file set_tpl.h.

295  {
296  return *(reinterpret_cast< const SetIteratorSafe< Key >* >(
297  SetIteratorStaticEnd::constEndSafe4Statics()));
298  }
friend class SetIteratorSafe< Key >
Friends to speed up access.
Definition: set.h:758

◆ contains()

template<typename Key, typename Alloc >
INLINE bool gum::Set< Key, Alloc >::contains ( const Key &  k) const

Indicates whether a given elements belong to the set.

Returns
Returns true if a given elements belong to the set.

Definition at line 578 of file set_tpl.h.

Referenced by gum::NodeGraphPart::__addHole(), gum::StaticTriangulation::__computeMaxPrimeJunctionTree(), gum::DAG::__hasDirectedPath(), gum::prm::SVED< GUM_SCALAR >::__initElimOrder(), gum::prm::SVE< GUM_SCALAR >::__initElimOrder(), gum::IBayesNet< double >::__minimalCondSetVisitDn(), gum::IBayesNet< double >::__minimalCondSetVisitUp(), gum::Potential< GUM_SCALAR >::_complementVars(), gum::MarginalTargetedInference< GUM_SCALAR >::addAllTargets(), gum::MarginalTargetedInference< GUM_SCALAR >::addTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::eraseTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::ArcGraphPart::existsArc(), gum::EdgeGraphPart::existsEdge(), gum::Potential< GUM_SCALAR >::fillWith(), gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder(), gum::BayesNetFragment< GUM_SCALAR >::installCPT(), gum::Set< gum::Potential< GUM_SCALAR > * >::isSubsetOf(), gum::MarginalTargetedInference< GUM_SCALAR >::isTarget(), gum::IBayesNet< double >::minimalCondSet(), gum::O3prmBNReader< GUM_SCALAR >::proceed(), gum::Estimator< GUM_SCALAR >::setFromBN(), and gum::Estimator< GUM_SCALAR >::setFromLBP().

578  {
579  return __inside.exists(k);
580  }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
+ Here is the caller graph for this function:

◆ emplace() [1/2]

template<typename Key, typename Alloc = std::allocator< Key >>
template<typename... Args>
void gum::Set< Key, Alloc >::emplace ( Args &&...  args)

Emplace a new element in the set.

Emplace is a method that allows to construct directly an element of type Key by passing to its constructor all the arguments it needs.

Parameters
argsthe arguments passed to the constructor
Warning
if the set already contains the element, nothing is done. In particular, it is not added to the set and no exception is thrown.

◆ emplace() [2/2]

template<typename Key, typename Alloc = std::allocator< Key >>
template<typename... Args>
INLINE void gum::Set< Key, Alloc >::emplace ( Args &&...  args)

Definition at line 647 of file set_tpl.h.

647  {
648  insert(std::move(Key(std::forward< Args >(args)...)));
649  }
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:610

◆ empty()

template<typename Key , typename Alloc >
INLINE bool gum::Set< Key, Alloc >::empty ( ) const
noexcept

Indicates whether the set is the empty set.

Returns
Returns true if the set is empty.

Definition at line 704 of file set_tpl.h.

Referenced by gum::NodeGraphPart::__addHole(), gum::prm::SVE< GUM_SCALAR >::__eliminateNodesDownward(), gum::VariableSelector::__removeVar(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::_msgL(), gum::learning::Miic::_orientation_miic(), gum::learning::Miic::_propagatesHead(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::_refreshLMsPIs(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNode(), gum::credal::CredalNet< GUM_SCALAR >::approximatedBinarization(), gum::DefaultPartialOrderedEliminationSequenceStrategy::eliminationUpdate(), gum::Set< gum::Potential< GUM_SCALAR > * >::empty(), gum::ArcGraphPart::emptyArcs(), gum::EdgeGraphPart::emptyEdges(), gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder(), gum::learning::Miic::learnStructure(), gum::DefaultPartialOrderedEliminationSequenceStrategy::nextNodeToEliminate(), gum::PartialOrderedEliminationSequenceStrategy::setPartialOrder(), and gum::prm::PRMFactory< GUM_SCALAR >::startClass().

704  {
705  return __inside.empty();
706  }
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
bool empty() const noexcept
Indicates whether the hash table is empty.
+ Here is the caller graph for this function:

◆ end()

template<typename Key , typename Alloc >
INLINE const Set< Key, Alloc >::iterator & gum::Set< Key, Alloc >::end ( ) const
noexcept

The usual unsafe end iterator to parse the set.

Returns
Returns the usual unsafe end iterator to parse the set.

Definition at line 527 of file set_tpl.h.

Referenced by gum::StaticTriangulation::__computeMaxPrimeMergings(), and gum::StaticTriangulation::__triangulate().

528  {
529  return *(reinterpret_cast< const SetIterator< Key >* >(
530  SetIteratorStaticEnd::__SetIterEnd));
531  }
friend class SetIterator< Key >
Friends to speed up access.
Definition: set.h:757
+ Here is the caller graph for this function:

◆ end4Statics()

template<typename Key , typename Alloc >
INLINE const SetIterator< Key > & gum::Set< Key, Alloc >::end4Statics ( )
static

Returns the end iterator for other classes' statics (read the detailed description of this method).

To reduce the Sets memory consumption (which are heavily used in aGrUM) while allowing fast for(iter=begin(); iter!=end();++iter) loops, end iterators are created just once as a static member of a non-template Set. While this scheme is efficient and it works quite effectively when manipulating sets, it has a drawback: other classes with static members using the Set's end() iterator may fail to work due to the well known "static initialization order fiasco" (see Marshall Cline's C++ FAQ for more details about this C++ feature). OK, so what is the problem? Consider a class, say X, containing a Set that stores all its elements in a convenient way. To reduce memory consumption, X::end iterator is a static member that is initialized with a Set::end iterator. If the compiler decides to initialize X::end before initializing Set::end, then X::end will be in an incoherent state. Unfortunately, we cannot know for sure in which order static members will be initialized (the order is a compiler's decision). Hence, we shall enfore the fact that Set::end is initialized before X::end. Using method Set::end4Statics will ensure this fact: it uses the C++ "construct on first use" idiom (see the C++ FAQ) that ensures that the order fiasco is avoided. More precisely, end4Statics uses a global variable that is the very end iterator used by all Sets. Now, this induces a small overhead. So, we also provide a Set::end() method that returns the Set::end iterator without this small overhead, but assuming that function end4Statics has already been called once (which is always the case) when a Set has been created.

So, to summarize: when initializing static members, use end4Statics() rather than end(). In all the other cases, use simply the usual method end().

Returns
Returns the end iterator for other classes' statics (read the detailed description of this method).

Definition at line 302 of file set_tpl.h.

302  {
303  return *(reinterpret_cast< const SetIterator< Key >* >(
304  SetIteratorStaticEnd::end4Statics()));
305  }
friend class SetIterator< Key >
Friends to speed up access.
Definition: set.h:757

◆ endSafe()

template<typename Key , typename Alloc >
INLINE const Set< Key, Alloc >::iterator_safe & gum::Set< Key, Alloc >::endSafe ( ) const
noexcept

The usual safe end iterator to parse the set.

Returns
Returns the usual safe end iterator to parse the set.

Definition at line 499 of file set_tpl.h.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::__updateNodeSet(), gum::BayesNetFragment< GUM_SCALAR >::_installCPT(), gum::LeafAggregator::addLeaf(), gum::BarrenNodesFinder::barrenNodes(), gum::ArcGraphPart::eraseChildren(), gum::ArcGraphPart::eraseParents(), gum::LeafAggregator::removeLeaf(), gum::VariableSelector::select(), gum::ArcGraphPart::unvirtualizedEraseChildren(), gum::ArcGraphPart::unvirtualizedEraseParents(), gum::IMDDI< AttributeSelection, isScalar >::updateGraph(), and gum::LeafAggregator::updateLeaf().

499  {
500  return *(reinterpret_cast< const SetIteratorSafe< Key >* >(
501  SetIteratorStaticEnd::__SetIterEndSafe));
502  }
friend class SetIteratorSafe< Key >
Friends to speed up access.
Definition: set.h:758
+ Here is the caller graph for this function:

◆ endSafe4Statics()

template<typename Key , typename Alloc >
INLINE const SetIteratorSafe< Key > & gum::Set< Key, Alloc >::endSafe4Statics ( )
static

Returns the end iterator for other classes' statics (read the detailed description of this method).

To reduce the Sets memory consumption (which are heavily used in aGrUM) while allowing fast for(iter=begin(); iter!=end();++iter) loops, end iterators are created just once as a static member of a non-template Set. While this scheme is efficient and it works quite effectively when manipulating sets, it has a drawback: other classes with static members using the Set's end() iterator may fail to work due to the well known "static initialization order fiasco" (see Marshall Cline's C++ FAQ for more details about this C++ feature). OK, so what is the problem? Consider a class, say X, containing a Set that stores all its elements in a convenient way. To reduce memory consumption, X::end iterator is a static member that is initialized with a Set::end iterator. If the compiler decides to initialize X::end before initializing Set::end, then X::end will be in an incoherent state. Unfortunately, we cannot know for sure in which order static members will be initialized (the order is a compiler's decision). Hence, we shall enfore the fact that Set::end is initialized before X::end. Using method Set::end4Statics will ensure this fact: it uses the C++ "construct on first use" idiom (see the C++ FAQ) that ensures that the order fiasco is avoided. More precisely, end4Statics uses a global variable that is the very end iterator used by all Sets. Now, this induces a small overhead. So, we also provide a Set::end() method that returns the Set::end iterator without this small overhead, but assuming that function end4Statics has already been called once (which is always the case) when a Set has been created.

So, to summarize: when initializing static members, use endSafe4Statics() rather than endSafe (). In all the other cases, use simply the usual method endSafe ().

Returns
Returns the end iterator for other classes' statics (read the detailed description of this method).

Definition at line 288 of file set_tpl.h.

288  {
289  return *(reinterpret_cast< const SetIteratorSafe< Key >* >(
290  SetIteratorStaticEnd::endSafe4Statics()));
291  }
friend class SetIteratorSafe< Key >
Friends to speed up access.
Definition: set.h:758

◆ erase() [1/2]

template<typename Key, typename Alloc >
INLINE void gum::Set< Key, Alloc >::erase ( const Key &  k)

Erases an element from the set.

Parameters
kThe element to remove.
Warning
if the set does not contain the element, nothing is done. In particular, no exception is thrown.

Definition at line 653 of file set_tpl.h.

Referenced by gum::NodeGraphPart::__addHole(), gum::prm::StructuredInference< GUM_SCALAR >::__buildPatternGraph(), gum::prm::StructuredInference< GUM_SCALAR >::__buildReduceGraph(), gum::StaticTriangulation::__computeRecursiveThinning(), gum::prm::SVED< GUM_SCALAR >::__initLiftedNodes(), gum::prm::SVE< GUM_SCALAR >::__initLiftedNodes(), gum::prm::StructuredInference< GUM_SCALAR >::__removeNode(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::_msgP(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::_refreshLMsPIs(), gum::BarrenNodesFinder::barrenNodes(), gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), gum::BayesNetInference< GUM_SCALAR >::chgEvidence(), gum::DefaultPartialOrderedEliminationSequenceStrategy::eliminationUpdate(), gum::Set< gum::Potential< GUM_SCALAR > * >::erase(), gum::ArcGraphPart::eraseArc(), gum::EdgeGraphPart::eraseEdge(), gum::BayesNetInference< GUM_SCALAR >::eraseEvidence(), gum::MarginalTargetedInference< GUM_SCALAR >::eraseTarget(), gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder(), and gum::ITI< AttributeSelection, isScalar >::updateGraph().

653  {
654  // erase the element (if it exists)
655  __inside.erase(k);
656 
657  // Note that actually there is no need to update the end iterator as this
658  // one
659  // is not affected by changes within hashtables (adding/deleting elements).
660  // Hence, for speedup, we do not update the end iterator
661  }
void erase(const Key &key)
Removes a given element from the hash table.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
+ Here is the caller graph for this function:

◆ erase() [2/2]

template<typename Key, typename Alloc >
INLINE void gum::Set< Key, Alloc >::erase ( const iterator_safe k)

Erases an element from the set.

Parameters
kThe iterator pointing to the element to remove.
Warning
if the set does not contain the element, nothing is done. In particular, no exception is thrown.

Definition at line 665 of file set_tpl.h.

665  {
666  // erase the element
667  __inside.erase(iter.__ht_iter);
668 
669  // Note that actually there is no need to update the end iterator as this
670  // one
671  // is not affected by changes within hashtables (adding/deleting elements).
672  // Hence, for speedup, we do not update the end iterator
673  }
void erase(const Key &key)
Removes a given element from the hash table.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764

◆ exists()

template<typename Key, typename Alloc >
INLINE bool gum::Set< Key, Alloc >::exists ( const Key &  k) const

Indicates whether a given elements belong to the set.

Returns
Returns true if a given elements belong to the set.

Definition at line 604 of file set_tpl.h.

Referenced by gum::prm::StructuredBayesBall< GUM_SCALAR >::__buildHashKey(), gum::prm::StructuredInference< GUM_SCALAR >::__buildPatternGraph(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__connect(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__directedPath(), gum::prm::SVED< GUM_SCALAR >::__eliminateNodes(), gum::prm::SVE< GUM_SCALAR >::__eliminateNodes(), gum::prm::SVE< GUM_SCALAR >::__eliminateNodesWithEvidence(), gum::prm::SVED< GUM_SCALAR >::__initLiftedNodes(), gum::prm::SVE< GUM_SCALAR >::__initLiftedNodes(), gum::prm::StructuredInference< GUM_SCALAR >::__insertNodeInElimLists(), gum::prm::StructuredInference< GUM_SCALAR >::__removeBarrenNodes(), gum::prm::StructuredInference< GUM_SCALAR >::__removeNode(), gum::DAGCycleDetector::__restrictWeightedSet(), gum::prm::SVE< GUM_SCALAR >::__variableElimination(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNode(), gum::BarrenNodesFinder::barrenNodes(), gum::Set< gum::Potential< GUM_SCALAR > * >::contains(), gum::Set< gum::Potential< GUM_SCALAR > * >::exists(), gum::BayesNetInference< GUM_SCALAR >::hasHardEvidence(), gum::MarkovBlanket::hasSameStructure(), gum::DAGmodel::hasSameStructure(), gum::BayesNetInference< GUM_SCALAR >::hasSoftEvidence(), gum::StructuredPlaner< double >::optimalPolicy2String(), gum::BayesBall::relevantPotentials(), gum::dSeparation::relevantPotentials(), gum::BayesBall::requisiteNodes(), gum::dSeparation::requisiteNodes(), and gum::MarkovBlanket::toDot().

604  {
605  return __inside.exists(k);
606  }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
+ Here is the caller graph for this function:

◆ hashMap() [1/2]

template<typename Key, typename Alloc >
template<typename NewKey , typename NewAlloc >
HashTable< Key, NewKey, NewAlloc > gum::Set< Key, Alloc >::hashMap ( NewKey(*)(const Key &)  f,
Size  capacity = 0 
) const

Creates a hashtable of NewKey from the set.

Warning
The order in the resulting hashtable may not be similar to that of the original set. Hence iterators on the former may not parse it in the same order as iterators on the latter.
Parameters
fA function that maps Key into a NewKey
capacityThe size of the resulting hashtable. When equal to 0, a default size is computed that is a good trade-off between space consumption and efficiency of new elements insertions.

Definition at line 835 of file set_tpl.h.

835  {
836  // determine the proper size of the hashtable
837  // by default, the size of the table is set so that the table does not take
838  // too much space while allowing to add a few elements without resizing
839  if (size == 0) size = std::max(Size(2), __inside.size() / 2);
840 
841  // create a new table
842  HashTable< Key, NewKey, NewAlloc > table(size);
843 
844  // fill the new hash table
846  iter != __inside.cend();
847  ++iter) {
848  table.insert(iter.key(), f(iter.key()));
849  }
850 
851  return table;
852  }
Size size() const noexcept
Returns the number of elements stored into the hashtable.
const const_iterator & cend() const noexcept
Returns the unsafe const_iterator pointing to the end of the hashtable.
const_iterator cbegin() const
Returns an unsafe const_iterator pointing to the beginning of the hashtable.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:698

◆ hashMap() [2/2]

template<typename Key, typename Alloc >
template<typename NewKey , typename NewAlloc >
HashTable< Key, NewKey, NewAlloc > gum::Set< Key, Alloc >::hashMap ( const NewKey &  val,
Size  size = 0 
) const

Creates a hash table of NewKey from the set.

Warning
The order in the resulting hash table may not be similar to that of the original set. Hence iterators on the former may not parse it in the same order as iterators on the latter.
Parameters
valThe value taken by all the elements of the resulting hashtable.
sizeThe size of the resulting hash table. When equal to 0, a default size is computed that is a good trade-off between space consumption and efficiency of new elements insertions.

Definition at line 857 of file set_tpl.h.

858  {
859  // determine the proper size of the hashtable
860  // by default, the size of the table is set so that the table does not take
861  // too much space while allowing to add a few elements without resizing
862  if (size == 0) size = std::max(Size(2), __inside.size() / 2);
863 
864  // create a new table
865  HashTable< Key, NewKey, NewAlloc > table(size);
866 
867  // fill the new hash table
869  iter != __inside.cend();
870  ++iter) {
871  table.insert(iter.key(), val);
872  }
873 
874  return table;
875  }
Size size() const noexcept
Returns the number of elements stored into the hashtable.
const const_iterator & cend() const noexcept
Returns the unsafe const_iterator pointing to the end of the hashtable.
const_iterator cbegin() const
Returns an unsafe const_iterator pointing to the beginning of the hashtable.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:698

◆ insert() [1/2]

template<typename Key, typename Alloc >
INLINE void gum::Set< Key, Alloc >::insert ( const Key &  k)

Inserts a new element into the set.

Parameters
kThe new element to insert.
Warning
if the set already contains the element, nothing is done. In particular, it is not added to the set and no exception is thrown.

Definition at line 610 of file set_tpl.h.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::__addEdgesInReducedGraph(), gum::NodeGraphPart::__addHole(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__AR(), gum::MarkovBlanket::__buildMarkovBlanket(), gum::prm::gspan::StrictSearch< GUM_SCALAR >::__buildPatternGraph(), gum::prm::StructuredInference< GUM_SCALAR >::__buildPatternGraph(), gum::prm::StructuredInference< GUM_SCALAR >::__buildReduceGraph(), gum::prm::o3prm::O3TypeFactory< GUM_SCALAR >::__checkO3IntTypes(), gum::prm::o3prm::O3TypeFactory< GUM_SCALAR >::__checkO3RealTypes(), gum::StaticTriangulation::__computeRecursiveThinning(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__connect(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__directedPath(), gum::prm::SVE< GUM_SCALAR >::__eliminateDelayedVariables(), gum::prm::SVED< GUM_SCALAR >::__eliminateNodes(), gum::prm::SVE< GUM_SCALAR >::__eliminateNodes(), gum::prm::SVED< GUM_SCALAR >::__eliminateNodesDownward(), gum::prm::SVE< GUM_SCALAR >::__eliminateNodesDownward(), gum::prm::SVED< GUM_SCALAR >::__eliminateNodesUpward(), gum::prm::SVED< GUM_SCALAR >::__eliminateNodesWithEvidence(), gum::prm::SVE< GUM_SCALAR >::__eliminateNodesWithEvidence(), gum::prm::gspan::StrictSearch< GUM_SCALAR >::__elimination_cost(), gum::prm::StructuredBayesBall< GUM_SCALAR >::__fillMaps(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClasses(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClasses(), gum::DAG::__hasDirectedPath(), gum::prm::SVED< GUM_SCALAR >::__initElimOrder(), gum::prm::SVE< GUM_SCALAR >::__initElimOrder(), gum::prm::gspan::DFSTree< GUM_SCALAR >::__initialiaze_root(), gum::prm::SVED< GUM_SCALAR >::__initLiftedNodes(), gum::prm::SVE< GUM_SCALAR >::__initLiftedNodes(), gum::prm::SVED< GUM_SCALAR >::__initReqSets(), gum::prm::SVED< GUM_SCALAR >::__insertEvidence(), gum::prm::SVE< GUM_SCALAR >::__insertEvidence(), gum::prm::SVED< GUM_SCALAR >::__insertLiftedNodes(), gum::prm::SVE< GUM_SCALAR >::__insertLiftedNodes(), gum::prm::StructuredInference< GUM_SCALAR >::__insertNodeInElimLists(), gum::prm::PRMInstance< GUM_SCALAR >::__instantiateSlotChain(), gum::OrderedEliminationSequenceStrategy::__isOrderNeeded(), gum::prm::StructuredInference< GUM_SCALAR >::__reduceAloneInstances(), gum::prm::StructuredInference< GUM_SCALAR >::__reducePattern(), gum::prm::StructuredInference< GUM_SCALAR >::__removeBarrenNodes(), gum::prm::GSpan< GUM_SCALAR >::__sortPatterns(), gum::EssentialGraph::__strongly_protected(), gum::StaticTriangulation::__triangulate(), gum::prm::SVE< GUM_SCALAR >::__variableElimination(), gum::Potential< GUM_SCALAR >::_complementVars(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::_initialize(), gum::PartialOrderedEliminationSequenceStrategy::_isPartialOrderNeeded(), gum::prm::SVED< GUM_SCALAR >::_marginal(), gum::prm::SVE< GUM_SCALAR >::_marginal(), gum::prm::StructuredInference< GUM_SCALAR >::_marginal(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::_msgL(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_transpose(), gum::MarginalTargetedInference< GUM_SCALAR >::addAllTargets(), gum::ArcGraphPart::addArc(), gum::EdgeGraphPart::addEdge(), gum::BayesNetInference< GUM_SCALAR >::addEvidence(), gum::LeafAggregator::addLeaf(), gum::NodeGraphPart::addNodeWithId(), gum::MarginalTargetedInference< GUM_SCALAR >::addTarget(), gum::NodeGraphPart::asNodeSet(), gum::BarrenNodesFinder::barrenNodes(), gum::BarrenNodesFinder::barrenPotentials(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildClasses(), gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::BayesNetInference< GUM_SCALAR >::chgEvidence(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAttributes(), gum::prm::eliminateNode(), gum::DefaultPartialOrderedEliminationSequenceStrategy::eliminationUpdate(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), gum::StaticTriangulation::fillIns(), gum::Potential< GUM_SCALAR >::fillWith(), gum::Potential< GUM_SCALAR >::findAll(), gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder(), gum::prm::gspan::DFSTree< GUM_SCALAR >::growPattern(), gum::DAGCycleDetector::hasCycleFromModifications(), gum::FMDPLearner< VariableAttributeSelection, RewardAttributeSelection, LearnerSelection >::initialize(), gum::Set< gum::Potential< GUM_SCALAR > * >::insert(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::Set< gum::Potential< GUM_SCALAR > * >::operator+=(), gum::prm::PRMClass< double >::PRMClass(), gum::O3prmBNReader< GUM_SCALAR >::proceed(), gum::BayesBall::requisiteNodes(), gum::dSeparation::requisiteNodes(), gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveClassElement(), gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveInterface(), gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveSlotType(), gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveType(), gum::BayesNet< double >::reverseArc(), gum::PartialOrderedEliminationSequenceStrategy::setPartialOrder(), gum::prm::PRMFactory< GUM_SCALAR >::startClass(), gum::IMDDI< AttributeSelection, isScalar >::updateGraph(), and gum::ITI< AttributeSelection, isScalar >::updateGraph().

610  {
611  // WARNING: we shall always test whether k already belongs to the set before
612  // trying to insert it because we set __inside's key uniqueness policy to
613  // false
614  if (!contains(k)) {
615  // insert the element
616  __inside.insert(k, true);
617 
618  // Note that actually there is no need to update the end iterator as this
619  // one
620  // is not affected by changes within hashtables (adding/deleting
621  // elements).
622  // Hence, for speedup, we do not update the end iterator
623  }
624  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:578
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ insert() [2/2]

template<typename Key, typename Alloc >
INLINE void gum::Set< Key, Alloc >::insert ( Key &&  k)

Inserts a new element into the set.

Parameters
kThe new element to insert.
Warning
if the set already contains the element, nothing is done. In particular, it is not added to the set and no exception is thrown.

Definition at line 628 of file set_tpl.h.

628  {
629  // WARNING: we shall always test whether k already belongs to the set before
630  // trying to insert it because we set __inside's key uniqueness policy to
631  // false
632  if (!contains(k)) {
633  // insert the element
634  __inside.insert(std::move(k), true);
635 
636  // Note that actually there is no need to update the end iterator as this
637  // one
638  // is not affected by changes within hashtables (adding/deleting
639  // elements).
640  // Hence, for speedup, we do not update the end iterator
641  }
642  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:578
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ isSubsetOf() [1/2]

template<typename Key, typename Alloc = std::allocator< Key >>
template<typename OtherAlloc >
bool gum::Set< Key, Alloc >::isSubsetOf ( const Set< Key, OtherAlloc > &  s) const
Returns
Returns true if *this is a strict subset of s

Referenced by gum::Set< gum::Potential< GUM_SCALAR > * >::isSupersetOf(), and gum::JointTargetedInference< GUM_SCALAR >::jointPosterior().

+ Here is the caller graph for this function:

◆ isSubsetOf() [2/2]

template<typename Key, typename Alloc = std::allocator< Key >>
template<typename OtherAlloc >
INLINE bool gum::Set< Key, Alloc >::isSubsetOf ( const Set< Key, OtherAlloc > &  s) const

Definition at line 586 of file set_tpl.h.

586  {
587  if (this->size() >= s.size()) { return false; }
588 
589  for (const auto& elt : *this) {
590  if (!s.contains(elt)) { return false; }
591  }
592  return true;
593  }
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:698

◆ isSupersetOf() [1/2]

template<typename Key, typename Alloc = std::allocator< Key >>
template<typename OtherAlloc >
bool gum::Set< Key, Alloc >::isSupersetOf ( const Set< Key, OtherAlloc > &  s) const
Returns
Returns true if *this is a strict superset of s

◆ isSupersetOf() [2/2]

template<typename Key, typename Alloc = std::allocator< Key >>
template<typename OtherAlloc >
INLINE bool gum::Set< Key, Alloc >::isSupersetOf ( const Set< Key, OtherAlloc > &  s) const

Definition at line 598 of file set_tpl.h.

598  {
599  return s.isSubsetOf(*this);
600  }

◆ listMap()

template<typename Key, typename Alloc >
template<typename NewKey , typename NewAlloc >
List< NewKey, NewAlloc > gum::Set< Key, Alloc >::listMap ( NewKey(*)(const Key &)  f) const

A method to create a List of NewKey from the set.

Warning
The order of the NewKey elements in the resulting list is arbitrary.
Parameters
fA function that maps a Key into a NewKey

Definition at line 881 of file set_tpl.h.

881  {
882  // create a new list
883  List< NewKey, NewAlloc > list;
884 
885  // fill the new list
887  iter != __inside.cend();
888  ++iter) {
889  list.pushBack(f(iter.key()));
890  }
891 
892  return list;
893  }
const const_iterator & cend() const noexcept
Returns the unsafe const_iterator pointing to the end of the hashtable.
const_iterator cbegin() const
Returns an unsafe const_iterator pointing to the beginning of the hashtable.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764

◆ operator!=() [1/2]

template<typename Key, typename Alloc = std::allocator< Key >>
template<typename OtherAlloc >
bool gum::Set< Key, Alloc >::operator!= ( const Set< Key, OtherAlloc > &  s2) const

Mathematical inequality between two sets.

Parameters
s2The gum::Set to test for inequality.
Template Parameters
OtherAllocThe other gum::Set allocator.
Returns
Returns true if both gum::Set are not equal.

◆ operator!=() [2/2]

template<typename Key, typename Alloc = std::allocator< Key >>
template<typename OtherAlloc >
INLINE bool gum::Set< Key, Alloc >::operator!= ( const Set< Key, OtherAlloc > &  s2) const

Definition at line 478 of file set_tpl.h.

478  {
479  return !(operator==(s2));
480  }
bool operator==(const Set< Key, OtherAlloc > &s2) const
Mathematical equality between two sets.
Definition: set_tpl.h:458

◆ operator*()

template<typename Key, typename Alloc >
template<typename OtherAlloc >
Set< Key, Alloc > gum::Set< Key, Alloc >::operator* ( const Set< Key, OtherAlloc > &  s2) const

Intersection operator.

Template Parameters
OtherAllocThe other gum::Set allocator.
Parameters
s2The gum::Set to intersect.
Returns
Returns a Set containing the elements belonging both to this and s2.

Definition at line 712 of file set_tpl.h.

712  {
713  Set< Key, Alloc > res;
714  const HashTable< Key, bool, OtherAlloc >& h2 = s2.__inside;
715  HashTable< Key, bool, Alloc >& h_r = res.__inside;
716 
717  if (size() < h2.size()) {
719  iter != __inside.cend();
720  ++iter) {
721  if (h2.exists(iter.key())) h_r.insert(iter.key(), true);
722  }
723  } else {
724  for (HashTableConstIterator< Key, bool > iter = h2.cbegin();
725  iter != h2.cend();
726  ++iter) {
727  if (__inside.exists(iter.key())) h_r.insert(iter.key(), true);
728  }
729  }
730 
731  return res;
732  }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
const const_iterator & cend() const noexcept
Returns the unsafe const_iterator pointing to the end of the hashtable.
const_iterator cbegin() const
Returns an unsafe const_iterator pointing to the beginning of the hashtable.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:698
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ operator*=()

template<typename Key, typename Alloc >
template<typename OtherAlloc >
const Set< Key, Alloc > & gum::Set< Key, Alloc >::operator*= ( const Set< Key, OtherAlloc > &  s2)

Intersection update operator.

Template Parameters
OtherAllocThe other gum::Set allocator.
Parameters
s2The gum::Set to intersect.
Returns
Returns this. Now this contains the elements belonging both to this and s2.

Definition at line 739 of file set_tpl.h.

739  {
740  if (&s2 != this) {
741  const HashTable< Key, bool, OtherAlloc >& h2 = s2.__inside;
742  for (auto iter = __inside.beginSafe(); iter != __inside.endSafe(); ++iter) {
743  if (!h2.exists(iter.key())) __inside.erase(iter);
744  }
745  }
746 
747  return *this;
748  }
const iterator_safe & endSafe() noexcept
Returns the safe iterator pointing to the end of the hashtable.
void erase(const Key &key)
Removes a given element from the hash table.
iterator_safe beginSafe()
Returns the safe iterator pointing to the beginning of the hashtable.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764

◆ operator+()

template<typename Key, typename Alloc >
template<typename OtherAlloc >
Set< Key, Alloc > gum::Set< Key, Alloc >::operator+ ( const Set< Key, OtherAlloc > &  s2) const

Union operator.

Template Parameters
OtherAllocThe other gum::Set allocator.
Parameters
s2The gum::Set to union.
Returns
Returns a new Set containing the union of the elements of this and s2.

Definition at line 770 of file set_tpl.h.

770  {
771  Set< Key, Alloc > res = *this;
772  const HashTable< Key, bool, OtherAlloc >& h2 = s2.__inside;
773  HashTable< Key, bool, Alloc >& h_r = res.__inside;
774 
775  for (HashTableConstIterator< Key, bool > iter = h2.cbegin(); iter != h2.cend();
776  ++iter) {
777  if (!h_r.exists(iter.key())) h_r.insert(iter.key(), true);
778  }
779 
780  return res;
781  }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in 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.

◆ operator+=()

template<typename Key, typename Alloc >
template<typename OtherAlloc >
const Set< Key, Alloc > & gum::Set< Key, Alloc >::operator+= ( const Set< Key, OtherAlloc > &  s2)

Union update operator.

Template Parameters
OtherAllocThe other gum::Set allocator.
Parameters
s2The gum::Set to update
Returns
Returns this. Now this contains the elements belonging both to this or to s2.

Definition at line 755 of file set_tpl.h.

755  {
756  if (&s2 != this) {
757  for (auto pair : s2.__inside) {
758  if (!__inside.exists(pair.first)) __inside.insert(pair.first, true);
759  }
760  }
761 
762  return *this;
763  }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ operator-()

template<typename Key, typename Alloc >
template<typename OtherAlloc >
Set< Key, Alloc > gum::Set< Key, Alloc >::operator- ( const Set< Key, OtherAlloc > &  s2) const

Disjunction operator.

Template Parameters
OtherAllocThe other gum::Set allocator.
Parameters
s2The gum::Set to disjunct.
Returns
Returns a Set whose elements belong to this but not to s2.
Warning
Unlike + and *, the - operator is not commutative!

Definition at line 788 of file set_tpl.h.

788  {
789  Set< Key, Alloc > res;
790  const HashTable< Key, bool, OtherAlloc >& h2 = s2.__inside;
791  HashTable< Key, bool, Alloc >& h_r = res.__inside;
792 
794  iter != __inside.cend();
795  ++iter)
796  if (!h2.exists(iter.key())) h_r.insert(iter.key(), true);
797 
798  return res;
799  }
const const_iterator & cend() const noexcept
Returns the unsafe const_iterator pointing to the end of the hashtable.
const_iterator cbegin() const
Returns an unsafe const_iterator pointing to the beginning of the hashtable.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ operator<<() [1/2]

template<typename Key, typename Alloc >
INLINE Set< Key, Alloc > & gum::Set< Key, Alloc >::operator<< ( const Key &  k)

Adds a new element to the set (alias for insert).

Parameters
kThe new element to add.
Returns
Returns this gum::Set.

Definition at line 677 of file set_tpl.h.

677  {
678  insert(k);
679  return *this;
680  }
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:610

◆ operator<<() [2/2]

template<typename Key, typename Alloc >
INLINE Set< Key, Alloc > & gum::Set< Key, Alloc >::operator<< ( Key &&  k)

Adds a new element to the set (alias for insert).

Parameters
kThe new element to add.
Returns
Returns this gum::Set.

Definition at line 684 of file set_tpl.h.

684  {
685  insert(std::move(k));
686  return *this;
687  }
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:610

◆ operator=() [1/3]

template<typename Key, typename Alloc>
Set< Key, Alloc > & gum::Set< Key, Alloc >::operator= ( const Set< Key, Alloc > &  from)

Copy operator.

Parameters
fromThe gum::Set to copy.
Returns
Returns this gum::Set.

Definition at line 388 of file set_tpl.h.

388  {
389  // avoid self assignment
390  if (&s != this) {
391  // remove the old content of the set. Actually, we remove all the elements
392  // from the underlying hashtable. Note that, doing so, all the hashtable
393  // iterators will be updated as well. In turn, this will imply that,
394  // whenever
395  // an operation will be performed on a SetIteratorSafe, this will raise an
396  // exception.
397  clear();
398 
399  // prepare the set for its new data
400  resize(s.capacity());
401  setResizePolicy(s.resizePolicy());
402 
403  // copy the set
404  __inside = s.__inside;
405 
406  // Note that actually there is no need to update the end iterator as this
407  // one
408  // is not affected by changes within hashtables (adding/deleting
409  // elements).
410  // Hence, for speedup, we do not update the end iterator
411  }
412 
413  return *this;
414  }
void resize(Size new_capacity)
Changes the size of the underlying hash table containing the set.
Definition: set_tpl.h:549
void setResizePolicy(const bool new_policy)
Enables the user to change dynamically the resizing policy of the underlying hash table...
Definition: set_tpl.h:561
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:372

◆ operator=() [2/3]

template<typename Key, typename Alloc >
template<typename OtherAlloc >
Set< Key, Alloc > & gum::Set< Key, Alloc >::operator= ( const Set< Key, OtherAlloc > &  from)

Generalized copy operator.

Parameters
fromThe gum::Set to copy.
Template Parameters
OtherAllocThe other gum::Set allocator.
Returns
Returns this gum::Set.

Definition at line 420 of file set_tpl.h.

420  {
421  // avoid self assignment
422  if (this != reinterpret_cast< const Set< Key, Alloc >* >(&s)) {
423  // remove the old content of the set. Actually, we remove all the elements
424  // from the underlying hashtable. Note that, doing so, all the hashtable
425  // iterators will be updated as well. In turn, this will imply that,
426  // whenever
427  // an operation will be performed on a SetIteratorSafe, this will raise an
428  // exception.
429  clear();
430 
431  // prepare the set for its new data
432  resize(s.capacity());
433  setResizePolicy(s.resizePolicy());
434 
435  // copy the set
436  __inside = s.__inside;
437 
438  // Note that actually there is no need to update the end iterator as this
439  // one
440  // is not affected by changes within hashtables (adding/deleting
441  // elements).
442  // Hence, for speedup, we do not update the end iterator
443  }
444 
445  return *this;
446  }
void resize(Size new_capacity)
Changes the size of the underlying hash table containing the set.
Definition: set_tpl.h:549
void setResizePolicy(const bool new_policy)
Enables the user to change dynamically the resizing policy of the underlying hash table...
Definition: set_tpl.h:561
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:372

◆ operator=() [3/3]

template<typename Key, typename Alloc>
Set< Key, Alloc > & gum::Set< Key, Alloc >::operator= ( Set< Key, Alloc > &&  from)

Move operator.

Parameters
fromThe gum::Set to move.
Returns
Returns this gum::Set.

Definition at line 450 of file set_tpl.h.

450  {
451  __inside = std::move(from.__inside);
452  return *this;
453  }
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764

◆ operator==()

template<typename Key, typename Alloc >
template<typename OtherAlloc >
bool gum::Set< Key, Alloc >::operator== ( const Set< Key, OtherAlloc > &  s2) const

Mathematical equality between two sets.

Parameters
s2The gum::Set to test for equality.
Template Parameters
OtherAllocThe other gum::Set allocator.
Returns
Returns true if both gum::Set are equal.

Definition at line 458 of file set_tpl.h.

458  {
459  const HashTable< Key, bool, OtherAlloc >& h2 = s2.__inside;
460 
461  // check whether both sets have the same number of elements
462  if (size() != h2.size()) return false;
463 
464  // check the content of the sets
466  iter != __inside.cend();
467  ++iter) {
468  if (!h2.exists(iter.key())) return false;
469  }
470 
471  return true;
472  }
const const_iterator & cend() const noexcept
Returns the unsafe const_iterator pointing to the end of the hashtable.
const_iterator cbegin() const
Returns an unsafe const_iterator pointing to the beginning of the hashtable.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:698

◆ operator>>()

template<typename Key, typename Alloc >
INLINE Set< Key, Alloc > & gum::Set< Key, Alloc >::operator>> ( const Key &  k)

Removes an element from the set (alias for erase).

Parameters
kThe element to remove.
Returns
Return this gum::Set.

Definition at line 691 of file set_tpl.h.

691  {
692  erase(k);
693  return *this;
694  }
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:653

◆ resize()

template<typename Key , typename Alloc >
INLINE void gum::Set< Key, Alloc >::resize ( Size  new_capacity)

Changes the size of the underlying hash table containing the set.

See gum::HashTable::resize(Size) method resize for more details.

Parameters
new_capacityThe underlying hash table new size.

Definition at line 549 of file set_tpl.h.

Referenced by gum::StaticTriangulation::__triangulate(), and gum::Set< gum::Potential< GUM_SCALAR > * >::resize().

549  {
550  __inside.resize(new_size);
551 
552  // Note that actually there is no need to update the end iterator as this
553  // one
554  // is not affected by changes within hashtables (adding/deleting elements).
555  // Hence, for speedup, we do not update the end iterator
556  }
void resize(Size new_size)
Changes the number of slots in the &#39;nodes&#39; vector of the hash table.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
+ Here is the caller graph for this function:

◆ resizePolicy()

template<typename Key , typename Alloc >
INLINE bool gum::Set< Key, Alloc >::resizePolicy ( ) const

Returns the current resizing policy of the underlying hash table.

Returns
Returns the current resizing policy of the underlying hash table.

Definition at line 572 of file set_tpl.h.

Referenced by gum::Set< gum::Potential< GUM_SCALAR > * >::operator=(), and gum::Set< gum::Potential< GUM_SCALAR > * >::resizePolicy().

572  {
573  return __inside.resizePolicy();
574  }
bool resizePolicy() const noexcept
Returns the current resizing policy.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
+ Here is the caller graph for this function:

◆ setResizePolicy()

template<typename Key , typename Alloc >
INLINE void gum::Set< Key, Alloc >::setResizePolicy ( const bool  new_policy)

Enables the user to change dynamically the resizing policy of the underlying hash table.

When new_policy is false, the set will not try to change its memory size, hence resulting in potentially slower accesses.

Parameters
new_policyIf true the set updates dynamically its memory consumption to guarantee that its elements are fast to retrieve.

Definition at line 561 of file set_tpl.h.

Referenced by gum::Set< gum::Potential< GUM_SCALAR > * >::setResizePolicy().

561  {
562  __inside.setResizePolicy(new_policy);
563 
564  // Note that actually there is no need to update the end iterator as this
565  // one
566  // is not affected by changes within hashtables (adding/deleting elements).
567  // Hence, for speedup, we do not update the end iterator
568  }
void setResizePolicy(const bool new_policy) noexcept
Enables the user to change dynamically the resizing policy.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764
+ Here is the caller graph for this function:

◆ size()

template<typename Key , typename Alloc >
INLINE Size gum::Set< Key, Alloc >::size ( ) const
noexcept

Returns the number of elements in the set.

Returns
Returns the number of elements in the set.

Definition at line 698 of file set_tpl.h.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::__buildReduceGraph(), gum::DefaultJunctionTreeStrategy::__computeJunctionTree(), gum::BinaryJoinTreeConverterDefault::__convertClique(), gum::prm::StructuredInference< GUM_SCALAR >::__eliminateObservedNodes(), gum::prm::StructuredInference< GUM_SCALAR >::__eliminateObservedNodesInSource(), gum::prm::gspan::StrictSearch< GUM_SCALAR >::__elimination_cost(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::SVED< GUM_SCALAR >::__initLiftedNodes(), gum::prm::SVE< GUM_SCALAR >::__initLiftedNodes(), gum::prm::StructuredInference< GUM_SCALAR >::__insertNodeInElimLists(), gum::prm::StructuredInference< GUM_SCALAR >::__reduceAloneInstances(), gum::EssentialGraph::__strongly_protected(), gum::StaticTriangulation::__triangulate(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::_initialize(), gum::learning::Miic::_initiation(), gum::prm::StructuredInference< GUM_SCALAR >::_marginal(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::_msgL(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::_msgP(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNode(), gum::BarrenNodesFinder::barrenNodes(), gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), gum::prm::eliminateNode(), gum::StaticTriangulation::fillIns(), gum::prm::gspan::DFSTree< GUM_SCALAR >::frequency(), gum::Set< gum::Potential< GUM_SCALAR > * >::isSubsetOf(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::BayesNetInference< GUM_SCALAR >::nbrHardEvidence(), gum::BayesNetInference< GUM_SCALAR >::nbrSoftEvidence(), gum::MarginalTargetedInference< GUM_SCALAR >::nbrTargets(), gum::prm::gspan::DFSTree< GUM_SCALAR >::NeighborDegreeSort::operator()(), gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveClassElement(), gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveInterface(), gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveSlotType(), gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveType(), gum::Set< gum::Potential< GUM_SCALAR > * >::size(), gum::ArcGraphPart::sizeArcs(), gum::EdgeGraphPart::sizeEdges(), gum::InfluenceDiagram< GUM_SCALAR >::toDot(), and gum::StaticTriangulation::triangulatedGraph().

698  {
699  return __inside.size();
700  }
Size size() const noexcept
Returns the number of elements stored into the hashtable.
HashTable< Key, bool, Alloc > __inside
A set of X&#39;s is actually a hash table whose keys are the X&#39;s.
Definition: set.h:764

◆ toString()

template<typename Key , typename Alloc >
INLINE std::string gum::Set< Key, Alloc >::toString ( ) const

Prints the content of the set.

Returns
Returns the content of the set.

Definition at line 803 of file set_tpl.h.

803  {
804  std::stringstream out;
805  bool first = true;
806  out << "{";
807 
808  for (iterator iter = begin(); iter != end(); ++iter) {
809  if (first) {
810  out << *iter;
811  first = false;
812  } else {
813  out << "," << *iter;
814  }
815  }
816 
817  out << "}";
818 
819  std::string res;
820  out >> res;
821  return res;
822  }
const iterator & end() const noexcept
The usual unsafe end iterator to parse the set.
Definition: set_tpl.h:527
iterator begin() const
The usual unsafe begin iterator to parse the set.
Definition: set_tpl.h:514
SetIterator< Key > iterator
Types for STL compliance.
Definition: set.h:174

Friends And Related Function Documentation

◆ Set

template<typename Key, typename Alloc = std::allocator< Key >>
template<typename K , typename A >
friend class Set
friend

Friends to speed up access.

Definition at line 760 of file set.h.

◆ SetIterator< Key >

template<typename Key, typename Alloc = std::allocator< Key >>
friend class SetIterator< Key >
friend

Friends to speed up access.

Definition at line 757 of file set.h.

◆ SetIteratorSafe< Key >

template<typename Key, typename Alloc = std::allocator< Key >>
friend class SetIteratorSafe< Key >
friend

Friends to speed up access.

Definition at line 758 of file set.h.

Member Data Documentation

◆ __inside


The documentation for this class was generated from the following files: