aGrUM  0.16.0
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 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 319 of file set_tpl.h.

319  :
320  // create the hash table without key uniqueness policy (as we will
321  // check
322  // ourselves the uniqueness of Keys before inserting new elements)
323  __inside(capacity, resize_policy, false) {
324  GUM_CONSTRUCTOR(Set);
325 
326  // make sure the end() iterator is constructed properly
327  endSafe4Statics();
328  end4Statics();
329  }
Size capacity() const
Returns the capacity of the underlying hash table containing the set.
Definition: set_tpl.h:546
static const iterator & end4Statics()
Returns the end iterator for other classes&#39; statics (read the detailed description of this method)...
Definition: set_tpl.h:305
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:291
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 333 of file set_tpl.h.

333  :
334  __inside(Size(list.size()) / 2, true, false) {
335  GUM_CONSTRUCTOR(Set);
336  for (const auto& elt : list) {
337  insert(elt);
338  }
339 
340  // make sure the end() iterator is constructed properly
341  endSafe4Statics();
342  end4Statics();
343  }
static const iterator & end4Statics()
Returns the end iterator for other classes&#39; statics (read the detailed description of this method)...
Definition: set_tpl.h:305
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:291
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:613

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

347  :
348  __inside(s.__inside) {
349  GUM_CONS_CPY(Set);
350  }
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 362 of file set_tpl.h.

362  :
363  __inside(std::move(s.__inside)) {
364  GUM_CONS_MOV(Set);
365  }
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 355 of file set_tpl.h.

355  :
356  __inside(s.__inside) {
357  GUM_CONS_CPY(Set);
358  }
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 517 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().

517  {
518  return SetIterator< Key >{*this};
519  }
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 488 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().

488  {
489  return SetIteratorSafe< Key >{*this};
490  }
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 546 of file set_tpl.h.

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

546  {
547  return __inside.capacity();
548  }
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 524 of file set_tpl.h.

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

524  {
525  return SetIterator< Key >{*this};
526  }
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 495 of file set_tpl.h.

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

495  {
496  return SetIteratorSafe< Key >{*this};
497  }
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 539 of file set_tpl.h.

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

539  {
540  return *(reinterpret_cast< const SetIterator< Key >* >(
541  SetIteratorStaticEnd::__SetIterEnd));
542  }
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 510 of file set_tpl.h.

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

510  {
511  return *(reinterpret_cast< const SetIteratorSafe< Key >* >(
512  SetIteratorStaticEnd::__SetIterEndSafe));
513  }
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 375 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().

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

312  {
313  return *(reinterpret_cast< const SetIterator< Key >* >(
314  SetIteratorStaticEnd::constEnd4Statics()));
315  }
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 298 of file set_tpl.h.

298  {
299  return *(reinterpret_cast< const SetIteratorSafe< Key >* >(
300  SetIteratorStaticEnd::constEndSafe4Statics()));
301  }
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 581 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().

581  {
582  return __inside.exists(k);
583  }
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 650 of file set_tpl.h.

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

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

707  {
708  return __inside.empty();
709  }
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 530 of file set_tpl.h.

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

531  {
532  return *(reinterpret_cast< const SetIterator< Key >* >(
533  SetIteratorStaticEnd::__SetIterEnd));
534  }
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 305 of file set_tpl.h.

305  {
306  return *(reinterpret_cast< const SetIterator< Key >* >(
307  SetIteratorStaticEnd::end4Statics()));
308  }
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 502 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().

502  {
503  return *(reinterpret_cast< const SetIteratorSafe< Key >* >(
504  SetIteratorStaticEnd::__SetIterEndSafe));
505  }
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 291 of file set_tpl.h.

291  {
292  return *(reinterpret_cast< const SetIteratorSafe< Key >* >(
293  SetIteratorStaticEnd::endSafe4Statics()));
294  }
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 656 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().

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

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

607  {
608  return __inside.exists(k);
609  }
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 838 of file set_tpl.h.

838  {
839  // determine the proper size of the hashtable
840  // by default, the size of the table is set so that the table does not take
841  // too much space while allowing to add a few elements without resizing
842  if (size == 0) size = std::max(Size(2), __inside.size() / 2);
843 
844  // create a new table
845  HashTable< Key, NewKey, NewAlloc > table(size);
846 
847  // fill the new hash table
849  iter != __inside.cend();
850  ++iter) {
851  table.insert(iter.key(), f(iter.key()));
852  }
853 
854  return table;
855  }
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:701

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

861  {
862  // determine the proper size of the hashtable
863  // by default, the size of the table is set so that the table does not take
864  // too much space while allowing to add a few elements without resizing
865  if (size == 0) size = std::max(Size(2), __inside.size() / 2);
866 
867  // create a new table
868  HashTable< Key, NewKey, NewAlloc > table(size);
869 
870  // fill the new hash table
872  iter != __inside.cend();
873  ++iter) {
874  table.insert(iter.key(), val);
875  }
876 
877  return table;
878  }
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:701

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

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

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

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

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

601  {
602  return s.isSubsetOf(*this);
603  }

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

884  {
885  // create a new list
886  List< NewKey, NewAlloc > list;
887 
888  // fill the new list
890  iter != __inside.cend();
891  ++iter) {
892  list.pushBack(f(iter.key()));
893  }
894 
895  return list;
896  }
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 481 of file set_tpl.h.

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

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

715  {
716  Set< Key, Alloc > res;
717  const HashTable< Key, bool, OtherAlloc >& h2 = s2.__inside;
718  HashTable< Key, bool, Alloc >& h_r = res.__inside;
719 
720  if (size() < h2.size()) {
722  iter != __inside.cend();
723  ++iter) {
724  if (h2.exists(iter.key())) h_r.insert(iter.key(), true);
725  }
726  } else {
727  for (HashTableConstIterator< Key, bool > iter = h2.cbegin();
728  iter != h2.cend();
729  ++iter) {
730  if (__inside.exists(iter.key())) h_r.insert(iter.key(), true);
731  }
732  }
733 
734  return res;
735  }
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:701
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 742 of file set_tpl.h.

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

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

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

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

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

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

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

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

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

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

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

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

453  {
454  __inside = std::move(from.__inside);
455  return *this;
456  }
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 461 of file set_tpl.h.

461  {
462  const HashTable< Key, bool, OtherAlloc >& h2 = s2.__inside;
463 
464  // check whether both sets have the same number of elements
465  if (size() != h2.size()) return false;
466 
467  // check the content of the sets
469  iter != __inside.cend();
470  ++iter) {
471  if (!h2.exists(iter.key())) return false;
472  }
473 
474  return true;
475  }
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:701

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

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

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

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

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

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

575  {
576  return __inside.resizePolicy();
577  }
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 564 of file set_tpl.h.

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

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

701  {
702  return __inside.size();
703  }
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 806 of file set_tpl.h.

806  {
807  std::stringstream out;
808  bool first = true;
809  out << "{";
810 
811  for (iterator iter = begin(); iter != end(); ++iter) {
812  if (first) {
813  out << *iter;
814  first = false;
815  } else {
816  out << "," << *iter;
817  }
818  }
819 
820  out << "}";
821 
822  std::string res;
823  out >> res;
824  return res;
825  }
const iterator & end() const noexcept
The usual unsafe end iterator to parse the set.
Definition: set_tpl.h:530
iterator begin() const
The usual unsafe begin iterator to parse the set.
Definition: set_tpl.h:517
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: