aGrUM  0.16.0
gum::SetTerminalNodePolicy< GUM_SCALAR > Class Template Reference

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

#include <agrum/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.

References gum::SetTerminalNodePolicy< GUM_SCALAR >::__map, gum::HashTable< Key, Val, Alloc >::exists(), and gum::HashTable< Key, Val, Alloc >::insert().

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.
+ Here is the call graph for this function:

◆ beginValues()

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

Initializes the constant safe iterator on terminal nodes.

Definition at line 118 of file SetTerminalNodePolicy.h.

References gum::SetTerminalNodePolicy< GUM_SCALAR >::__map, gum::SetTerminalNodePolicy< GUM_SCALAR >::__mappy, and gum::HashTable< Key, Val, Alloc >::cbeginSafe().

118 { __mappy = __map.cbeginSafe(); }
HashTable< NodeId, GUM_SCALAR *> __map
The mapping between NodeIds and Value Sets.
const_iterator_safe cbeginSafe() const
Returns the safe const_iterator pointing to the beginning of the hashtable.
HashTableConstIteratorSafe< NodeId, GUM_SCALAR *> __mappy
The mapping between NodeIds and Value Sets.
+ Here is the call graph for this function:

◆ clearAllTerminalNodes()

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

Erase all terminal nodes.

Definition at line 69 of file SetTerminalNodePolicy.h.

References gum::SetTerminalNodePolicy< GUM_SCALAR >::__map, gum::HashTable< Key, Val, Alloc >::beginSafe(), gum::HashTable< Key, Val, Alloc >::clear(), and gum::HashTable< Key, Val, Alloc >::endSafe().

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

69  {
70  for (auto nodeIter = __map.beginSafe(); nodeIter != __map.endSafe();
71  ++nodeIter)
72  delete nodeIter.val();
73  __map.clear();
74  }
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 call graph for this function:
+ 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.

References gum::SetTerminalNodePolicy< GUM_SCALAR >::__map, gum::HashTable< Key, Val, Alloc >::erase(), and gum::HashTable< Key, Val, Alloc >::exists().

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.
+ Here is the call graph for this function:

◆ 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 83 of file SetTerminalNodePolicy.h.

References gum::SetTerminalNodePolicy< GUM_SCALAR >::__map, and gum::HashTable< Key, Val, Alloc >::exists().

83  {
84  return __map.exists(n);
85  }
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.
+ Here is the call graph for this function:

◆ 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 88 of file SetTerminalNodePolicy.h.

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

88  {
89  return terminalNodeId(v) != 0;
90  }
const NodeId & terminalNodeId(const GUM_SCALAR &v) const
Returns the id of the terminal node that has the given value.
+ Here is the call graph for this function:

◆ 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 121 of file SetTerminalNodePolicy.h.

References gum::SetTerminalNodePolicy< GUM_SCALAR >::__map, gum::SetTerminalNodePolicy< GUM_SCALAR >::__mappy, and gum::HashTable< Key, Val, Alloc >::cendSafe().

121 { return __mappy != __map.cendSafe(); }
HashTable< NodeId, GUM_SCALAR *> __map
The mapping between NodeIds and Value Sets.
HashTableConstIteratorSafe< NodeId, GUM_SCALAR *> __mappy
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.
+ Here is the call graph for this function:

◆ 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 132 of file SetTerminalNodePolicy.h.

References gum::SetTerminalNodePolicy< GUM_SCALAR >::__mappy, and gum::HashTableConstIteratorSafe< Key, Val >::key().

132 { 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.
+ Here is the call graph for this function:

◆ nextValue()

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

Increments the constant safe iterator.

Definition at line 124 of file SetTerminalNodePolicy.h.

References gum::SetTerminalNodePolicy< GUM_SCALAR >::__mappy.

124 { ++__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 104 of file SetTerminalNodePolicy.h.

References gum::SetTerminalNodePolicy< GUM_SCALAR >::__map, gum::HashTable< Key, Val, Alloc >::beginSafe(), gum::HashTable< Key, Val, Alloc >::endSafe(), and gum::SetTerminalNodePolicy< GUM_SCALAR >::jocker.

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

104  {
105  for (auto nodeIter = __map.beginSafe(); nodeIter != __map.endSafe();
106  ++nodeIter)
107  if (*(nodeIter.val()) == v) return nodeIter.key();
108  return jocker;
109  }
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.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 99 of file SetTerminalNodePolicy.h.

References gum::SetTerminalNodePolicy< GUM_SCALAR >::__map.

99  {
100  return *(__map[n]);
101  }
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 128 of file SetTerminalNodePolicy.h.

References gum::SetTerminalNodePolicy< GUM_SCALAR >::__mappy, and gum::HashTableConstIteratorSafe< Key, Val >::val().

128 { 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.
+ Here is the call graph for this function:

Member Data Documentation

◆ __map

◆ __mappy

◆ jocker

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

The mapping between NodeIds and Value Sets.

Definition at line 139 of file SetTerminalNodePolicy.h.

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


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