aGrUM 3.1.1
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

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) noexcept
 Move constructor.
 ~Set ()
 Class destructor.
Operators
Set< Key > & operator= (const Set< Key > &from)
 Copy operator.
Set< Key > & operator= (Set< Key > &&from) noexcept
 Move operator.
bool operator== (const Set< Key > &s2) const
 Mathematical equality 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.
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.

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.
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.
static const iterator_safeendSafe () noexcept
 The usual safe end iterator to parse the set.
static const const_iterator_safecendSafe () noexcept
 The usual safe end iterator to parse the set.
static const iteratorend () noexcept
 The usual unsafe end iterator to parse the set.
static const const_iteratorcend () noexcept
 The usual unsafe end iterator to parse the set.

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

Definition at line 129 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 141 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 143 of file set.h.

◆ const_pointer

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

Types for STL compliance.

Definition at line 137 of file set.h.

◆ const_reference

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

Types for STL compliance.

Definition at line 135 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 139 of file set.h.

◆ iterator

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

Types for STL compliance.

Definition at line 140 of file set.h.

◆ iterator_safe

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

Types for STL compliance.

Definition at line 142 of file set.h.

◆ pointer

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

Types for STL compliance.

Definition at line 136 of file set.h.

◆ reference

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

Types for STL compliance.

Definition at line 134 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 138 of file set.h.

◆ value_type

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

Types for STL compliance.

Definition at line 133 of file set.h.

Constructor & Destructor Documentation

◆ Set() [1/5]

template<typename Key>
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 277 of file set_tpl.h.

277 :
278 // create the hash table without key uniqueness policy (as we will
279 // check
280 // ourselves the uniqueness of Keys before inserting new elements)
283 }
Representation of a set.
Definition set.h:129
HashTable< Key, bool > _inside_
A set of X's is actually a hash table whose keys are the X's.
Definition set.h:549
Size capacity() const
Returns the capacity of the underlying hash table containing the set.
Definition set_tpl.h:433

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

Referenced by Set(), Set(), Set(), isStrictSubsetOf(), isStrictSupersetOf(), isSubsetOrEqual(), isSupersetOrEqual(), 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>
gum::Set< Key >::Set ( std::initializer_list< Key > list)

Initializer list constructor.

Parameters
listThe initializer list.

Definition at line 287 of file set_tpl.h.

287 :
288 _inside_(Size(list.size()) / 2, true, false) {
290 for (const auto& elt: list) {
291 insert(elt);
292 }
293 }
void insert(const Key &k)
Inserts a new element into the set.
Definition set_tpl.h:510
Size size() const noexcept
Returns the number of elements in the set.
Definition set_tpl.h:607

References _inside_, and size().

Here is the call graph for this function:

◆ Set() [3/5]

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

Copy constructor.

Parameters
aHTThe gum::Set to copy.

Definition at line 297 of file set_tpl.h.

297 : _inside_(s._inside_) {
299 }

References Set(), and _inside_.

Here is the call graph for this function:

◆ Set() [4/5]

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

Move constructor.

Parameters
aHTThe gum::Set to move.

Definition at line 303 of file set_tpl.h.

305 }

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)
explicitprivate

Convert a hash table into a set of keys.

Member Function Documentation

◆ begin()

template<typename Key>
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 409 of file set_tpl.h.

409 {
410 return SetIterator< Key >{*this};
411 }
friend class SetIterator< Key >
Friends to speed up access.
Definition set.h:544

References SetIterator< Key >.

Referenced by gum::StaticTriangulation::_computeMaxPrimeMergings_(), gum::MeekRules::_orientDoubleHeadedArcs_(), gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), gum::StaticTriangulation::_triangulate_(), gum::graph::ancestors(), gum::graph::areConnected(), gum::BarrenNodesFinder::barrenNodes(), gum::graph::chainComponent(), gum::graph::chainComponents(), gum::CausalModel< GUM_SCALAR >::connectedComponents(), gum::graph::connectedComponents(), gum::graph::descendants(), gum::prm::eliminateNode(), gum::ASTjointProba< GUM_SCALAR >::eval(), gum::graph::hasUndirectedPath(), gum::graph::hasUndirectedPath(), gum::graph::hasUndirectedPath(), gum::graph::moralizedAncestralGraph(), gum::CausalImpact< GUM_ELEMENT >::on(), gum::learning::ConstraintBasedLearning::orientDoubleHeadedArcs_(), popFirst(), gum::learning::FCI::possibleDSepPhase_(), 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>
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 385 of file set_tpl.h.

385 {
386 return SetIteratorSafe< Key >{*this};
387 }
friend class SetIteratorSafe< Key >
Friends to speed up access.
Definition set.h:545

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

433 {
434 return _inside_.capacity();
435 }

References _inside_.

Referenced by Set().

Here is the caller graph for this function:

◆ cbegin()

template<typename Key>
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 415 of file set_tpl.h.

415 {
416 return SetIterator< Key >{*this};
417 }

References SetIterator< Key >.

Here is the call graph for this function:

◆ cbeginSafe()

template<typename Key>
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 391 of file set_tpl.h.

391 {
392 return SetIteratorSafe< Key >{*this};
393 }

References SetIteratorSafe< Key >.

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

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

◆ cend()

template<typename Key>
const Set< Key >::const_iterator & gum::Set< Key >::cend ( )
staticnoexcept

The usual unsafe end iterator to parse the set.

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

Definition at line 427 of file set_tpl.h.

427 {
428 return *(static_cast< const SetIterator< Key >* >(_Set_end_));
429 }

References SetIterator< Key >.

Here is the call graph for this function:

◆ cendSafe()

template<typename Key>
const Set< Key >::const_iterator_safe & gum::Set< Key >::cendSafe ( )
staticnoexcept

The usual safe end iterator to parse the set.

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

Definition at line 403 of file set_tpl.h.

403 {
404 return *(static_cast< const SetIteratorSafe< Key >* >(_Set_end_safe_));
405 }

References SetIteratorSafe< Key >.

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

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

◆ clear()

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

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

Definition at line 315 of file set_tpl.h.

315 {
316 // first we remove all the elements from the hashtable actually containing
317 // the elements of the set. Note that, doing so, all the hashtable iterators
318 // will be updated as well. In turn, this will imply that, whenever an
319 // operation will be performed on a SetIteratorSafe, this will raise an
320 // exception.
321 _inside_.clear();
322
323 // Note that actually there is no need to update the end iterator as this
324 // one
325 // is not affected by changes within hashtables (adding/deleting elements).
326 // Hence, for speedup, we do not update the end iterator
327 }

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::dSeparationAlgorithm::requisiteNodes(), gum::ITI< AttributeSelection, isScalar >::updateGraph(), and gum::LeafAggregator::updateLeaf().

Here is the caller graph for this function:

◆ contains()

template<typename Key>
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 468 of file set_tpl.h.

468 {
469 return _inside_.exists(k);
470 }

References _inside_.

Referenced by gum::DoCalculus< GUM_SCALAR >::_ancestorsIn_(), gum::DoCalculus< GUM_SCALAR >::_cDecomposition_(), gum::Tensor< GUM_SCALAR >::_complementVars_(), gum::StaticTriangulation::_computeMaxPrimeJunctionTree_(), gum::DoorCriteria::_existsUnblockedDirectedPath_(), gum::DoCalculus< GUM_SCALAR >::_ID_(), gum::prm::SVE< GUM_SCALAR >::_initElimOrder_(), gum::prm::SVED< GUM_SCALAR >::_initElimOrder_(), gum::graph::_mcsVisitDn_(), gum::graph::_mcsVisitUp_(), gum::IMarkovRandomField< GUM_SCALAR >::_minimalCondSetVisit_(), gum::MeekRules::_orientDoubleHeadedArcs_(), gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), gum::graph::ancestors(), gum::graph::areConnected(), gum::CausalModel< GUM_SCALAR >::backDoor(), gum::graph::chainComponent(), gum::graph::descendants(), gum::DoorCriteria::enumerateBackdoorSets(), gum::DoorCriteria::enumerateFrontdoorSets(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::evidenceImpact(), gum::CausalModel< GUM_SCALAR >::frontDoor(), gum::DoCalculus< GUM_SCALAR >::getBackDoorTree(), gum::DoCalculus< GUM_SCALAR >::getFrontDoorTree(), gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder(), gum::graph::hasDirectedPath(), gum::graph::hasUndirectedPath(), gum::graph::hasUndirectedPath(), gum::graph::hasUndirectedPath(), gum::Separation::isAncestorOf(), gum::Separation::isDescendantOf(), isStrictSubsetOf(), gum::learning::SimpleMiic::learnStructure(), gum::graph::minimalCondSet(), gum::IMarkovRandomField< GUM_SCALAR >::minimalCondSet(), gum::graph::moralGraph(), gum::graph::moralizedAncestralGraph(), gum::DoorCriteria::nodesOnDirectedPaths(), gum::learning::ConstraintBasedLearning::orientDoubleHeadedArcs_(), gum::O3prmBNReader< GUM_SCALAR >::proceed(), gum::learning::SimpleMiic::propagatesOrientationInChainOfRemainingEdges_(), gum::rec_hasMixedReallyOrientedPath(), gum::DoorCriteria::satisfiesBackdoorCriterion(), gum::DoorCriteria::satisfiesFrontdoorCriterion(), gum::Estimator< GUM_SCALAR >::setFromBN(), and gum::Estimator< GUM_SCALAR >::setFromLBP().

◆ emplace()

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.

Definition at line 547 of file set_tpl.h.

547 {
549 }

References insert().

Here is the call graph for this function:

◆ empty()

template<typename Key>
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 613 of file set_tpl.h.

613 {
614 return _inside_.empty();
615 }

References _inside_.

Referenced by gum::_dsepExplanation_(), gum::prm::SVE< GUM_SCALAR >::_eliminateNodesDownward_(), gum::DoCalculus< GUM_SCALAR >::_ID_(), gum::prm::SVE< GUM_SCALAR >::_initElimOrder_(), gum::prm::SVED< GUM_SCALAR >::_initElimOrder_(), gum::DoorCriteria::_isMinimalFrontdoorAdjustment(), gum::MeekRules::_orientDoubleHeadedArcs_(), gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), gum::VariableSelector::_removeVar_(), gum::graph::ancestors(), gum::graph::areConnected(), gum::graph::chainComponent(), gum::graph::chainComponents(), gum::CausalModel< GUM_SCALAR >::connectedComponents(), gum::graph::connectedComponents(), gum::graph::descendants(), gum::DoCalculus< GUM_SCALAR >::doCalculusWithObservation(), gum::DoorCriteria::enumerateBackdoorSets(), gum::DoorCriteria::enumerateFrontdoorSets(), gum::DoCalculus< GUM_SCALAR >::getBackDoorTree(), gum::DoCalculus< GUM_SCALAR >::getFrontDoorTree(), gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder(), gum::graph::hasUndirectedPath(), gum::graph::hasUndirectedPath(), gum::graph::hasUndirectedPath(), gum::learning::ConstraintBasedLearning::initGraph_(), 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::graph::markovBlanket(), gum::Tensor< GUM_SCALAR >::maxIn(), gum::Tensor< GUM_SCALAR >::minIn(), gum::graph::moralGraph(), gum::graph::moralizedAncestralGraph(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::msgL_(), gum::learning::ConstraintBasedLearning::orientDoubleHeadedArcs_(), popFirst(), gum::learning::IBNLearner::prepareFCI_(), gum::learning::IBNLearner::prepareMiic_(), gum::learning::IBNLearner::preparePC_(), gum::Tensor< GUM_SCALAR >::prodIn(), gum::learning::SimpleMiic::propagatesOrientationInChainOfRemainingEdges_(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::refreshLMsPIs_(), gum::DoorCriteria::satisfiesFrontdoorCriterion(), gum::prm::PRMFactory< GUM_SCALAR >::startClass(), gum::Tensor< GUM_SCALAR >::sumIn(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateNode_().

◆ end()

template<typename Key>
const Set< Key >::iterator & gum::Set< Key >::end ( )
staticnoexcept

The usual unsafe end iterator to parse the set.

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

Definition at line 421 of file set_tpl.h.

421 {
422 return *(static_cast< const SetIterator< Key >* >(_Set_end_));
423 }

References SetIterator< Key >.

Referenced by gum::StaticTriangulation::_computeMaxPrimeMergings_(), gum::StaticTriangulation::_triangulate_(), gum::CausalImpact< GUM_ELEMENT >::on(), and gum::learning::FCI::possibleDSepPhase_().

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

◆ endSafe()

template<typename Key>
const Set< Key >::iterator_safe & gum::Set< Key >::endSafe ( )
staticnoexcept

The usual safe end iterator to parse the set.

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

Definition at line 397 of file set_tpl.h.

397 {
398 return *(static_cast< const SetIteratorSafe< Key >* >(_Set_end_safe_));
399 }

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

574 {
575 // erase the element
576 _inside_.erase(iter._ht_iter_);
577
578 // Note that actually there is no need to update the end iterator as this
579 // one
580 // is not affected by changes within hashtables (adding/deleting elements).
581 // Hence, for speedup, we do not update the end iterator
582 }

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

Here is the call graph for this function:

◆ erase() [2/2]

template<typename Key>
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 553 of file set_tpl.h.

553 {
554 // erase the element (if it exists)
555 _inside_.erase(k);
556
557 // Note that actually there is no need to update the end iterator as this
558 // one
559 // is not affected by changes within hashtables (adding/deleting elements).
560 // Hence, for speedup, we do not update the end iterator
561 }

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::DoorCriteria::_isMinimalBackdoorAdjustment(), gum::DoorCriteria::_isMinimalFrontdoorAdjustment(), gum::MeekRules::_orientDoubleHeadedArcs_(), gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), gum::prm::StructuredInference< GUM_SCALAR >::_removeNode_(), gum::graph::ancestors(), gum::graph::areConnected(), gum::DoorCriteria::backdoorReach(), gum::BarrenNodesFinder::barrenNodes(), gum::graph::chainComponent(), gum::graph::chainComponents(), gum::graph::connectedComponents(), gum::Counterfactual< GUM_ELEMENT >::counterFactualModel(), gum::Counterfactual< GUM_ELEMENT >::counterFactualModel(), gum::counterfactualModel(), gum::graph::descendants(), gum::DoorCriteria::enumerateFrontdoorSets(), gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder(), gum::graph::hasUndirectedPath(), gum::graph::hasUndirectedPath(), gum::graph::hasUndirectedPath(), gum::graph::moralizedAncestralGraph(), gum::DoorCriteria::nodesOnDirectedPaths(), operator>>(), gum::learning::ConstraintBasedLearning::orientDoubleHeadedArcs_(), popFirst(), gum::learning::SimpleMiic::propagatesOrientationInChainOfRemainingEdges_(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), and gum::ITI< AttributeSelection, isScalar >::updateGraph().

◆ exists()

template<typename Key>
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 504 of file set_tpl.h.

504 {
505 return _inside_.exists(k);
506 }

References _inside_.

Referenced by gum::graph::_bayesBall_(), 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::ConstraintBasedLearning::_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::graph::areConnected(), gum::BarrenNodesFinder::barrenNodes(), gum::graph::dSeparated(), gum::prm::gspan::DFSTree< GUM_SCALAR >::growPattern(), gum::DAGCycleDetector::hasCycleFromModifications(), gum::DAGmodel::hasSameStructure(), gum::MarkovBlanket::hasSameStructure(), gum::UGmodel::hasSameStructure(), gum::Tensor< GUM_SCALAR >::maxOut(), gum::Tensor< GUM_SCALAR >::minOut(), gum::Tensor< GUM_SCALAR >::prodOut(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), gum::dSeparationAlgorithm::requisiteNodes(), and gum::MixedGraph::toDot().

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

745 {
746 // determine the proper size of the hashtable
747 // by default, the size of the table is set so that the table does not take
748 // too much space while allowing to add a few elements without resizing
749 if (size == 0) size = std::max(Size(2), _inside_.size() / 2);
750
751 // create a new table
753
754 // fill the new hash table
756 ++iter) {
757 table.insert(iter.key(), val);
758 }
759
760 return table;
761 }

References _inside_, 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 724 of file set_tpl.h.

724 {
725 // determine the proper size of the hashtable
726 // by default, the size of the table is set so that the table does not take
727 // too much space while allowing to add a few elements without resizing
728 if (size == 0) size = std::max(Size(2), _inside_.size() / 2);
729
730 // create a new table
732
733 // fill the new hash table
735 ++iter) {
736 table.insert(iter.key(), f(iter.key()));
737 }
738
739 return table;
740 }

References _inside_, and size().

Here is the call graph for this function:

◆ insert() [1/2]

template<typename Key>
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 510 of file set_tpl.h.

510 {
511 // WARNING: we shall always test whether k already belongs to the set before
512 // trying to insert it because we set _inside_'s key uniqueness policy to
513 // false
514 if (!contains(k)) {
515 // insert the element
516 _inside_.insert(k, true);
517
518 // Note that actually there is no need to update the end iterator as this
519 // one
520 // is not affected by changes within hashtables (adding/deleting
521 // elements).
522 // Hence, for speedup, we do not update the end iterator
523 }
524 }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition set_tpl.h:468

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), gum::prm::StructuredInference< GUM_SCALAR >::_addEdgesInReducedGraph_(), gum::DoCalculus< GUM_SCALAR >::_ancestorsIn_(), gum::graph::_bayesBall_(), gum::prm::gspan::StrictSearch< GUM_SCALAR >::_buildPatternGraph_(), gum::prm::StructuredInference< GUM_SCALAR >::_buildPatternGraph_(), gum::prm::StructuredInference< GUM_SCALAR >::_buildReduceGraph_(), gum::DoCalculus< GUM_SCALAR >::_cDecomposition_(), gum::Tensor< GUM_SCALAR >::_complementVars_(), gum::ASTposteriorProba< GUM_SCALAR >::_compute_knw_from_bn(), gum::ASTposteriorProba< GUM_SCALAR >::_compute_knw_from_dag(), gum::StaticTriangulation::_computeRecursiveThinning_(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::_connect_(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::_directedPath_(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::_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::ConstraintBasedLearning::_existsDirectedPath_(), gum::learning::SimpleMiic::_existsDirectedPath_(), gum::MeekRules::_existsDirectedPath_(), gum::DoorCriteria::_existsUnblockedDirectedPath_(), gum::prm::StructuredBayesBall< GUM_SCALAR >::_fillMaps_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClasses_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClasses_(), gum::DoCalculus< GUM_SCALAR >::_ID_(), gum::CausalImpact< GUM_SCALAR >::_idsToNames_(), gum::Counterfactual< GUM_ELEMENT >::_idsToNames_(), 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::MCBayesNetGenerator< GUM_SCALAR, SimpleCPTGenerator, SimpleCPTDisturber >::_isPolytree_(), gum::CausalImpact< GUM_SCALAR >::_namesToIds_(), 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::CausalFormula< GUM_SCALAR >::_toNodeSetFromNames_(), gum::prm::StructuredInference< GUM_SCALAR >::_translatePotSet_(), gum::StaticTriangulation::_triangulate_(), gum::prm::SVE< GUM_SCALAR >::_variableElimination_(), gum::LeafAggregator::addLeaf(), gum::graph::ancestors(), gum::graph::areConnected(), gum::NodeGraphPart::asNodeSet(), gum::CausalModel< GUM_ELEMENT >::assumeNonSpurious(), gum::DoorCriteria::backdoorReach(), gum::BarrenNodesFinder::barrenNodes(), gum::BarrenNodesFinder::barrenNodes(), gum::BarrenNodesFinder::barrenTensors(), gum::graph::chainComponent(), gum::graph::chainComponents(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::CausalModel< GUM_SCALAR >::connectedComponents(), gum::graph::connectedComponents(), gum::Counterfactual< GUM_ELEMENT >::counterFactualModel(), gum::Counterfactual< GUM_ELEMENT >::counterFactualModel(), gum::counterfactualModel(), gum::graph::cSeparated(), gum::graph::cSeparated(), gum::graph::descendants(), gum::DoCalculus< GUM_SCALAR >::doCalculusWithObservation(), gum::DoCalculus< GUM_SCALAR >::doCalculusWithObservation(), gum::graph::dSeparated(), gum::prm::eliminateNode(), emplace(), gum::DoorCriteria::enumerateBackdoorSets(), gum::DoorCriteria::enumerateFrontdoorSets(), gum::ASTjointProba< GUM_SCALAR >::eval(), gum::ASTposteriorProba< GUM_SCALAR >::eval(), gum::ASTsum< GUM_SCALAR >::eval(), gum::ASTsum< GUM_SCALAR >::fastToLatex(), gum::Tensor< GUM_SCALAR >::fillWith(), gum::Tensor< GUM_SCALAR >::findAll(), gum::DoCalculus< GUM_SCALAR >::getBackDoorTree(), gum::DoCalculus< GUM_SCALAR >::getBackDoorTree(), gum::DoCalculus< GUM_SCALAR >::getFrontDoorTree(), gum::DoCalculus< GUM_SCALAR >::getFrontDoorTree(), gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder(), gum::prm::gspan::DFSTree< GUM_SCALAR >::growPattern(), gum::DoorCriteria::hasBackdoorPath(), gum::DAGCycleDetector::hasCycleFromModifications(), gum::graph::hasDirectedPath(), gum::graph::hasUndirectedPath(), gum::graph::hasUndirectedPath(), gum::graph::hasUndirectedPath(), gum::DoCalculus< GUM_SCALAR >::identifyingIntervention(), gum::FMDPLearner< VariableAttributeSelection, RewardAttributeSelection, LearnerSelection >::initialize(), gum::Separation::isForwardSeparated(), gum::PartialOrderedEliminationSequenceStrategy::isPartialOrderNeeded_(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::JointTargetedMRFInference< GUM_SCALAR >::jointMutualInformation(), gum::JointTargetedMRFInference< GUM_SCALAR >::jointPosterior(), gum::CausalModel< GUM_SCALAR >::latentVariablesIds(), gum::CausalModel< GUM_ELEMENT >::latentVariablesIds(), gum::DecisionTensor< GUM_SCALAR >::marginalization(), gum::graph::moralGraph(), gum::graph::moralizedAncestralGraph(), gum::GraphicalModel::nodeset(), gum::DoorCriteria::nodesOnDirectedPaths(), gum::IMarkovRandomField< GUM_SCALAR >::operator==(), gum::learning::ConstraintBasedLearning::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::dSeparationAlgorithm::requisiteNodes(), gum::DoorCriteria::satisfiesBackdoorCriterion(), gum::DoorCriteria::satisfiesFrontdoorCriterion(), gum::prm::PRMFactory< GUM_SCALAR >::startClass(), gum::MixedGraph::toDot(), gum::IMDDI< AttributeSelection, isScalar >::updateGraph(), gum::ITI< AttributeSelection, isScalar >::updateGraph(), and gum::GraphicalModel::variables().

◆ insert() [2/2]

template<typename Key>
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 528 of file set_tpl.h.

528 {
529 // WARNING: we shall always test whether k already belongs to the set before
530 // trying to insert it because we set _inside_'s key uniqueness policy to
531 // false
532 if (!contains(k)) {
533 // insert the element
534 _inside_.insert(std::move(k), true);
535
536 // Note that actually there is no need to update the end iterator as this
537 // one
538 // is not affected by changes within hashtables (adding/deleting
539 // elements).
540 // Hence, for speedup, we do not update the end iterator
541 }
542 }

References _inside_, and gum::contains().

Here is the call graph for this function:

◆ isStrictSubsetOf()

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

Definition at line 473 of file set_tpl.h.

473 {
474 if (this->size() >= s.size()) { return false; }
475
476 for (const auto& elt: *this) {
477 if (!s.contains(elt)) { return false; }
478 }
479 return true;
480 }

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>
bool gum::Set< Key >::isStrictSupersetOf ( const Set< Key > & s) const
Returns
Returns true if *this is a proper superset of s

Definition at line 483 of file set_tpl.h.

483 {
484 return s.isStrictSubsetOf(*this);
485 }
bool isStrictSubsetOf(const Set< Key > &s) const
Definition set_tpl.h:473

References Set(), and isStrictSubsetOf().

Here is the call graph for this function:

◆ isSubsetOrEqual()

template<typename Key>
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 488 of file set_tpl.h.

488 {
489 if (this->size() > s.size()) { return false; }
490
491 for (const auto& elt: *this) {
492 if (!s.contains(elt)) { return false; }
493 }
494 return true;
495 }

References Set().

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

498 {
499 return s.isSubsetOrEqual(*this);
500 }
bool isSubsetOrEqual(const Set< Key > &s) const
Definition set_tpl.h:488

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

766 {
767 // create a new list
769
770 // fill the new list
772 ++iter) {
773 list.pushBack(f(iter.key()));
774 }
775
776 return list;
777 }

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

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

619 {
623
624 if (size() < h2.size()) {
626 ++iter) {
627 if (h2.exists(iter.key())) h_r.insert(iter.key(), true);
628 }
629 } else {
631 if (_inside_.exists(iter.key())) h_r.insert(iter.key(), true);
632 }
633 }
634
635 return res;
636 }
const_iterator cbegin() const
The usual unsafe begin iterator to parse the set.
Definition set_tpl.h:415
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition set_tpl.h:504
static const const_iterator & cend() noexcept
The usual unsafe end iterator to parse the set.
Definition set_tpl.h:427

References Set().

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

640 {
641 if (&s2 != this) {
643 for (auto iter = _inside_.beginSafe(); iter != _inside_.endSafe(); ++iter) {
644 if (!h2.exists(iter.key())) _inside_.erase(iter);
645 }
646 }
647
648 return *this;
649 }

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

665 {
666 Set< Key > res = *this;
669
671 if (!h_r.exists(iter.key())) h_r.insert(iter.key(), true);
672 }
673
674 return res;
675 }

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

653 {
654 if (&s2 != this) {
655 for (auto pair: s2._inside_) {
656 if (!_inside_.exists(pair.first)) { _inside_.insert(pair.first, true); }
657 }
658 }
659
660 return *this;
661 }

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

679 {
683
685 ++iter)
686 if (!h2.exists(iter.key())) h_r.insert(iter.key(), true);
687
688 return res;
689 }

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

Here is the call graph for this function:

◆ operator<<() [1/2]

template<typename Key>
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 574 of file set_tpl.h.

586 {
587 insert(k);
588 return *this;
589 }

◆ operator<<() [2/2]

template<typename Key>
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 574 of file set_tpl.h.

593 {
595 return *this;
596 }

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

331 {
332 // avoid self assignment
333 if (&s != this) {
334 // remove the old content of the set. Actually, we remove all the elements
335 // from the underlying hashtable. Note that, doing so, all the hashtable
336 // iterators will be updated as well. In turn, this will imply that,
337 // whenever
338 // an operation will be performed on a SetIteratorSafe, this will raise an
339 // exception.
340 clear();
341
342 // prepare the set for its new data
343 resize(s.capacity());
345
346 // copy the set
348
349 // Note that actually there is no need to update the end iterator as this
350 // one
351 // is not affected by changes within hashtables (adding/deleting
352 // elements).
353 // Hence, for speedup, we do not update the end iterator
354 }
355
356 return *this;
357 }
void setResizePolicy(const bool new_policy)
Enables the user to change dynamically the resizing policy of the underlying hash table.
Definition set_tpl.h:451
void resize(Size new_capacity)
Changes the size of the underlying hash table containing the set.
Definition set_tpl.h:439
void clear()
Removes all the elements, if any, from the set.
Definition set_tpl.h:315
bool resizePolicy() const
Returns the current resizing policy of the underlying hash table.
Definition set_tpl.h:462

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)
noexcept

Move operator.

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

Definition at line 361 of file set_tpl.h.

361 {
362 if (this != &from) { _inside_ = std::move(from._inside_); }
363 return *this;
364 }

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

368 {
370
371 // check whether both sets have the same number of elements
372 if (size() != h2.size()) { return false; }
373
374 // check the content of the sets
376 ++iter) {
377 if (!h2.exists(iter.key())) { return false; }
378 }
379
380 return true;
381 }

References Set(), and _inside_.

Here is the call graph for this function:

◆ operator>>()

template<typename Key>
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 600 of file set_tpl.h.

600 {
601 erase(k);
602 return *this;
603 }

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

564 {
565 if (this->empty()) { GUM_ERROR(NotFound, "Cannot popFirst from an empty set"); }
566
567 auto key = *this->begin();
568 this->erase(key);
569 return key;
570 }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition set_tpl.h:613
#define GUM_ERROR(type, msg)
Definition exceptions.h:76

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

Referenced by gum::graph::moralGraph().

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

◆ resize()

template<typename Key>
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 439 of file set_tpl.h.

439 {
440 _inside_.resize(new_size);
441
442 // Note that actually there is no need to update the end iterator as this
443 // one
444 // is not affected by changes within hashtables (adding/deleting elements).
445 // Hence, for speedup, we do not update the end iterator
446 }

References _inside_.

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

Here is the caller graph for this function:

◆ resizePolicy()

template<typename Key>
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 462 of file set_tpl.h.

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

References _inside_.

◆ setResizePolicy()

template<typename Key>
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 451 of file set_tpl.h.

451 {
452 _inside_.setResizePolicy(new_policy);
453
454 // Note that actually there is no need to update the end iterator as this
455 // one
456 // is not affected by changes within hashtables (adding/deleting elements).
457 // Hence, for speedup, we do not update the end iterator
458 }

References _inside_.

◆ size()

template<typename Key>
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 607 of file set_tpl.h.

607 {
608 return _inside_.size();
609 }

References _inside_.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), Set(), 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::ClusteredLayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::DoCalculus< GUM_SCALAR >::_ID_(), 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::DoCalculus< GUM_SCALAR >::_topoObserved_(), gum::StaticTriangulation::_triangulate_(), gum::AggregatorDecomposition< GUM_SCALAR >::addDepthLayer_(), gum::BarrenNodesFinder::barrenNodes(), gum::AggregatorDecomposition< GUM_SCALAR >::decomposeAggregator_(), gum::prm::eliminateNode(), gum::ASTjointProba< GUM_SCALAR >::eval(), gum::StaticTriangulation::fillIns(), gum::DoCalculus< GUM_SCALAR >::getBackDoorTree(), gum::DoCalculus< GUM_SCALAR >::getFrontDoorTree(), hashMap(), hashMap(), gum::learning::Miic::initiation_(), gum::learning::SimpleMiic::initiation_(), gum::Separation::isBackdoorSeparated(), gum::PartialOrderedEliminationSequenceStrategy::isPartialOrderNeeded_(), isStrictSubsetOf(), 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(), and gum::StaticTriangulation::triangulatedGraph().

◆ toString()

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

Prints the content of the set.

Returns
Returns the content of the set.

Definition at line 693 of file set_tpl.h.

693 {
695 bool first = true;
696 out << "{";
697
698 for (iterator iter = begin(); iter != end(); ++iter) {
699 if (first) {
700 out << *iter;
701 first = false;
702 } else {
703 out << "," << *iter;
704 }
705 }
706
707 out << "}";
708
710 out >> res;
711 return res;
712 }

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 537 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 537 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 549 of file set.h.

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


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