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

Representation of a set. More...

#include <agrum/base/core/set.h>

Collaboration diagram for gum::Set< Key >:

Public Types

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

Public Member Functions

template<typename... Args>
INLINE void emplace (Args &&... args)
Constructors / Destructors
 Set (Size capacity=HashTableConst::default_size, bool resize_policy=true)
 Default constructor.
 Set (std::initializer_list< Key > list)
 Initializer list constructor.
 Set (const Set< Key > &aHT)
 Copy constructor.
 Set (Set< Key > &&aHT)
 Move constructor.
 ~Set ()
 Class destructor.
Operators
Set< Key > & operator= (const Set< Key > &from)
 Copy operator.
Set< Key > & operator= (Set< Key > &&from)
 Move operator.
bool operator== (const Set< Key > &s2) const
 Mathematical equality between two sets.
bool operator!= (const Set< Key > &s2) const
 Mathematical inequality between two sets.
const Set< Key > & operator*= (const Set< Key > &s2)
 Intersection update operator.
Set< Key > operator* (const Set< Key > &s2) const
 Intersection operator.
const Set< Key > & operator+= (const Set< Key > &s2)
 Union update operator.
Set< Key > operator+ (const Set< Key > &s2) const
 Union operator.
Set< Key > operator- (const Set< Key > &s2) const
 Disjunction operator.
Set< Key > & operator<< (const Key &k)
 Adds a new element to the set (alias for insert).
Set< Key > & operator<< (Key &&k)
 Adds a new element to the set (alias for insert).
Set< Key > & operator>> (const Key &k)
 Removes an element from the set (alias for erase).
Accessors / Modifiers
void insert (const Key &k)
 Inserts a new element into the set.
void insert (Key &&k)
 Inserts a new element into the set.
template<typename... Args>
void emplace (Args &&... args)
 Emplace a new element in the set.
void erase (const Key &k)
 Erases an element from the set.
Key popFirst ()
 Removes and returns an arbitrary element from the set.
void erase (const iterator_safe &k)
 Erases an element from the set.
void clear ()
 Removes all the elements, if any, from the set.
Size size () const noexcept
 Returns the number of elements in the set.
bool contains (const Key &k) const
 Indicates whether a given elements belong to the set.
bool isStrictSubsetOf (const Set< Key > &s) const
bool isStrictSupersetOf (const Set< Key > &s) const
bool isSubsetOrEqual (const Set< Key > &s) const
bool isSupersetOrEqual (const Set< Key > &s) const
bool exists (const Key &k) const
 Indicates whether a given elements belong to the set.
bool empty () const noexcept
 Indicates whether the set is the empty set.
std::string toString () const
 Prints the content of the set.
Iterators
iterator_safe beginSafe () const
 The usual safe begin iterator to parse the set.
const_iterator_safe cbeginSafe () const
 The usual safe begin iterator to parse the set.
const iterator_safeendSafe () const noexcept
 The usual safe end iterator to parse the set.
const const_iterator_safecendSafe () const noexcept
 The usual safe end iterator to parse the set.
iterator begin () const
 The usual unsafe begin iterator to parse the set.
const_iterator cbegin () const
 The usual unsafe begin iterator to parse the set.
const iteratorend () const noexcept
 The usual unsafe end iterator to parse the set.
const const_iteratorcend () const noexcept
 The usual unsafe end iterator to parse the set.
Fine tuning
Size capacity () const
 Returns the capacity of the underlying hash table containing the set.
void resize (Size new_capacity)
 Changes the size of the underlying hash table containing the set.
void setResizePolicy (const bool new_policy)
 Enables the user to change dynamically the resizing policy of the underlying hash table.
bool resizePolicy () const
 Returns the current resizing policy of the underlying hash table.
Mapper
template<typename NewKey>
HashTable< Key, NewKey > hashMap (NewKey(*f)(const Key &), Size capacity=0) const
 Creates a hashtable of NewKey from the set.
template<typename NewKey>
HashTable< Key, NewKey > hashMap (const NewKey &val, Size size=0) const
 Creates a hash table of NewKey from the set.
template<typename NewKey>
List< NewKey > listMap (NewKey(*f)(const Key &)) const
 A method to create a List of NewKey from the set.

Private Member Functions

 Set (const HashTable< Key, bool > &h)
 Convert a hash table into a set of keys.

Private Attributes

HashTable< Key, bool_inside_
 A set of X's is actually a hash table whose keys are the X's.

Friends

class SetIterator< Key >
 Friends to speed up access.
class SetIteratorSafe< Key >
 Friends to speed up access.

Detailed Description

template<typename Key>
class gum::Set< Key >

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
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";
iterator begin() const
The usual unsafe begin iterator to parse the set.
Definition set_tpl.h:438
const iterator & end() const noexcept
The usual unsafe end iterator to parse the set.
Definition set_tpl.h:450
Set(Size capacity=HashTableConst::default_size, bool resize_policy=true)
Default constructor.
Definition set_tpl.h:300
SetIterator< Key > iterator
Types for STL compliance.
Definition set.h:142
void erase(const Key &k)
Erases an element from the set.
Definition set_tpl.h:582
Template Parameters
KeyThe elements type.

Definition at line 131 of file set.h.

Member Typedef Documentation

◆ const_iterator

template<typename Key>
using gum::Set< Key >::const_iterator = SetIterator< Key >

Types for STL compliance.

Definition at line 143 of file set.h.

◆ const_iterator_safe

template<typename Key>
using gum::Set< Key >::const_iterator_safe = SetIteratorSafe< Key >

Types for STL compliance.

Definition at line 145 of file set.h.

◆ const_pointer

template<typename Key>
using gum::Set< Key >::const_pointer = const Key*

Types for STL compliance.

Definition at line 139 of file set.h.

◆ const_reference

template<typename Key>
using gum::Set< Key >::const_reference = const Key&

Types for STL compliance.

Definition at line 137 of file set.h.

◆ difference_type

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

Types for STL compliance.

Definition at line 141 of file set.h.

◆ iterator

template<typename Key>
using gum::Set< Key >::iterator = SetIterator< Key >

Types for STL compliance.

Definition at line 142 of file set.h.

◆ iterator_safe

template<typename Key>
using gum::Set< Key >::iterator_safe = SetIteratorSafe< Key >

Types for STL compliance.

Definition at line 144 of file set.h.

◆ pointer

template<typename Key>
using gum::Set< Key >::pointer = Key*

Types for STL compliance.

Definition at line 138 of file set.h.

◆ reference

template<typename Key>
using gum::Set< Key >::reference = Key&

Types for STL compliance.

Definition at line 136 of file set.h.

◆ size_type

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

Types for STL compliance.

Definition at line 140 of file set.h.

◆ value_type

template<typename Key>
using gum::Set< Key >::value_type = Key

Types for STL compliance.

Definition at line 135 of file set.h.

Constructor & Destructor Documentation

◆ Set() [1/5]

template<typename Key>
INLINE gum::Set< Key >::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 300 of file set_tpl.h.

300 :
301 // create the hash table without key uniqueness policy (as we will
302 // check
303 // ourselves the uniqueness of Keys before inserting new elements)
306 }
Representation of a set.
Definition set.h:131
HashTable< Key, bool > _inside_
A set of X's is actually a hash table whose keys are the X's.
Definition set.h:558
Size capacity() const
Returns the capacity of the underlying hash table containing the set.
Definition set_tpl.h:462

References Set(), _inside_, and capacity().

Referenced by Set(), Set(), Set(), Set(), isStrictSubsetOf(), isStrictSupersetOf(), isSubsetOrEqual(), isSupersetOrEqual(), operator!=(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator<<(), operator<<(), operator=(), operator=(), operator==(), and operator>>().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Set() [2/5]

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

Initializer list constructor.

Parameters
listThe initializer list.

Definition at line 310 of file set_tpl.h.

310 :
311 _inside_(Size(list.size()) / 2, true, false) {
313 for (const auto& elt: list) {
314 insert(elt);
315 }
316 }
Size size() const noexcept
Returns the number of elements in the set.
Definition set_tpl.h:636
void insert(const Key &k)
Inserts a new element into the set.
Definition set_tpl.h:539

References Set(), _inside_, insert(), and size().

Here is the call graph for this function:

◆ Set() [3/5]

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

Copy constructor.

Parameters
aHTThe gum::Set to copy.

Definition at line 320 of file set_tpl.h.

320 : _inside_(s._inside_) {
322 }

References Set(), and _inside_.

Here is the call graph for this function:

◆ Set() [4/5]

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

Move constructor.

Parameters
aHTThe gum::Set to move.

Definition at line 326 of file set_tpl.h.

328 }

References Set(), and _inside_.

Here is the call graph for this function:

◆ ~Set()

template<typename Key>
gum::Set< Key >::~Set ( )

Class destructor.

◆ Set() [5/5]

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

Convert a hash table into a set of keys.

Member Function Documentation

◆ begin()

template<typename Key>
INLINE Set< Key >::iterator gum::Set< Key >::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 438 of file set_tpl.h.

438 {
439 return SetIterator< Key >{*this};
440 }
friend class SetIterator< Key >
Friends to speed up access.
Definition set.h:553

References SetIterator< Key >.

Referenced by gum::StaticTriangulation::_computeMaxPrimeMergings_(), gum::MeekRules::_orientDoubleHeadedArcs_(), gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), gum::StaticTriangulation::_triangulate_(), gum::ArcGraphPart::ancestors(), gum::BarrenNodesFinder::barrenNodes(), gum::MixedGraph::chainComponent(), gum::ArcGraphPart::descendants(), gum::prm::eliminateNode(), gum::EdgeGraphPart::hasUndirectedPath(), gum::EdgeGraphPart::hasUndirectedPath(), gum::EdgeGraphPart::hasUndirectedPath(), gum::DAG::moralizedAncestralGraph(), gum::learning::Miic::orientDoubleHeadedArcs_(), popFirst(), gum::prm::StructuredInference< GUM_SCALAR >::posterior_(), and gum::learning::SimpleMiic::propagatesOrientationInChainOfRemainingEdges_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ beginSafe()

template<typename Key>
INLINE Set< Key >::iterator_safe gum::Set< Key >::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 414 of file set_tpl.h.

414 {
415 return SetIteratorSafe< Key >{*this};
416 }
friend class SetIteratorSafe< Key >
Friends to speed up access.
Definition set.h:554

References SetIteratorSafe< Key >.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::_updateNodeSet_(), gum::LeafAggregator::addLeaf(), gum::BarrenNodesFinder::barrenNodes(), gum::EdgeGraphPart::eraseNeighbours(), gum::LeafAggregator::removeLeaf(), gum::VariableSelector::select(), gum::EdgeGraphPart::unvirtualizedEraseNeighbours(), gum::IMDDI< AttributeSelection, isScalar >::updateGraph(), and gum::LeafAggregator::updateLeaf().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ capacity()

template<typename Key>
INLINE Size gum::Set< Key >::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 462 of file set_tpl.h.

462 {
463 return _inside_.capacity();
464 }

References _inside_.

Referenced by Set().

Here is the caller graph for this function:

◆ cbegin()

template<typename Key>
INLINE Set< Key >::const_iterator gum::Set< Key >::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 444 of file set_tpl.h.

444 {
445 return SetIterator< Key >{*this};
446 }

References SetIterator< Key >.

Here is the call graph for this function:

◆ cbeginSafe()

template<typename Key>
INLINE Set< Key >::const_iterator_safe gum::Set< Key >::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 420 of file set_tpl.h.

420 {
421 return SetIteratorSafe< Key >{*this};
422 }

References SetIteratorSafe< Key >.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cend()

template<typename Key>
INLINE const Set< Key >::const_iterator & gum::Set< Key >::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 456 of file set_tpl.h.

456 {
457 return *(reinterpret_cast< const SetIterator< Key >* >(_Set_end_));
458 }

References SetIterator< Key >.

Here is the call graph for this function:

◆ cendSafe()

template<typename Key>
INLINE const Set< Key >::const_iterator_safe & gum::Set< Key >::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 432 of file set_tpl.h.

432 {
433 return *(reinterpret_cast< const SetIteratorSafe< Key >* >(_Set_end_safe_));
434 }

References SetIteratorSafe< Key >.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

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

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

Definition at line 338 of file set_tpl.h.

338 {
339 // first we remove all the elements from the hashtable actually containing
340 // the elements of the set. Note that, doing so, all the hashtable iterators
341 // will be updated as well. In turn, this will imply that, whenever an
342 // operation will be performed on a SetIteratorSafe, this will raise an
343 // exception.
344 _inside_.clear();
345
346 // Note that actually there is no need to update the end iterator as this
347 // one
348 // is not affected by changes within hashtables (adding/deleting elements).
349 // Hence, for speedup, we do not update the end iterator
350 }

References _inside_.

Referenced by gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), gum::IMDDI< AttributeSelection, isScalar >::_updateNodeSet_(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::JointTargetedMRFInference< GUM_SCALAR >::jointMutualInformation(), gum::learning::SimpleMiic::propagatesOrientationInChainOfRemainingEdges_(), gum::BayesBall::requisiteNodes(), gum::dSeparationAlgorithm::requisiteNodes(), gum::ITI< AttributeSelection, isScalar >::updateGraph(), and gum::LeafAggregator::updateLeaf().

Here is the caller graph for this function:

◆ contains()

template<typename Key>
INLINE bool gum::Set< Key >::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 497 of file set_tpl.h.

497 {
498 return _inside_.exists(k);
499 }

Referenced by gum::StaticTriangulation::_computeMaxPrimeJunctionTree_(), gum::BayesNet< double >::_copyTensors_(), gum::prm::SVE< GUM_SCALAR >::_initElimOrder_(), gum::prm::SVED< GUM_SCALAR >::_initElimOrder_(), gum::IMarkovRandomField< GUM_SCALAR >::_minimalCondSetVisit_(), gum::DAG::_minimalCondSetVisitDn_(), gum::DAG::_minimalCondSetVisitUp_(), gum::MeekRules::_orientDoubleHeadedArcs_(), gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), gum::ArcGraphPart::ancestors(), gum::Tensor< GUM_SCALAR >::complementVars_(), gum::ArcGraphPart::descendants(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::evidenceImpact(), gum::Tensor< GUM_SCALAR >::fillWith(), gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder(), gum::DiGraph::hasDirectedPath(), gum::Set< const gum::Observation * >::hashMap(), gum::EdgeGraphPart::hasUndirectedPath(), gum::EdgeGraphPart::hasUndirectedPath(), gum::EdgeGraphPart::hasUndirectedPath(), insert(), insert(), isStrictSubsetOf(), gum::learning::SimpleMiic::learnStructure(), gum::DAG::minimalCondSet(), gum::IMarkovRandomField< GUM_SCALAR >::minimalCondSet(), gum::PDAG::moralGraph(), gum::DAG::moralizedAncestralGraph(), gum::learning::Miic::orientDoubleHeadedArcs_(), gum::O3prmBNReader< GUM_SCALAR >::proceed(), gum::learning::SimpleMiic::propagatesOrientationInChainOfRemainingEdges_(), gum::rec_hasMixedReallyOrientedPath(), gum::Estimator< GUM_SCALAR >::setFromBN(), and gum::Estimator< GUM_SCALAR >::setFromLBP().

◆ emplace() [1/2]

template<typename Key>
template<typename... Args>
void gum::Set< Key >::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>
template<typename... Args>
INLINE void gum::Set< Key >::emplace ( Args &&... args)

Definition at line 576 of file set_tpl.h.

576 {
578 }

◆ empty()

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

Indicates whether the set is the empty set.

Returns
Returns true if the set is empty.

Definition at line 642 of file set_tpl.h.

642 {
643 return _inside_.empty();
644 }

References _inside_.

Referenced by gum::MeekRules::_complete_(), gum::prm::SVE< GUM_SCALAR >::_eliminateNodesDownward_(), gum::prm::SVE< GUM_SCALAR >::_initElimOrder_(), gum::prm::SVED< GUM_SCALAR >::_initElimOrder_(), gum::MeekRules::_orientDoubleHeadedArcs_(), gum::MeekRules::_propagates_(), gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), gum::learning::Miic::_propagatingOrientationMiic_(), gum::learning::SimpleMiic::_propagatingOrientationMiic_(), gum::VariableSelector::_removeVar_(), gum::ArcGraphPart::ancestors(), gum::MixedGraph::chainComponent(), gum::ArcGraphPart::descendants(), gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder(), gum::EdgeGraphPart::hasUndirectedPath(), gum::EdgeGraphPart::hasUndirectedPath(), gum::EdgeGraphPart::hasUndirectedPath(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::initialize_(), gum::JointTargetedInference< GUM_SCALAR >::jointPosterior(), gum::JointTargetedMRFInference< GUM_SCALAR >::jointPosterior(), gum::learning::SimpleMiic::learnPDAG(), gum::learning::SimpleMiic::learnStructure(), gum::Tensor< GUM_SCALAR >::maxIn(), gum::Tensor< GUM_SCALAR >::minIn(), gum::DAG::moralizedAncestralGraph(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::msgL_(), gum::learning::Miic::orientDoubleHeadedArcs_(), popFirst(), gum::learning::IBNLearner::prepareMiic_(), gum::Tensor< GUM_SCALAR >::prodIn(), gum::learning::SimpleMiic::propagatesOrientationInChainOfRemainingEdges_(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::refreshLMsPIs_(), gum::prm::PRMFactory< GUM_SCALAR >::startClass(), gum::Tensor< GUM_SCALAR >::sumIn(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateNode_().

◆ end()

template<typename Key>
INLINE const Set< Key >::iterator & gum::Set< Key >::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 450 of file set_tpl.h.

450 {
451 return *(reinterpret_cast< const SetIterator< Key >* >(_Set_end_));
452 }

References SetIterator< Key >.

Referenced by gum::StaticTriangulation::_computeMaxPrimeMergings_(), and gum::StaticTriangulation::_triangulate_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ endSafe()

template<typename Key>
INLINE const Set< Key >::iterator_safe & gum::Set< Key >::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 426 of file set_tpl.h.

426 {
427 return *(reinterpret_cast< const SetIteratorSafe< Key >* >(_Set_end_safe_));
428 }

References SetIteratorSafe< Key >.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::_updateNodeSet_(), gum::LeafAggregator::addLeaf(), gum::BarrenNodesFinder::barrenNodes(), gum::EdgeGraphPart::eraseNeighbours(), gum::LeafAggregator::removeLeaf(), gum::VariableSelector::select(), gum::EdgeGraphPart::unvirtualizedEraseNeighbours(), gum::IMDDI< AttributeSelection, isScalar >::updateGraph(), and gum::LeafAggregator::updateLeaf().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erase() [1/2]

template<typename Key>
INLINE void gum::Set< Key >::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 603 of file set_tpl.h.

603 {
604 // erase the element
605 _inside_.erase(iter._ht_iter_);
606
607 // Note that actually there is no need to update the end iterator as this
608 // one
609 // is not affected by changes within hashtables (adding/deleting elements).
610 // Hence, for speedup, we do not update the end iterator
611 }

References gum::SetIteratorSafe< Key >::_ht_iter_, _inside_, and SetIteratorSafe< Key >.

Here is the call graph for this function:

◆ erase() [2/2]

template<typename Key>
INLINE void gum::Set< Key >::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 582 of file set_tpl.h.

582 {
583 // erase the element (if it exists)
584 _inside_.erase(k);
585
586 // Note that actually there is no need to update the end iterator as this
587 // one
588 // is not affected by changes within hashtables (adding/deleting elements).
589 // Hence, for speedup, we do not update the end iterator
590 }

References _inside_.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), gum::prm::StructuredInference< GUM_SCALAR >::_buildPatternGraph_(), gum::prm::StructuredInference< GUM_SCALAR >::_buildReduceGraph_(), gum::prm::gspan::StrictSearch< GUM_SCALAR >::_elimination_cost_(), gum::prm::SVE< GUM_SCALAR >::_initLiftedNodes_(), gum::prm::SVED< GUM_SCALAR >::_initLiftedNodes_(), gum::MeekRules::_orientDoubleHeadedArcs_(), gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), gum::prm::StructuredInference< GUM_SCALAR >::_removeNode_(), gum::ArcGraphPart::ancestors(), gum::BarrenNodesFinder::barrenNodes(), gum::MixedGraph::chainComponent(), gum::ArcGraphPart::descendants(), gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder(), gum::EdgeGraphPart::hasUndirectedPath(), gum::EdgeGraphPart::hasUndirectedPath(), gum::EdgeGraphPart::hasUndirectedPath(), gum::DAG::moralizedAncestralGraph(), operator>>(), gum::learning::Miic::orientDoubleHeadedArcs_(), popFirst(), gum::learning::SimpleMiic::propagatesOrientationInChainOfRemainingEdges_(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), and gum::ITI< AttributeSelection, isScalar >::updateGraph().

Here is the caller graph for this function:

◆ exists()

template<typename Key>
INLINE bool gum::Set< Key >::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 533 of file set_tpl.h.

533 {
534 return _inside_.exists(k);
535 }

References _inside_.

Referenced by gum::prm::StructuredBayesBall< GUM_SCALAR >::_buildHashKey_(), gum::prm::StructuredInference< GUM_SCALAR >::_buildPatternGraph_(), gum::BinaryJoinTreeConverterDefault::_combinedSize_(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::_connect_(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::_directedPath_(), gum::prm::SVE< GUM_SCALAR >::_eliminateNodes_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodes_(), gum::prm::SVE< GUM_SCALAR >::_eliminateNodesWithEvidence_(), gum::learning::Miic::_existsDirectedPath_(), gum::learning::SimpleMiic::_existsDirectedPath_(), gum::MeekRules::_existsDirectedPath_(), gum::prm::gspan::DFSTree< GUM_SCALAR >::_initialiaze_root_(), gum::prm::SVE< GUM_SCALAR >::_initLiftedNodes_(), gum::prm::SVED< GUM_SCALAR >::_initLiftedNodes_(), gum::prm::StructuredInference< GUM_SCALAR >::_insertNodeInElimLists_(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::_is_connected_(), gum::prm::StructuredInference< GUM_SCALAR >::_reducePattern_(), gum::prm::StructuredInference< GUM_SCALAR >::_removeBarrenNodes_(), gum::prm::StructuredInference< GUM_SCALAR >::_removeNode_(), gum::DAGCycleDetector::_restrictWeightedSet_(), gum::prm::GSpan< GUM_SCALAR >::_sortPatterns_(), gum::prm::SVE< GUM_SCALAR >::_variableElimination_(), gum::BarrenNodesFinder::barrenNodes(), gum::MixedGraph::chainComponent(), gum::PDAG::cSeparation(), gum::DAG::dSeparation(), gum::prm::gspan::DFSTree< GUM_SCALAR >::growPattern(), gum::DAGmodel::hasSameStructure(), gum::MarkovBlanket::hasSameStructure(), gum::UGmodel::hasSameStructure(), gum::StructuredPlaner< double >::initialize(), gum::Tensor< GUM_SCALAR >::maxOut(), gum::Tensor< GUM_SCALAR >::minOut(), gum::Tensor< GUM_SCALAR >::prodOut(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), gum::BayesBall::requisiteNodes(), gum::dSeparationAlgorithm::requisiteNodes(), gum::Tensor< GUM_SCALAR >::sumOut(), gum::MixedGraph::toDot(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateNode_().

◆ hashMap() [1/2]

template<typename Key>
template<typename NewKey>
HashTable< Key, NewKey > gum::Set< Key >::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 774 of file set_tpl.h.

774 {
775 // determine the proper size of the hashtable
776 // by default, the size of the table is set so that the table does not take
777 // too much space while allowing to add a few elements without resizing
778 if (size == 0) size = std::max(Size(2), _inside_.size() / 2);
779
780 // create a new table
782
783 // fill the new hash table
785 ++iter) {
786 table.insert(iter.key(), val);
787 }
788
789 return table;
790 }

References _inside_, gum::HashTable< Key, Val >::insert(), and size().

Here is the call graph for this function:

◆ hashMap() [2/2]

template<typename Key>
template<typename NewKey>
HashTable< Key, NewKey > gum::Set< Key >::hashMap ( NewKey(* )(const Key &),
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 753 of file set_tpl.h.

753 {
754 // determine the proper size of the hashtable
755 // by default, the size of the table is set so that the table does not take
756 // too much space while allowing to add a few elements without resizing
757 if (size == 0) size = std::max(Size(2), _inside_.size() / 2);
758
759 // create a new table
761
762 // fill the new hash table
764 ++iter) {
765 table.insert(iter.key(), f(iter.key()));
766 }
767
768 return table;
769 }

References size().

Here is the call graph for this function:

◆ insert() [1/2]

template<typename Key>
INLINE void gum::Set< Key >::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 539 of file set_tpl.h.

539 {
540 // WARNING: we shall always test whether k already belongs to the set before
541 // trying to insert it because we set _inside_'s key uniqueness policy to
542 // false
543 if (!contains(k)) {
544 // insert the element
545 _inside_.insert(k, true);
546
547 // Note that actually there is no need to update the end iterator as this
548 // one
549 // is not affected by changes within hashtables (adding/deleting
550 // elements).
551 // Hence, for speedup, we do not update the end iterator
552 }
553 }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition set_tpl.h:497

References _inside_, and contains().

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), Set(), gum::prm::StructuredInference< GUM_SCALAR >::_addEdgesInReducedGraph_(), gum::prm::gspan::StrictSearch< GUM_SCALAR >::_buildPatternGraph_(), gum::prm::StructuredInference< GUM_SCALAR >::_buildPatternGraph_(), gum::prm::StructuredInference< GUM_SCALAR >::_buildReduceGraph_(), gum::StaticTriangulation::_computeRecursiveThinning_(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::_connect_(), gum::BayesNet< double >::_copyTensors_(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::_directedPath_(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::_directedPath_(), gum::MCBayesNetGenerator< GUM_SCALAR, SimpleCPTGenerator, SimpleCPTDisturber >::_directedPath_(), gum::prm::SVE< GUM_SCALAR >::_eliminateDelayedVariables_(), gum::prm::SVE< GUM_SCALAR >::_eliminateNodes_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodes_(), gum::prm::SVE< GUM_SCALAR >::_eliminateNodesDownward_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodesDownward_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodesUpward_(), gum::prm::SVE< GUM_SCALAR >::_eliminateNodesWithEvidence_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodesWithEvidence_(), gum::prm::gspan::StrictSearch< GUM_SCALAR >::_elimination_cost_(), gum::learning::Miic::_existsDirectedPath_(), gum::learning::SimpleMiic::_existsDirectedPath_(), gum::MeekRules::_existsDirectedPath_(), gum::prm::StructuredBayesBall< GUM_SCALAR >::_fillMaps_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClasses_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClasses_(), gum::prm::SVE< GUM_SCALAR >::_initElimOrder_(), gum::prm::SVED< GUM_SCALAR >::_initElimOrder_(), gum::prm::gspan::DFSTree< GUM_SCALAR >::_initialiaze_root_(), gum::prm::SVE< GUM_SCALAR >::_initLiftedNodes_(), gum::prm::SVED< GUM_SCALAR >::_initLiftedNodes_(), gum::prm::SVED< GUM_SCALAR >::_initReqSets_(), gum::prm::SVE< GUM_SCALAR >::_insertEvidence_(), gum::prm::SVED< GUM_SCALAR >::_insertEvidence_(), gum::prm::SVE< GUM_SCALAR >::_insertLiftedNodes_(), gum::prm::SVED< GUM_SCALAR >::_insertLiftedNodes_(), gum::prm::StructuredInference< GUM_SCALAR >::_insertNodeInElimLists_(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::_is_connected_(), gum::OrderedEliminationSequenceStrategy::_isOrderNeeded_(), gum::MeekRules::_orientDoubleHeadedArcs_(), gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), 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::prm::StructuredInference< GUM_SCALAR >::_translatePotSet_(), gum::StaticTriangulation::_triangulate_(), gum::prm::SVE< GUM_SCALAR >::_variableElimination_(), gum::LeafAggregator::addLeaf(), gum::ArcGraphPart::ancestors(), gum::NodeGraphPart::asNodeSet(), gum::BarrenNodesFinder::barrenNodes(), gum::BarrenNodesFinder::barrenNodes(), gum::BarrenNodesFinder::barrenTensors(), gum::MixedGraph::chainComponent(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::Tensor< GUM_SCALAR >::complementVars_(), gum::PDAG::cSeparation(), gum::ArcGraphPart::descendants(), gum::DAG::dSeparation(), gum::prm::eliminateNode(), gum::Tensor< GUM_SCALAR >::fillWith(), gum::Tensor< GUM_SCALAR >::findAll(), gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder(), gum::prm::gspan::DFSTree< GUM_SCALAR >::growPattern(), gum::DAGCycleDetector::hasCycleFromModifications(), gum::DiGraph::hasDirectedPath(), gum::EdgeGraphPart::hasUndirectedPath(), gum::EdgeGraphPart::hasUndirectedPath(), gum::EdgeGraphPart::hasUndirectedPath(), gum::IBayesNet< double >::ids(), gum::FMDPLearner< VariableAttributeSelection, RewardAttributeSelection, LearnerSelection >::initialize(), gum::PartialOrderedEliminationSequenceStrategy::isPartialOrderNeeded_(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::JointTargetedMRFInference< GUM_SCALAR >::jointMutualInformation(), gum::JointTargetedMRFInference< GUM_SCALAR >::jointPosterior(), gum::DecisionTensor< GUM_SCALAR >::marginalization(), gum::PDAG::moralGraph(), gum::DAG::moralizedAncestralGraph(), gum::GraphicalModel::nodeset(), operator<<(), operator<<(), gum::IMarkovRandomField< GUM_SCALAR >::operator==(), gum::learning::Miic::orientDoubleHeadedArcs_(), gum::prm::StructuredInference< GUM_SCALAR >::posterior_(), gum::prm::SVE< GUM_SCALAR >::posterior_(), gum::prm::SVED< GUM_SCALAR >::posterior_(), gum::O3prmBNReader< GUM_SCALAR >::proceed(), gum::learning::SimpleMiic::propagatesOrientationInChainOfRemainingEdges_(), gum::rec_hasMixedReallyOrientedPath(), gum::dSeparationAlgorithm::relevantTensors(), gum::BayesBall::requisiteNodes(), gum::dSeparationAlgorithm::requisiteNodes(), gum::prm::PRMFactory< GUM_SCALAR >::startClass(), gum::MixedGraph::toDot(), gum::IMDDI< AttributeSelection, isScalar >::updateGraph(), gum::ITI< AttributeSelection, isScalar >::updateGraph(), and gum::GraphicalModel::variables().

Here is the call graph for this function:

◆ insert() [2/2]

template<typename Key>
INLINE void gum::Set< Key >::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 557 of file set_tpl.h.

557 {
558 // WARNING: we shall always test whether k already belongs to the set before
559 // trying to insert it because we set _inside_'s key uniqueness policy to
560 // false
561 if (!contains(k)) {
562 // insert the element
563 _inside_.insert(std::move(k), true);
564
565 // Note that actually there is no need to update the end iterator as this
566 // one
567 // is not affected by changes within hashtables (adding/deleting
568 // elements).
569 // Hence, for speedup, we do not update the end iterator
570 }
571 }

References _inside_, and contains().

Here is the call graph for this function:

◆ isStrictSubsetOf()

template<typename Key>
INLINE bool gum::Set< Key >::isStrictSubsetOf ( const Set< Key > & s) const
Returns
Returns true if *this is a proper subset of s

Definition at line 502 of file set_tpl.h.

502 {
503 if (this->size() >= s.size()) { return false; }
504
505 for (const auto& elt: *this) {
506 if (!s.contains(elt)) { return false; }
507 }
508 return true;
509 }

References Set(), contains(), and size().

Referenced by isStrictSupersetOf(), and gum::JointTargetedInference< GUM_SCALAR >::jointPosterior().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isStrictSupersetOf()

template<typename Key>
INLINE bool gum::Set< Key >::isStrictSupersetOf ( const Set< Key > & s) const
Returns
Returns true if *this is a proper superset of s

Definition at line 512 of file set_tpl.h.

512 {
513 return s.isStrictSubsetOf(*this);
514 }
bool isStrictSubsetOf(const Set< Key > &s) const
Definition set_tpl.h:502

References Set(), and isStrictSubsetOf().

Here is the call graph for this function:

◆ isSubsetOrEqual()

template<typename Key>
INLINE bool gum::Set< Key >::isSubsetOrEqual ( const Set< Key > & s) const
Returns
Returns true if *this is a subset of s (or equal to s)

Definition at line 517 of file set_tpl.h.

517 {
518 if (this->size() > s.size()) { return false; }
519
520 for (const auto& elt: *this) {
521 if (!s.contains(elt)) { return false; }
522 }
523 return true;
524 }

References Set(), and size().

Referenced by isSupersetOrEqual(), and gum::JointTargetedMRFInference< GUM_SCALAR >::superForJointComputable_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isSupersetOrEqual()

template<typename Key>
INLINE bool gum::Set< Key >::isSupersetOrEqual ( const Set< Key > & s) const
Returns
Returns true if *this is a superset of s (or equal to s)

Definition at line 527 of file set_tpl.h.

527 {
528 return s.isSubsetOrEqual(*this);
529 }
bool isSubsetOrEqual(const Set< Key > &s) const
Definition set_tpl.h:517

References Set(), and isSubsetOrEqual().

Here is the call graph for this function:

◆ listMap()

template<typename Key>
template<typename NewKey>
List< NewKey > gum::Set< Key >::listMap ( NewKey(* )(const Key &)) 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 795 of file set_tpl.h.

795 {
796 // create a new list
798
799 // fill the new list
801 ++iter) {
802 list.pushBack(f(iter.key()));
803 }
804
805 return list;
806 }

References _inside_, and gum::List< Val >::pushBack().

Here is the call graph for this function:

◆ operator!=()

template<typename Key>
INLINE bool gum::Set< Key >::operator!= ( const Set< Key > & s2) const

Mathematical inequality between two sets.

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

Definition at line 408 of file set_tpl.h.

408 {
409 return !(operator==(s2));
410 }
bool operator==(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:243

References Set(), and gum::operator==().

Here is the call graph for this function:

◆ operator*()

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

Intersection operator.

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

Definition at line 648 of file set_tpl.h.

648 {
652
653 if (size() < h2.size()) {
655 ++iter) {
656 if (h2.exists(iter.key())) h_r.insert(iter.key(), true);
657 }
658 } else {
660 if (_inside_.exists(iter.key())) h_r.insert(iter.key(), true);
661 }
662 }
663
664 return res;
665 }
const const_iterator & cend() const noexcept
The usual unsafe end iterator to parse the set.
Definition set_tpl.h:456
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition set_tpl.h:533
const_iterator cbegin() const
The usual unsafe begin iterator to parse the set.
Definition set_tpl.h:444

References Set(), _inside_, gum::HashTable< Key, Val >::cbegin(), gum::HashTable< Key, Val >::cend(), gum::HashTable< Key, Val >::exists(), gum::HashTable< Key, Val >::insert(), gum::HashTable< Key, Val >::size(), and size().

Here is the call graph for this function:

◆ operator*=()

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

Intersection update operator.

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

Definition at line 669 of file set_tpl.h.

669 {
670 if (&s2 != this) {
672 for (auto iter = _inside_.beginSafe(); iter != _inside_.endSafe(); ++iter) {
673 if (!h2.exists(iter.key())) _inside_.erase(iter);
674 }
675 }
676
677 return *this;
678 }

References Set(), _inside_, and gum::HashTable< Key, Val >::exists().

Here is the call graph for this function:

◆ operator+()

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

Union operator.

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

Definition at line 694 of file set_tpl.h.

694 {
695 Set< Key > res = *this;
698
700 if (!h_r.exists(iter.key())) h_r.insert(iter.key(), true);
701 }
702
703 return res;
704 }

References Set(), _inside_, gum::HashTable< Key, Val >::cbegin(), gum::HashTable< Key, Val >::cend(), gum::HashTable< Key, Val >::exists(), and gum::HashTable< Key, Val >::insert().

Here is the call graph for this function:

◆ operator+=()

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

Union update operator.

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

Definition at line 682 of file set_tpl.h.

682 {
683 if (&s2 != this) {
684 for (auto pair: s2._inside_) {
685 if (!_inside_.exists(pair.first)) _inside_.insert(pair.first, true);
686 }
687 }
688
689 return *this;
690 }

References Set(), and _inside_.

Here is the call graph for this function:

◆ operator-()

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

Disjunction operator.

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

708 {
712
714 ++iter)
715 if (!h2.exists(iter.key())) h_r.insert(iter.key(), true);
716
717 return res;
718 }

References Set().

Here is the call graph for this function:

◆ operator<<() [1/2]

template<typename Key>
INLINE Set< Key > & gum::Set< Key >::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 615 of file set_tpl.h.

615 {
616 insert(k);
617 return *this;
618 }

References Set(), and insert().

Here is the call graph for this function:

◆ operator<<() [2/2]

template<typename Key>
INLINE Set< Key > & gum::Set< Key >::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 622 of file set_tpl.h.

622 {
624 return *this;
625 }

References Set(), and insert().

Here is the call graph for this function:

◆ operator=() [1/2]

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

Copy operator.

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

Definition at line 354 of file set_tpl.h.

354 {
355 // avoid self assignment
356 if (&s != this) {
357 // remove the old content of the set. Actually, we remove all the elements
358 // from the underlying hashtable. Note that, doing so, all the hashtable
359 // iterators will be updated as well. In turn, this will imply that,
360 // whenever
361 // an operation will be performed on a SetIteratorSafe, this will raise an
362 // exception.
363 clear();
364
365 // prepare the set for its new data
366 resize(s.capacity());
368
369 // copy the set
371
372 // Note that actually there is no need to update the end iterator as this
373 // one
374 // is not affected by changes within hashtables (adding/deleting
375 // elements).
376 // Hence, for speedup, we do not update the end iterator
377 }
378
379 return *this;
380 }
bool resizePolicy() const
Returns the current resizing policy of the underlying hash table.
Definition set_tpl.h:491
void setResizePolicy(const bool new_policy)
Enables the user to change dynamically the resizing policy of the underlying hash table.
Definition set_tpl.h:480
void resize(Size new_capacity)
Changes the size of the underlying hash table containing the set.
Definition set_tpl.h:468
void clear()
Removes all the elements, if any, from the set.
Definition set_tpl.h:338

References Set().

Here is the call graph for this function:

◆ operator=() [2/2]

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

Move operator.

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

Definition at line 384 of file set_tpl.h.

384 {
386 return *this;
387 }

References Set(), and _inside_.

Here is the call graph for this function:

◆ operator==()

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

Mathematical equality between two sets.

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

Definition at line 391 of file set_tpl.h.

391 {
393
394 // check whether both sets have the same number of elements
395 if (size() != h2.size()) return false;
396
397 // check the content of the sets
399 ++iter) {
400 if (!h2.exists(iter.key())) return false;
401 }
402
403 return true;
404 }

References Set().

Here is the call graph for this function:

◆ operator>>()

template<typename Key>
INLINE Set< Key > & gum::Set< Key >::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 629 of file set_tpl.h.

629 {
630 erase(k);
631 return *this;
632 }

References Set(), and erase().

Here is the call graph for this function:

◆ popFirst()

template<typename Key>
Key gum::Set< Key >::popFirst ( )

Removes and returns an arbitrary element from the set.

Exceptions
NotFoundRaised if the set is empty.
Returns
The removed element.

Definition at line 593 of file set_tpl.h.

593 {
594 if (this->empty()) { GUM_ERROR(NotFound, "Cannot popFirst from an empty set"); }
595
596 auto key = *this->begin();
597 this->erase(key);
598 return key;
599 }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition set_tpl.h:642
#define GUM_ERROR(type, msg)
Definition exceptions.h:72

References begin(), empty(), erase(), and GUM_ERROR.

Here is the call graph for this function:

◆ resize()

template<typename Key>
INLINE void gum::Set< Key >::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 468 of file set_tpl.h.

468 {
469 _inside_.resize(new_size);
470
471 // Note that actually there is no need to update the end iterator as this
472 // one
473 // is not affected by changes within hashtables (adding/deleting elements).
474 // Hence, for speedup, we do not update the end iterator
475 }

References _inside_.

Referenced by gum::StaticTriangulation::_triangulate_().

Here is the caller graph for this function:

◆ resizePolicy()

template<typename Key>
INLINE bool gum::Set< Key >::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 491 of file set_tpl.h.

491 {
492 return _inside_.resizePolicy();
493 }

References _inside_.

◆ setResizePolicy()

template<typename Key>
INLINE void gum::Set< Key >::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 tensorly 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 480 of file set_tpl.h.

480 {
481 _inside_.setResizePolicy(new_policy);
482
483 // Note that actually there is no need to update the end iterator as this
484 // one
485 // is not affected by changes within hashtables (adding/deleting elements).
486 // Hence, for speedup, we do not update the end iterator
487 }

References _inside_.

◆ size()

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

Returns the number of elements in the set.

Returns
Returns the number of elements in the set.

Definition at line 636 of file set_tpl.h.

636 {
637 return _inside_.size();
638 }

References _inside_.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), Set(), gum::BinaryJoinTreeConverterDefault::_convertClique_(), gum::MeekRules::_critereMinParents_(), gum::prm::StructuredInference< GUM_SCALAR >::_eliminateObservedNodes_(), gum::prm::StructuredInference< GUM_SCALAR >::_eliminateObservedNodesInSource_(), gum::prm::gspan::StrictSearch< GUM_SCALAR >::_elimination_cost_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::prm::SVE< GUM_SCALAR >::_initLiftedNodes_(), gum::prm::SVED< GUM_SCALAR >::_initLiftedNodes_(), gum::prm::StructuredInference< GUM_SCALAR >::_insertNodeInElimLists_(), gum::OrderedEliminationSequenceStrategy::_isOrderNeeded_(), gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_(), gum::prm::StructuredInference< GUM_SCALAR >::_reducePattern_(), gum::StaticTriangulation::_triangulate_(), gum::AggregatorDecomposition< GUM_SCALAR >::addDepthLayer_(), gum::BarrenNodesFinder::barrenNodes(), gum::AggregatorDecomposition< GUM_SCALAR >::decomposeAggregator_(), gum::prm::eliminateNode(), gum::StaticTriangulation::fillIns(), hashMap(), hashMap(), gum::learning::Miic::initiation_(), gum::learning::SimpleMiic::initiation_(), gum::prm::PRMClassElementContainer< double >::isInputNode(), gum::learning::Miic::isMaxIndegree_(), gum::PartialOrderedEliminationSequenceStrategy::isPartialOrderNeeded_(), isStrictSubsetOf(), isSubsetOrEqual(), gum::Tensor< GUM_SCALAR >::maxOut(), gum::Tensor< GUM_SCALAR >::minOut(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::msgL_(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::msgP_(), operator*(), gum::prm::StructuredInference< GUM_SCALAR >::posterior_(), gum::Tensor< GUM_SCALAR >::prodOut(), gum::learning::SimpleMiic::propagatesOrientationInChainOfRemainingEdges_(), gum::DAGCycleDetector::setDAG(), gum::Tensor< GUM_SCALAR >::sumOut(), gum::StaticTriangulation::triangulatedGraph(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateNode_().

◆ toString()

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

Prints the content of the set.

Returns
Returns the content of the set.

Definition at line 722 of file set_tpl.h.

722 {
724 bool first = true;
725 out << "{";
726
727 for (iterator iter = begin(); iter != end(); ++iter) {
728 if (first) {
729 out << *iter;
730 first = false;
731 } else {
732 out << "," << *iter;
733 }
734 }
735
736 out << "}";
737
739 out >> res;
740 return res;
741 }

Referenced by gum::operator<<().

Here is the caller graph for this function:

◆ SetIterator< Key >

template<typename Key>
friend class SetIterator< Key >
friend

Friends to speed up access.

Definition at line 546 of file set.h.

Referenced by begin(), cbegin(), cend(), and end().

◆ SetIteratorSafe< Key >

template<typename Key>
friend class SetIteratorSafe< Key >
friend

Friends to speed up access.

Definition at line 546 of file set.h.

Referenced by beginSafe(), cbeginSafe(), cendSafe(), endSafe(), and erase().

Member Data Documentation

◆ _inside_

template<typename Key>
HashTable< Key, bool > gum::Set< Key >::_inside_
private

A set of X's is actually a hash table whose keys are the X's.

Definition at line 558 of file set.h.

Referenced by Set(), Set(), Set(), Set(), capacity(), clear(), empty(), erase(), erase(), exists(), hashMap(), insert(), insert(), listMap(), operator*(), operator*=(), operator+(), operator+=(), operator=(), resize(), resizePolicy(), setResizePolicy(), and size().


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