aGrUM  0.17.2
a C++ library for (probabilistic) graphical models
gum::Set< Key, Alloc > Class Template Reference

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

#include <agrum/tools/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 165 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 176 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 178 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 180 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 173 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 171 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 175 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 177 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 179 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 172 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 170 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 174 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 169 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 321 of file set_tpl.h.

321  :
322  // create the hash table without key uniqueness policy (as we will
323  // check
324  // ourselves the uniqueness of Keys before inserting new elements)
325  __inside(capacity, resize_policy, false) {
326  GUM_CONSTRUCTOR(Set);
327 
328  // make sure the end() iterator is constructed properly
329  endSafe4Statics();
330  end4Statics();
331  }
Size capacity() const
Returns the capacity of the underlying hash table containing the set.
Definition: set_tpl.h:548
static const iterator & end4Statics()
Returns the end iterator for other classes&#39; statics (read the detailed description of this method)...
Definition: set_tpl.h:307
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:293
friend class Set
Friends to speed up access.
Definition: set.h:763
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:767

◆ 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 335 of file set_tpl.h.

335  :
336  __inside(Size(list.size()) / 2, true, false) {
337  GUM_CONSTRUCTOR(Set);
338  for (const auto& elt: list) {
339  insert(elt);
340  }
341 
342  // make sure the end() iterator is constructed properly
343  endSafe4Statics();
344  end4Statics();
345  }
static const iterator & end4Statics()
Returns the end iterator for other classes&#39; statics (read the detailed description of this method)...
Definition: set_tpl.h:307
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:293
friend class Set
Friends to speed up access.
Definition: set.h:763
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:767
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:615

◆ 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 349 of file set_tpl.h.

349  :
350  __inside(s.__inside) {
351  GUM_CONS_CPY(Set);
352  }
friend class Set
Friends to speed up access.
Definition: set.h:763
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:767

◆ 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 364 of file set_tpl.h.

364  :
365  __inside(std::move(s.__inside)) {
366  GUM_CONS_MOV(Set);
367  }
friend class Set
Friends to speed up access.
Definition: set.h:763
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:767

◆ ~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 357 of file set_tpl.h.

357  :
358  __inside(s.__inside) {
359  GUM_CONS_CPY(Set);
360  }
friend class Set
Friends to speed up access.
Definition: set.h:763
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:767

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 519 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().

519  {
520  return SetIterator< Key >{*this};
521  }
friend class SetIterator< Key >
Friends to speed up access.
Definition: set.h:760
+ 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 490 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().

490  {
491  return SetIteratorSafe< Key >{*this};
492  }
friend class SetIteratorSafe< Key >
Friends to speed up access.
Definition: set.h:761
+ 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 548 of file set_tpl.h.

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

548  {
549  return __inside.capacity();
550  }
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:767
+ 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 526 of file set_tpl.h.

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

526  {
527  return SetIterator< Key >{*this};
528  }
friend class SetIterator< Key >
Friends to speed up access.
Definition: set.h:760
+ 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 497 of file set_tpl.h.

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

497  {
498  return SetIteratorSafe< Key >{*this};
499  }
friend class SetIteratorSafe< Key >
Friends to speed up access.
Definition: set.h:761
+ 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 541 of file set_tpl.h.

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

541  {
542  return *(reinterpret_cast< const SetIterator< Key >* >(
543  SetIteratorStaticEnd::__SetIterEnd));
544  }
friend class SetIterator< Key >
Friends to speed up access.
Definition: set.h:760
+ 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 512 of file set_tpl.h.

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

512  {
513  return *(reinterpret_cast< const SetIteratorSafe< Key >* >(
514  SetIteratorStaticEnd::__SetIterEndSafe));
515  }
friend class SetIteratorSafe< Key >
Friends to speed up access.
Definition: set.h:761
+ 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 377 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().

377  {
378  // first we remove all the elements from the hashtable actually containing
379  // the elements of the set. Note that, doing so, all the hashtable iterators
380  // will be updated as well. In turn, this will imply that, whenever an
381  // operation will be performed on a SetIteratorSafe, this will raise an
382  // exception.
383  __inside.clear();
384 
385  // Note that actually there is no need to update the end iterator as this
386  // one
387  // is not affected by changes within hashtables (adding/deleting elements).
388  // Hence, for speedup, we do not update the end iterator
389  }
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:767
+ 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 314 of file set_tpl.h.

314  {
315  return *(reinterpret_cast< const SetIterator< Key >* >(
316  SetIteratorStaticEnd::constEnd4Statics()));
317  }
friend class SetIterator< Key >
Friends to speed up access.
Definition: set.h:760

◆ 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 300 of file set_tpl.h.

300  {
301  return *(reinterpret_cast< const SetIteratorSafe< Key >* >(
302  SetIteratorStaticEnd::constEndSafe4Statics()));
303  }
friend class SetIteratorSafe< Key >
Friends to speed up access.
Definition: set.h:761

◆ 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 583 of file set_tpl.h.

Referenced by gum::NodeGraphPart::__addHole(), gum::StaticTriangulation::__computeMaxPrimeJunctionTree(), 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::DiGraph::hasDirectedPath(), 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().

583  {
584  return __inside.exists(k);
585  }
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:767
+ 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 652 of file set_tpl.h.

652  {
653  insert(std::move(Key(std::forward< Args >(args)...)));
654  }
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:615

◆ 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 709 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().

709  {
710  return __inside.empty();
711  }
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:767
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 532 of file set_tpl.h.

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

533  {
534  return *(reinterpret_cast< const SetIterator< Key >* >(
535  SetIteratorStaticEnd::__SetIterEnd));
536  }
friend class SetIterator< Key >
Friends to speed up access.
Definition: set.h:760
+ 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 307 of file set_tpl.h.

307  {
308  return *(reinterpret_cast< const SetIterator< Key >* >(
309  SetIteratorStaticEnd::end4Statics()));
310  }
friend class SetIterator< Key >
Friends to speed up access.
Definition: set.h:760

◆ 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 504 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().

504  {
505  return *(reinterpret_cast< const SetIteratorSafe< Key >* >(
506  SetIteratorStaticEnd::__SetIterEndSafe));
507  }
friend class SetIteratorSafe< Key >
Friends to speed up access.
Definition: set.h:761
+ 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 293 of file set_tpl.h.

293  {
294  return *(reinterpret_cast< const SetIteratorSafe< Key >* >(
295  SetIteratorStaticEnd::endSafe4Statics()));
296  }
friend class SetIteratorSafe< Key >
Friends to speed up access.
Definition: set.h:761

◆ 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 658 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().

658  {
659  // erase the element (if it exists)
660  __inside.erase(k);
661 
662  // Note that actually there is no need to update the end iterator as this
663  // one
664  // is not affected by changes within hashtables (adding/deleting elements).
665  // Hence, for speedup, we do not update the end iterator
666  }
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:767
+ 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 670 of file set_tpl.h.

670  {
671  // erase the element
672  __inside.erase(iter.__ht_iter);
673 
674  // Note that actually there is no need to update the end iterator as this
675  // one
676  // is not affected by changes within hashtables (adding/deleting elements).
677  // Hence, for speedup, we do not update the end iterator
678  }
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:767

◆ 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 609 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::UGmodel::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().

609  {
610  return __inside.exists(k);
611  }
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:767
+ 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 840 of file set_tpl.h.

840  {
841  // determine the proper size of the hashtable
842  // by default, the size of the table is set so that the table does not take
843  // too much space while allowing to add a few elements without resizing
844  if (size == 0) size = std::max(Size(2), __inside.size() / 2);
845 
846  // create a new table
847  HashTable< Key, NewKey, NewAlloc > table(size);
848 
849  // fill the new hash table
851  iter != __inside.cend();
852  ++iter) {
853  table.insert(iter.key(), f(iter.key()));
854  }
855 
856  return table;
857  }
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:767
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:703

◆ 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 862 of file set_tpl.h.

863  {
864  // determine the proper size of the hashtable
865  // by default, the size of the table is set so that the table does not take
866  // too much space while allowing to add a few elements without resizing
867  if (size == 0) size = std::max(Size(2), __inside.size() / 2);
868 
869  // create a new table
870  HashTable< Key, NewKey, NewAlloc > table(size);
871 
872  // fill the new hash table
874  iter != __inside.cend();
875  ++iter) {
876  table.insert(iter.key(), val);
877  }
878 
879  return table;
880  }
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:767
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:703

◆ 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 615 of file set_tpl.h.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::__addEdgesInReducedGraph(), gum::NodeGraphPart::__addHole(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__AR(), 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::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::DiGraph::hasDirectedPath(), gum::FMDPLearner< VariableAttributeSelection, RewardAttributeSelection, LearnerSelection >::initialize(), gum::Set< gum::Potential< GUM_SCALAR > * >::insert(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::MarkovBlanket::MarkovBlanket(), gum::Set< gum::Potential< GUM_SCALAR > * >::operator+=(), gum::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().

615  {
616  // WARNING: we shall always test whether k already belongs to the set before
617  // trying to insert it because we set __inside's key uniqueness policy to
618  // false
619  if (!contains(k)) {
620  // insert the element
621  __inside.insert(k, true);
622 
623  // Note that actually there is no need to update the end iterator as this
624  // one
625  // is not affected by changes within hashtables (adding/deleting
626  // elements).
627  // Hence, for speedup, we do not update the end iterator
628  }
629  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:583
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:767
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 633 of file set_tpl.h.

633  {
634  // WARNING: we shall always test whether k already belongs to the set before
635  // trying to insert it because we set __inside's key uniqueness policy to
636  // false
637  if (!contains(k)) {
638  // insert the element
639  __inside.insert(std::move(k), true);
640 
641  // Note that actually there is no need to update the end iterator as this
642  // one
643  // is not affected by changes within hashtables (adding/deleting
644  // elements).
645  // Hence, for speedup, we do not update the end iterator
646  }
647  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:583
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:767
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 591 of file set_tpl.h.

591  {
592  if (this->size() >= s.size()) { return false; }
593 
594  for (const auto& elt: *this) {
595  if (!s.contains(elt)) { return false; }
596  }
597  return true;
598  }
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:703

◆ 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 603 of file set_tpl.h.

603  {
604  return s.isSubsetOf(*this);
605  }

◆ 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 886 of file set_tpl.h.

886  {
887  // create a new list
888  List< NewKey, NewAlloc > list;
889 
890  // fill the new list
892  iter != __inside.cend();
893  ++iter) {
894  list.pushBack(f(iter.key()));
895  }
896 
897  return list;
898  }
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:767

◆ 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 483 of file set_tpl.h.

483  {
484  return !(operator==(s2));
485  }
bool operator==(const Set< Key, OtherAlloc > &s2) const
Mathematical equality between two sets.
Definition: set_tpl.h:463

◆ 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 717 of file set_tpl.h.

717  {
718  Set< Key, Alloc > res;
719  const HashTable< Key, bool, OtherAlloc >& h2 = s2.__inside;
720  HashTable< Key, bool, Alloc >& h_r = res.__inside;
721 
722  if (size() < h2.size()) {
724  iter != __inside.cend();
725  ++iter) {
726  if (h2.exists(iter.key())) h_r.insert(iter.key(), true);
727  }
728  } else {
729  for (HashTableConstIterator< Key, bool > iter = h2.cbegin();
730  iter != h2.cend();
731  ++iter) {
732  if (__inside.exists(iter.key())) h_r.insert(iter.key(), true);
733  }
734  }
735 
736  return res;
737  }
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:767
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:703
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 744 of file set_tpl.h.

744  {
745  if (&s2 != this) {
746  const HashTable< Key, bool, OtherAlloc >& h2 = s2.__inside;
747  for (auto iter = __inside.beginSafe(); iter != __inside.endSafe(); ++iter) {
748  if (!h2.exists(iter.key())) __inside.erase(iter);
749  }
750  }
751 
752  return *this;
753  }
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:767

◆ 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 775 of file set_tpl.h.

775  {
776  Set< Key, Alloc > res = *this;
777  const HashTable< Key, bool, OtherAlloc >& h2 = s2.__inside;
778  HashTable< Key, bool, Alloc >& h_r = res.__inside;
779 
780  for (HashTableConstIterator< Key, bool > iter = h2.cbegin(); iter != h2.cend();
781  ++iter) {
782  if (!h_r.exists(iter.key())) h_r.insert(iter.key(), true);
783  }
784 
785  return res;
786  }
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 760 of file set_tpl.h.

760  {
761  if (&s2 != this) {
762  for (auto pair: s2.__inside) {
763  if (!__inside.exists(pair.first)) __inside.insert(pair.first, true);
764  }
765  }
766 
767  return *this;
768  }
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:767
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 793 of file set_tpl.h.

793  {
794  Set< Key, Alloc > res;
795  const HashTable< Key, bool, OtherAlloc >& h2 = s2.__inside;
796  HashTable< Key, bool, Alloc >& h_r = res.__inside;
797 
799  iter != __inside.cend();
800  ++iter)
801  if (!h2.exists(iter.key())) h_r.insert(iter.key(), true);
802 
803  return res;
804  }
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:767
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 682 of file set_tpl.h.

682  {
683  insert(k);
684  return *this;
685  }
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:615

◆ 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 689 of file set_tpl.h.

689  {
690  insert(std::move(k));
691  return *this;
692  }
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:615

◆ 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 393 of file set_tpl.h.

393  {
394  // avoid self assignment
395  if (&s != this) {
396  // remove the old content of the set. Actually, we remove all the elements
397  // from the underlying hashtable. Note that, doing so, all the hashtable
398  // iterators will be updated as well. In turn, this will imply that,
399  // whenever
400  // an operation will be performed on a SetIteratorSafe, this will raise an
401  // exception.
402  clear();
403 
404  // prepare the set for its new data
405  resize(s.capacity());
406  setResizePolicy(s.resizePolicy());
407 
408  // copy the set
409  __inside = s.__inside;
410 
411  // Note that actually there is no need to update the end iterator as this
412  // one
413  // is not affected by changes within hashtables (adding/deleting
414  // elements).
415  // Hence, for speedup, we do not update the end iterator
416  }
417 
418  return *this;
419  }
void resize(Size new_capacity)
Changes the size of the underlying hash table containing the set.
Definition: set_tpl.h:554
void setResizePolicy(const bool new_policy)
Enables the user to change dynamically the resizing policy of the underlying hash table...
Definition: set_tpl.h:566
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:767
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:377

◆ 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 425 of file set_tpl.h.

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

◆ 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 455 of file set_tpl.h.

455  {
456  __inside = std::move(from.__inside);
457  return *this;
458  }
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:767

◆ 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 463 of file set_tpl.h.

463  {
464  const HashTable< Key, bool, OtherAlloc >& h2 = s2.__inside;
465 
466  // check whether both sets have the same number of elements
467  if (size() != h2.size()) return false;
468 
469  // check the content of the sets
471  iter != __inside.cend();
472  ++iter) {
473  if (!h2.exists(iter.key())) return false;
474  }
475 
476  return true;
477  }
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:767
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:703

◆ 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 696 of file set_tpl.h.

696  {
697  erase(k);
698  return *this;
699  }
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:658

◆ 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 554 of file set_tpl.h.

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

554  {
555  __inside.resize(new_size);
556 
557  // Note that actually there is no need to update the end iterator as this
558  // one
559  // is not affected by changes within hashtables (adding/deleting elements).
560  // Hence, for speedup, we do not update the end iterator
561  }
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:767
+ 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 577 of file set_tpl.h.

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

577  {
578  return __inside.resizePolicy();
579  }
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:767
+ 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 566 of file set_tpl.h.

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

566  {
567  __inside.setResizePolicy(new_policy);
568 
569  // Note that actually there is no need to update the end iterator as this
570  // one
571  // is not affected by changes within hashtables (adding/deleting elements).
572  // Hence, for speedup, we do not update the end iterator
573  }
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:767
+ 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 703 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::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().

703  {
704  return __inside.size();
705  }
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:767

◆ 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 808 of file set_tpl.h.

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

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 763 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 760 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 761 of file set.h.

Member Data Documentation

◆ __inside


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