aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::SetTerminalNodePolicy< GUM_SCALAR > Class Template Reference

Implementation of a Terminal Node Policy that maps nodeid to a set of value. More...

#include <agrum/tools/multidim/FunctionGraphUtilities/terminalNodePolicies/SetTerminalNodePolicy.h>

+ Inheritance diagram for gum::SetTerminalNodePolicy< GUM_SCALAR >:
+ Collaboration diagram for gum::SetTerminalNodePolicy< GUM_SCALAR >:

Public Member Functions

 ~SetTerminalNodePolicy ()
 
Terminal Node Creation and Destruction
void addTerminalNode (const NodeId &n, const GUM_SCALAR &v)
 Insert a new terminal node with given value. More...
 
void eraseTerminalNode (const NodeId &n)
 Remove node matching given id. More...
 
void clearAllTerminalNodes ()
 Erase all terminal nodes. More...
 
Terminal Nodes Existence
bool existsTerminalNodeWithId (const NodeId &n) const
 Returns true if a terminal node matching this id exists. More...
 
bool existsTerminalNodeWithValue (const GUM_SCALAR &v) const
 Returns true if a terminal node matching this value exists. More...
 
Terminal Nodes value and id access
const GUM_SCALAR & terminalNodeValue (const NodeId &n) const
 Returns the value of the terminal node that has the given id. More...
 
const NodeIdterminalNodeId (const GUM_SCALAR &v) const
 Returns the id of the terminal node that has the given value. More...
 

Iterator on Terminal Nodes

HashTable< NodeId, GUM_SCALAR *> _map_
 The mapping between NodeIds and Value Sets. More...
 
HashTableConstIteratorSafe< NodeId, GUM_SCALAR *> _mappy_
 The mapping between NodeIds and Value Sets. More...
 
const NodeId jocker = 0
 The mapping between NodeIds and Value Sets. More...
 
void beginValues () const
 Initializes the constant safe iterator on terminal nodes. More...
 
bool hasValue () const
 Indicates if constant safe iterator has reach end of terminal nodes list. More...
 
void nextValue () const
 Increments the constant safe iterator. More...
 
const GUM_SCALAR & value () const
 Returns the value of the current terminal nodes pointed by the constant safe iterator. More...
 
const NodeIdid () const
 Returns the id of the current terminal nodes pointed by the constant safe iterator. More...
 

Detailed Description

template<typename GUM_SCALAR>
class gum::SetTerminalNodePolicy< GUM_SCALAR >

Implementation of a Terminal Node Policy that maps nodeid to a set of value.

Definition at line 48 of file SetTerminalNodePolicy.h.

Constructor & Destructor Documentation

◆ ~SetTerminalNodePolicy()

template<typename GUM_SCALAR >
gum::SetTerminalNodePolicy< GUM_SCALAR >::~SetTerminalNodePolicy ( )
inline

Definition at line 50 of file SetTerminalNodePolicy.h.

References gum::SetTerminalNodePolicy< GUM_SCALAR >::clearAllTerminalNodes().

void clearAllTerminalNodes()
Erase all terminal nodes.
+ Here is the call graph for this function:

Member Function Documentation

◆ addTerminalNode()

template<typename GUM_SCALAR >
void gum::SetTerminalNodePolicy< GUM_SCALAR >::addTerminalNode ( const NodeId n,
const GUM_SCALAR &  v 
)
inline

Insert a new terminal node with given value.

Definition at line 58 of file SetTerminalNodePolicy.h.

58  {
59  if (_map_.exists(n)) *(_map_[n]) += v;
60  _map_.insert(n, new GUM_SCALAR(v));
61  }
HashTable< NodeId, GUM_SCALAR *> _map_
The mapping between NodeIds and Value Sets.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ beginValues()

template<typename GUM_SCALAR >
void gum::SetTerminalNodePolicy< GUM_SCALAR >::beginValues ( ) const
inline

Initializes the constant safe iterator on terminal nodes.

Definition at line 110 of file SetTerminalNodePolicy.h.

110 { _mappy_ = _map_.cbeginSafe(); }
const_iterator_safe cbeginSafe() const
Returns the safe const_iterator pointing to the beginning of the hashtable.
HashTable< NodeId, GUM_SCALAR *> _map_
The mapping between NodeIds and Value Sets.
HashTableConstIteratorSafe< NodeId, GUM_SCALAR *> _mappy_
The mapping between NodeIds and Value Sets.

◆ clearAllTerminalNodes()

template<typename GUM_SCALAR >
void gum::SetTerminalNodePolicy< GUM_SCALAR >::clearAllTerminalNodes ( )
inline

Erase all terminal nodes.

Definition at line 69 of file SetTerminalNodePolicy.h.

Referenced by gum::SetTerminalNodePolicy< GUM_SCALAR >::~SetTerminalNodePolicy().

69  {
70  for (auto nodeIter = _map_.beginSafe(); nodeIter != _map_.endSafe(); ++nodeIter)
71  delete nodeIter.val();
72  _map_.clear();
73  }
const iterator_safe & endSafe() noexcept
Returns the safe iterator pointing to the end of the hashtable.
HashTable< NodeId, GUM_SCALAR *> _map_
The mapping between NodeIds and Value Sets.
void clear()
Removes all the elements in the hash table.
iterator_safe beginSafe()
Returns the safe iterator pointing to the beginning of the hashtable.
+ Here is the caller graph for this function:

◆ eraseTerminalNode()

template<typename GUM_SCALAR >
void gum::SetTerminalNodePolicy< GUM_SCALAR >::eraseTerminalNode ( const NodeId n)
inline

Remove node matching given id.

Definition at line 64 of file SetTerminalNodePolicy.h.

64  {
65  if (_map_.exists(n)) _map_.erase(n);
66  }
void erase(const Key &key)
Removes a given element from the hash table.
HashTable< NodeId, GUM_SCALAR *> _map_
The mapping between NodeIds and Value Sets.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.

◆ existsTerminalNodeWithId()

template<typename GUM_SCALAR >
bool gum::SetTerminalNodePolicy< GUM_SCALAR >::existsTerminalNodeWithId ( const NodeId n) const
inline

Returns true if a terminal node matching this id exists.

Definition at line 82 of file SetTerminalNodePolicy.h.

82 { return _map_.exists(n); }
HashTable< NodeId, GUM_SCALAR *> _map_
The mapping between NodeIds and Value Sets.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.

◆ existsTerminalNodeWithValue()

template<typename GUM_SCALAR >
bool gum::SetTerminalNodePolicy< GUM_SCALAR >::existsTerminalNodeWithValue ( const GUM_SCALAR &  v) const
inline

Returns true if a terminal node matching this value exists.

Definition at line 85 of file SetTerminalNodePolicy.h.

85 { return terminalNodeId(v) != 0; }
const NodeId & terminalNodeId(const GUM_SCALAR &v) const
Returns the id of the terminal node that has the given value.

◆ hasValue()

template<typename GUM_SCALAR >
bool gum::SetTerminalNodePolicy< GUM_SCALAR >::hasValue ( ) const
inline

Indicates if constant safe iterator has reach end of terminal nodes list.

Definition at line 113 of file SetTerminalNodePolicy.h.

113 { return _mappy_ != _map_.cendSafe(); }
HashTable< NodeId, GUM_SCALAR *> _map_
The mapping between NodeIds and Value Sets.
const const_iterator_safe & cendSafe() const noexcept
Returns the safe const_iterator pointing to the end of the hashtable.
HashTableConstIteratorSafe< NodeId, GUM_SCALAR *> _mappy_
The mapping between NodeIds and Value Sets.

◆ id()

template<typename GUM_SCALAR >
const NodeId& gum::SetTerminalNodePolicy< GUM_SCALAR >::id ( ) const
inline

Returns the id of the current terminal nodes pointed by the constant safe iterator.

Definition at line 124 of file SetTerminalNodePolicy.h.

124 { return _mappy_.key(); }
const key_type & key() const
Returns the key pointed to by the iterator.
HashTableConstIteratorSafe< NodeId, GUM_SCALAR *> _mappy_
The mapping between NodeIds and Value Sets.

◆ nextValue()

template<typename GUM_SCALAR >
void gum::SetTerminalNodePolicy< GUM_SCALAR >::nextValue ( ) const
inline

Increments the constant safe iterator.

Definition at line 116 of file SetTerminalNodePolicy.h.

116 { ++_mappy_; }
HashTableConstIteratorSafe< NodeId, GUM_SCALAR *> _mappy_
The mapping between NodeIds and Value Sets.

◆ terminalNodeId()

template<typename GUM_SCALAR >
const NodeId& gum::SetTerminalNodePolicy< GUM_SCALAR >::terminalNodeId ( const GUM_SCALAR &  v) const
inline

Returns the id of the terminal node that has the given value.

Definition at line 97 of file SetTerminalNodePolicy.h.

97  {
98  for (auto nodeIter = _map_.beginSafe(); nodeIter != _map_.endSafe(); ++nodeIter)
99  if (*(nodeIter.val()) == v) return nodeIter.key();
100  return jocker;
101  }
const iterator_safe & endSafe() noexcept
Returns the safe iterator pointing to the end of the hashtable.
HashTable< NodeId, GUM_SCALAR *> _map_
The mapping between NodeIds and Value Sets.
const NodeId jocker
The mapping between NodeIds and Value Sets.
iterator_safe beginSafe()
Returns the safe iterator pointing to the beginning of the hashtable.

◆ terminalNodeValue()

template<typename GUM_SCALAR >
const GUM_SCALAR& gum::SetTerminalNodePolicy< GUM_SCALAR >::terminalNodeValue ( const NodeId n) const
inline

Returns the value of the terminal node that has the given id.

Definition at line 94 of file SetTerminalNodePolicy.h.

94 { return *(_map_[n]); }
HashTable< NodeId, GUM_SCALAR *> _map_
The mapping between NodeIds and Value Sets.

◆ value()

template<typename GUM_SCALAR >
const GUM_SCALAR& gum::SetTerminalNodePolicy< GUM_SCALAR >::value ( ) const
inline

Returns the value of the current terminal nodes pointed by the constant safe iterator.

Definition at line 120 of file SetTerminalNodePolicy.h.

120 { return *(_mappy_.val()); }
const mapped_type & val() const
Returns the mapped value pointed to by the iterator.
HashTableConstIteratorSafe< NodeId, GUM_SCALAR *> _mappy_
The mapping between NodeIds and Value Sets.

Member Data Documentation

◆ _map_

template<typename GUM_SCALAR >
HashTable< NodeId, GUM_SCALAR* > gum::SetTerminalNodePolicy< GUM_SCALAR >::_map_
private

The mapping between NodeIds and Value Sets.

Definition at line 128 of file SetTerminalNodePolicy.h.

◆ _mappy_

template<typename GUM_SCALAR >
HashTableConstIteratorSafe< NodeId, GUM_SCALAR* > gum::SetTerminalNodePolicy< GUM_SCALAR >::_mappy_
mutableprivate

The mapping between NodeIds and Value Sets.

Definition at line 129 of file SetTerminalNodePolicy.h.

◆ jocker

template<typename GUM_SCALAR >
const NodeId gum::SetTerminalNodePolicy< GUM_SCALAR >::jocker = 0
private

The mapping between NodeIds and Value Sets.

Definition at line 131 of file SetTerminalNodePolicy.h.


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