aGrUM  0.21.0
a C++ library for (probabilistic) graphical models
gum::NodeGraphPart Class Reference

Class for node sets in graph. More...

#include <nodeGraphPart.h>

+ Inheritance diagram for gum::NodeGraphPart:
+ Collaboration diagram for gum::NodeGraphPart:

Public Attributes

Signaler1< NodeIdonNodeAdded
 
Signaler1< NodeIdonNodeDeleted
 

Public Member Functions

Constructors / Destructors
 NodeGraphPart (Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
 default constructor More...
 
 NodeGraphPart (const NodeGraphPart &s)
 copy constructor More...
 
virtual ~NodeGraphPart ()
 destructor More...
 
Operators
NodeGraphPartoperator= (const NodeGraphPart &p)
 copy operator More...
 
bool operator== (const NodeGraphPart &p) const
 check whether two NodeGraphParts contain the same nodes More...
 
bool operator!= (const NodeGraphPart &p) const
 check whether two NodeGraphParts contain different nodes More...
 
Accessors/Modifiers
void populateNodes (const NodeGraphPart &s)
 populateNodes clears *this and fills it with the same nodes as "s" More...
 
template<typename T >
void populateNodesFromProperty (const NodeProperty< T > &h)
 populateNodesFromProperty clears *this and fills it with the keys of "h" More...
 
NodeId nextNodeId () const
 returns a new node id, not yet used by any node More...
 
virtual NodeId addNode ()
 insert a new node and return its id More...
 
std::vector< NodeIdaddNodes (Size n)
 insert n nodes More...
 
virtual void addNodeWithId (const NodeId id)
 try to insert a node with the given id More...
 
virtual void eraseNode (const NodeId id)
 erase the node with the given id More...
 
bool existsNode (const NodeId id) const
 returns true iff the NodeGraphPart contains the given nodeId More...
 
bool exists (const NodeId id) const
 alias for existsNode More...
 
bool emptyNodes () const
 indicates whether there exists nodes in the NodeGraphPart More...
 
bool empty () const
 alias for emptyNodes More...
 
virtual void clearNodes ()
 remove all the nodes from the NodeGraphPart More...
 
virtual void clear ()
 alias for clearNodes More...
 
Size sizeNodes () const
 returns the number of nodes in the NodeGraphPart More...
 
Size size () const
 alias for sizeNodes More...
 
NodeId bound () const
 returns a number n such that all node ids are strictly lower than n More...
 
NodeSet asNodeSet () const
 returns a copy of the set of nodes represented by the NodeGraphPart More...
 
const NodeGraphPartnodes () const
 return *this as a NodeGraphPart More...
 
node_iterator_safe beginSafe () const
 a begin iterator to parse the set of nodes contained in the NodeGraphPart More...
 
const node_iterator_safeendSafe () const noexcept
 the end iterator to parse the set of nodes contained in the NodeGraphPart More...
 
node_iterator begin () const noexcept
 a begin iterator to parse the set of nodes contained in the NodeGraphPart More...
 
const node_iteratorend () const noexcept
 the end iterator to parse the set of nodes contained in the NodeGraphPart More...
 
virtual std::string toString () const
 a function to display the set of nodes More...
 
template<typename VAL >
NodeProperty< VAL > nodesProperty (VAL(*f)(const NodeId &), Size size=0) const
 a method to create a HashTable with key:NodeId and value:VAL More...
 
template<typename VAL >
NodeProperty< VAL > nodesProperty (const VAL &a, Size size=0) const
 a method to create a hashMap with key:NodeId and value:VAL More...
 
template<typename VAL >
List< VAL > listMapNodes (VAL(*f)(const NodeId &)) const
 a method to create a list of VAL from a set of nodes (using for every nodee, say x, the VAL f(x)) More...
 

Public Types

typedef NodeGraphPartIterator NodeIterator
 
typedef NodeGraphPartIterator NodeConstIterator
 
typedef NodeGraphPartIteratorSafe NodeIteratorSafe
 
typedef NodeGraphPartIteratorSafe NodeConstIteratorSafe
 
using node_iterator = NodeGraphPartIterator
 types for STL compliance More...
 
using node_const_iterator = NodeGraphPartIterator
 types for STL compliance More...
 
using node_iterator_safe = NodeGraphPartIteratorSafe
 types for STL compliance More...
 
using node_const_iterator_safe = NodeGraphPartIteratorSafe
 types for STL compliance More...
 

Friends

class NodeGraphPartIterator
 
class NodeGraphPartIteratorSafe
 
class gum_tests::NodeGraphPartTestSuite
 to enable testunits to use check More...
 

Detailed Description

Class for node sets in graph.

NodeGraphPart represents the set of nodes of all the graphs. It is built to be as light as possible and it implements its own NodeId factory. The set of NodeId is 0 ... ( bound-1) minus the NodeIds in holes.

Author
Pierre-Henri WUILLEMIN() & Christophe GONZALES()
Usage example:
// create an empty node list
// add 2 elements
NodeId id_a=nodes1.addNode( );
NodeId id_b=nodes1.addNode( );
// checks if there exists a node with ID = 6
if ( !nodes1.exists( 6 ) ) std::cerr << "no node with ID 6" << std::endl;
// check if the set of nodes is empty
if ( !nodes1.empty() || ( nodes1.size() != 0 ) )
std::cerr << "nodes1 is not empty" << std::endl;
// copy a set of nodes
NodeGraphPart nodes2 = nodes1, nodes3;
nodes3 = nodes1;
// remove elements from list3
nodes3.eraseNode( id_a );
nodes3.eraseNode( id_b );
// remove all the elements from the list
nodes1.clear();
for ( NodeGraphPart::iterator it=nodes2.beginNodes();
it!=nodes2.endNodes();++it ) {
std::cerr<<*it<<" ";
}
std::cerr<<"list : "<<nodes2.listMapNodes(getDouble)<<std::endl;
std::cerr<<"hashmap : "<<nodes2.hashMapNodes(getDouble)<<std::endl;

Definition at line 253 of file nodeGraphPart.h.

Member Typedef Documentation

◆ node_const_iterator

types for STL compliance

Definition at line 258 of file nodeGraphPart.h.

◆ node_const_iterator_safe

types for STL compliance

Definition at line 260 of file nodeGraphPart.h.

◆ node_iterator

types for STL compliance

Definition at line 257 of file nodeGraphPart.h.

◆ node_iterator_safe

types for STL compliance

Definition at line 259 of file nodeGraphPart.h.

◆ NodeConstIterator

◆ NodeConstIteratorSafe

◆ NodeIterator

◆ NodeIteratorSafe

Constructor & Destructor Documentation

◆ NodeGraphPart() [1/2]

gum::NodeGraphPart::NodeGraphPart ( Size  holes_size = HashTableConst::default_size,
bool  holes_resize_policy = true 
)
explicit

default constructor

A NodeGrphPart does not store all its nodes. To be lighter in terms of memory consumption, it store its maximal NodeId and the set of NodeIds between 0 and this maximum that do not actually belong to the set of its nodes (the so-called set of holes). In practice, it turns out that the set of holes is most often very small.

Parameters
holes_sizethe size of the hash table used to store all holes
holes_resize_policythe resizing policy of this hash table

Definition at line 37 of file nodeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

37  :
38  _holes_size_(holes_size), _holes_resize_policy_(holes_resize_policy),
39  _endIteratorSafe_(*this), _boundVal_(0) {
40  _holes_ = nullptr;
41  GUM_CONSTRUCTOR(NodeGraphPart);
43  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
void _updateEndIteratorSafe_()
updating endIterator (always at max+1)
NodeGraphPartIteratorSafe _endIteratorSafe_
the end iterator (used to speed-up parsings of the NodeGraphPart)
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
Size _holes_size_
value for holes configuration
bool _holes_resize_policy_
value for holes configuration
+ Here is the call graph for this function:

◆ NodeGraphPart() [2/2]

gum::NodeGraphPart::NodeGraphPart ( const NodeGraphPart s)

copy constructor

Parameters
sthe NodeGraphPart to be copied

Definition at line 45 of file nodeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

45  :
46  _holes_size_(s._holes_size_), _holes_resize_policy_(s._holes_resize_policy_),
47  _endIteratorSafe_(*this), _boundVal_(s._boundVal_) {
48  _holes_ = nullptr;
49 
50  if (s._holes_) _holes_ = new NodeSet(*s._holes_);
51 
53 
54  GUM_CONS_CPY(NodeGraphPart);
55  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
void _updateEndIteratorSafe_()
updating endIterator (always at max+1)
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeGraphPartIteratorSafe _endIteratorSafe_
the end iterator (used to speed-up parsings of the NodeGraphPart)
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
Size _holes_size_
value for holes configuration
bool _holes_resize_policy_
value for holes configuration
+ Here is the call graph for this function:

◆ ~NodeGraphPart()

gum::NodeGraphPart::~NodeGraphPart ( )
virtual

destructor

Definition at line 57 of file nodeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

57  {
58  if (_holes_) delete _holes_;
59 
60  GUM_DESTRUCTOR(NodeGraphPart);
61  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
+ Here is the call graph for this function:

Member Function Documentation

◆ _addHole_()

void gum::NodeGraphPart::_addHole_ ( NodeId  id)
private

to add a hole.

Warning
id is assumed not to be already a hole

Definition at line 76 of file nodeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

76  {
77  // we assume that the node exists
78  if (node + 1 == _boundVal_) {
79  // we remove the max : no new hole and maybe a bunch of holes to remove
80  --_boundVal_;
81 
82  if (_holes_) {
83  while (_holes_->contains(_boundVal_ - 1)) {
84  // a bunch of holes to remove. We do not use inHoles for optimisation
85  // :
86  // not to repeat the test if ( _holes_) each time
88  }
89 
90  if (_holes_->empty()) {
91  delete _holes_;
92  _holes_ = nullptr;
93  }
94  }
95 
97  } else {
99 
100  _holes_->insert(node);
101  }
102  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:558
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:700
void _updateEndIteratorSafe_()
updating endIterator (always at max+1)
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:649
Size _holes_size_
value for holes configuration
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
bool _holes_resize_policy_
value for holes configuration
+ Here is the call graph for this function:

◆ _clearNodes_()

void gum::NodeGraphPart::_clearNodes_ ( )
private

code for clearing nodes (called twice)

Definition at line 154 of file nodeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

154  {
156  _boundVal_ = 0;
157 
158  if (onNodeDeleted.hasListener()) {
159  for (NodeId n = 0; n < bound; ++n) {
160  if (!_inHoles_(n)) GUM_EMIT1(onNodeDeleted, n);
161  }
162  }
163 
165 
166  delete (_holes_);
167  _holes_ = nullptr;
168  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
void _updateEndIteratorSafe_()
updating endIterator (always at max+1)
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:41
NodeId bound() const
returns a number n such that all node ids are strictly lower than n
bool _inHoles_(NodeId id) const
Signaler1< NodeId > onNodeDeleted
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ _eraseHole_()

INLINE void gum::NodeGraphPart::_eraseHole_ ( NodeId  id)
private

to delete hole.

Warning
the hole is assumed to be existing.

Definition at line 224 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

224  {
225  _holes_->erase(id);
226 
227  if (_holes_->empty()) {
228  delete _holes_;
229  _holes_ = nullptr;
230  }
231  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:700
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:649
+ Here is the call graph for this function:

◆ _inHoles_()

INLINE bool gum::NodeGraphPart::_inHoles_ ( NodeId  id) const
private
Returns
true if id is part of holes

Definition at line 356 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

356 { return _holes_ && _holes_->contains(id); }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:558
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
+ Here is the call graph for this function:

◆ _sizeHoles_()

INLINE Size gum::NodeGraphPart::_sizeHoles_ ( ) const
private
Returns
the size of holes

Definition at line 359 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

359 { return _holes_ ? _holes_->size() : (Size)0; }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:694
+ Here is the call graph for this function:

◆ _updateEndIteratorSafe_()

INLINE void gum::NodeGraphPart::_updateEndIteratorSafe_ ( )
private

updating endIterator (always at max+1)

Definition at line 308 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
void setPos_(NodeId id) noexcept
this function is used by NodeGraphPart to update
NodeGraphPartIteratorSafe _endIteratorSafe_
the end iterator (used to speed-up parsings of the NodeGraphPart)
+ Here is the call graph for this function:

◆ addNode()

INLINE NodeId gum::NodeGraphPart::addNode ( )
virtual

insert a new node and return its id

Returns
the id chosen by the internal idFactory

Reimplemented in gum::CliqueGraph.

Definition at line 238 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

238  {
239  NodeId newNode;
240 
241  // fill the first hole if holes exist
242  if (_holes_ && (!_holes_->empty())) {
243  newNode = *(_holes_->begin());
244  _eraseHole_(newNode);
245  } else {
246  newNode = _boundVal_;
247  ++_boundVal_;
249  }
250 
251  GUM_EMIT1(onNodeAdded, newNode);
252 
253  return newNode;
254  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:700
void _updateEndIteratorSafe_()
updating endIterator (always at max+1)
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:41
iterator begin() const
The usual unsafe begin iterator to parse the set.
Definition: set_tpl.h:498
Signaler1< NodeId > onNodeAdded
void _eraseHole_(NodeId id)
to delete hole.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ addNodes()

INLINE std::vector< NodeId > gum::NodeGraphPart::addNodes ( Size  n)

insert n nodes

Parameters
nthe number of nodes to add
Returns
the vector of chosen ids

Definition at line 256 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

256  {
257  std::vector< NodeId > v;
258  v.reserve(N);
259  for (Idx i = 0; i < N; i++)
260  v.push_back(this->addNode());
261  return v;
262  }
+ Here is the call graph for this function:

◆ addNodeWithId()

void gum::NodeGraphPart::addNodeWithId ( const NodeId  id)
virtual

try to insert a node with the given id

Warning
This method should be carefully used. Please prefer populateNodes or populateNodesFromProperty when possible
Exceptions
DuplicateElementexception if the id already exists

Definition at line 131 of file nodeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

131  {
132  if (id >= _boundVal_) {
133  if (id > _boundVal_) { // we have to add holes
135 
136  for (NodeId i = _boundVal_; i < id; ++i)
137  _holes_->insert(i);
138  }
139 
140  _boundVal_ = id + 1;
141 
143  } else {
144  if (_inHoles_(id)) { // we fill a hole
145  _eraseHole_(id);
146  } else {
147  GUM_ERROR(DuplicateElement, "Id " << id << " is already used")
148  }
149  }
150 
151  GUM_EMIT1(onNodeAdded, id);
152  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
void _updateEndIteratorSafe_()
updating endIterator (always at max+1)
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:41
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Size _holes_size_
value for holes configuration
Signaler1< NodeId > onNodeAdded
bool _inHoles_(NodeId id) const
void _eraseHole_(NodeId id)
to delete hole.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
bool _holes_resize_policy_
value for holes configuration
+ Here is the call graph for this function:

◆ asNodeSet()

INLINE NodeSet gum::NodeGraphPart::asNodeSet ( ) const

returns a copy of the set of nodes represented by the NodeGraphPart

Warning
this function is o(n) where n is the number of nodes. In space and in time. Usually, when you need to parse the nodes of a NodeGraphPart, prefer using
for(const auto n : nodes())
rather than
for(const auto n : asNodeSet())
as this is faster and consumes much less memory.

Definition at line 340 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

340  {
341  NodeSet son(sizeNodes());
342 
343  if (!empty()) {
344  for (NodeId n = 0; n < _boundVal_; ++n) {
345  if (!_inHoles_(n)) son.insert(n);
346  }
347  }
348 
349  return son;
350  }
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
bool empty() const
alias for emptyNodes
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart
bool _inHoles_(NodeId id) const
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ begin()

INLINE NodeGraphPartIterator gum::NodeGraphPart::begin ( ) const
noexcept

a begin iterator to parse the set of nodes contained in the NodeGraphPart

Definition at line 314 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

314  {
315  NodeGraphPartIterator it(*this);
316  it.validate_(); // stop the iterator at the first not-in-holes
317  return it;
318  }
friend class NodeGraphPartIterator
+ Here is the call graph for this function:

◆ beginSafe()

INLINE NodeGraphPartIteratorSafe gum::NodeGraphPart::beginSafe ( ) const

a begin iterator to parse the set of nodes contained in the NodeGraphPart

Definition at line 302 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

302  {
303  NodeGraphPartIteratorSafe it(*this);
304  it.validate_(); // stop the iterator at the first not-in-holes
305  return it;
306  }
friend class NodeGraphPartIteratorSafe
+ Here is the call graph for this function:

◆ bound()

INLINE NodeId gum::NodeGraphPart::bound ( ) const

returns a number n such that all node ids are strictly lower than n

Definition at line 291 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

291 { return _boundVal_; }
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
+ Here is the call graph for this function:

◆ clear()

INLINE void gum::NodeGraphPart::clear ( )
virtual

alias for clearNodes

Reimplemented in gum::MixedGraph, gum::DiGraph, gum::UndiGraph, and gum::CliqueGraph.

Definition at line 300 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

300 { _clearNodes_(); }
void _clearNodes_()
code for clearing nodes (called twice)
+ Here is the call graph for this function:

◆ clearNodes()

INLINE void gum::NodeGraphPart::clearNodes ( )
virtual

remove all the nodes from the NodeGraphPart

Definition at line 293 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

293 { _clearNodes_(); }
void _clearNodes_()
code for clearing nodes (called twice)
+ Here is the call graph for this function:

◆ empty()

INLINE bool gum::NodeGraphPart::empty ( ) const

alias for emptyNodes

Definition at line 289 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

289 { return emptyNodes(); }
bool emptyNodes() const
indicates whether there exists nodes in the NodeGraphPart
+ Here is the call graph for this function:

◆ emptyNodes()

INLINE bool gum::NodeGraphPart::emptyNodes ( ) const

indicates whether there exists nodes in the NodeGraphPart

Definition at line 287 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

287 { return (sizeNodes() == 0); }
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart
+ Here is the call graph for this function:

◆ end()

INLINE const NodeGraphPartIterator & gum::NodeGraphPart::end ( ) const
noexcept

the end iterator to parse the set of nodes contained in the NodeGraphPart

Definition at line 320 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

320  {
321  return _endIteratorSafe_;
322  }
NodeGraphPartIteratorSafe _endIteratorSafe_
the end iterator (used to speed-up parsings of the NodeGraphPart)
+ Here is the call graph for this function:

◆ endSafe()

INLINE const NodeGraphPartIteratorSafe & gum::NodeGraphPart::endSafe ( ) const
noexcept

the end iterator to parse the set of nodes contained in the NodeGraphPart

Definition at line 310 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

310  {
311  return _endIteratorSafe_;
312  }
NodeGraphPartIteratorSafe _endIteratorSafe_
the end iterator (used to speed-up parsings of the NodeGraphPart)
+ Here is the call graph for this function:

◆ eraseNode()

INLINE void gum::NodeGraphPart::eraseNode ( const NodeId  id)
virtual

erase the node with the given id

If the NodeGraphPart does not contain the nodeId, then nothing is done. In particular, no exception is raised. However, the signal onNodeDeleted is fired only if a node is effectively removed.

Reimplemented in gum::MixedGraph, gum::DiGraph, gum::UndiGraph, and gum::CliqueGraph.

Definition at line 279 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

279  {
280  if (!existsNode(node)) return;
281 
282  _addHole_(node);
283 
284  GUM_EMIT1(onNodeDeleted, node);
285  }
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:41
void _addHole_(NodeId id)
to add a hole.
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
Signaler1< NodeId > onNodeDeleted
+ Here is the call graph for this function:

◆ exists()

INLINE bool gum::NodeGraphPart::exists ( const NodeId  id) const

alias for existsNode

Definition at line 277 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

277 { return existsNode(node); }
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
+ Here is the call graph for this function:

◆ existsNode()

INLINE bool gum::NodeGraphPart::existsNode ( const NodeId  id) const

returns true iff the NodeGraphPart contains the given nodeId

Definition at line 271 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

271  {
272  if (node >= _boundVal_) return false;
273 
274  return (!_inHoles_(node));
275  }
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
bool _inHoles_(NodeId id) const
+ Here is the call graph for this function:

◆ listMapNodes()

template<typename VAL >
List< VAL > gum::NodeGraphPart::listMapNodes ( VAL(*)(const NodeId &)  f) const

a method to create a list of VAL from a set of nodes (using for every nodee, say x, the VAL f(x))

Parameters
fa function assigning a VAL to any node

◆ nextNodeId()

INLINE NodeId gum::NodeGraphPart::nextNodeId ( ) const

returns a new node id, not yet used by any node

Warning
a code like
id=nextNodeId();addNode(id);
is basically not thread safe !!
Returns
a node id not yet used by any node within the NodeGraphPart

Definition at line 211 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

211  {
212  NodeId next = 0;
213 
214  // return the first hole if holes exist
215  if (_holes_ && (!_holes_->empty()))
216  next = *(_holes_->begin());
217  else // in other case
218  next = _boundVal_;
219 
220  return next;
221  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:700
iterator begin() const
The usual unsafe begin iterator to parse the set.
Definition: set_tpl.h:498
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ nodes()

INLINE const NodeGraphPart & gum::NodeGraphPart::nodes ( ) const

return *this as a NodeGraphPart

Definition at line 352 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

352  {
353  return *(static_cast< const NodeGraphPart* >(this));
354  }
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
+ Here is the call graph for this function:

◆ nodesProperty() [1/2]

template<typename VAL >
NodeProperty< VAL > gum::NodeGraphPart::nodesProperty ( VAL(*)(const NodeId &)  f,
Size  size = 0 
) const

a method to create a HashTable with key:NodeId and value:VAL

VAL are computed from the nodes using for all node x, VAL f(x). This method is a wrapper of the same method in HashTable.

See also
HashTable::map.
Parameters
fa function assigning a VAL to any node
sizean optional parameter enabling to fine-tune the returned Property. Roughly speaking, it is a good practice to have a size equal to half the number of nodes. If you do not specify this parameter, the method will assign it for you.

◆ nodesProperty() [2/2]

template<typename VAL >
NodeProperty< VAL > gum::NodeGraphPart::nodesProperty ( const VAL &  a,
Size  size = 0 
) const

a method to create a hashMap with key:NodeId and value:VAL

for all nodes, the value stored is a. This method is a wrapper of the same method in HashTable.

See also
HashTable::map.
Parameters
athe default value assigned to each edge in the returned Property
sizean optional parameter enabling to fine-tune the returned Property. Roughly speaking, it is a good practice to have a size equal to half the number of nodes. If you do not specify this parameter, the method will assign it for you.

◆ operator!=()

INLINE bool gum::NodeGraphPart::operator!= ( const NodeGraphPart p) const

check whether two NodeGraphParts contain different nodes

Parameters
pthe NodeGraphPart to be compared with "this"

Definition at line 338 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

338 { return !operator==(p); }
bool operator==(const NodeGraphPart &p) const
check whether two NodeGraphParts contain the same nodes
+ Here is the call graph for this function:

◆ operator=()

INLINE NodeGraphPart & gum::NodeGraphPart::operator= ( const NodeGraphPart p)

copy operator

Parameters
pthe NodeGraphPart to be copied

Definition at line 204 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

204  {
205  // avoid self assignment
206  if (this != &p) { populateNodes(p); }
207 
208  return *this;
209  }
void populateNodes(const NodeGraphPart &s)
populateNodes clears *this and fills it with the same nodes as "s"
+ Here is the call graph for this function:

◆ operator==()

INLINE bool gum::NodeGraphPart::operator== ( const NodeGraphPart p) const

check whether two NodeGraphParts contain the same nodes

Parameters
pthe NodeGraphPart to be compared with "this"

Definition at line 324 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

324  {
325  if (_boundVal_ != p._boundVal_) return false;
326 
327  if (_holes_)
328  if (p._holes_)
329  return (*_holes_ == *p._holes_);
330  else
331  return false;
332  else if (p._holes_)
333  return false;
334 
335  return true;
336  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
+ Here is the call graph for this function:

◆ populateNodes()

void gum::NodeGraphPart::populateNodes ( const NodeGraphPart s)

populateNodes clears *this and fills it with the same nodes as "s"

populateNodes should basically be the preferred way to insert nodes with IDs not selected by the internal idFactory.

Parameters
sthe NodeGraphPart to be copied

Definition at line 63 of file nodeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

63  {
64  clear(); // "virtual" flush of the nodes set
65  _holes_size_ = s._holes_size_;
66  _holes_resize_policy_ = s._holes_resize_policy_;
67 
68  if (s._holes_) _holes_ = new NodeSet(*s._holes_);
69 
70  _boundVal_ = s._boundVal_;
71 
73  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
void _updateEndIteratorSafe_()
updating endIterator (always at max+1)
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Size _holes_size_
value for holes configuration
virtual void clear()
alias for clearNodes
bool _holes_resize_policy_
value for holes configuration
+ Here is the call graph for this function:

◆ populateNodesFromProperty()

template<typename T >
void gum::NodeGraphPart::populateNodesFromProperty ( const NodeProperty< T > &  h)

populateNodesFromProperty clears *this and fills it with the keys of "h"

populateNodes should basically be the preferred way to insert nodes with IDs not selected by the internal idFactory.

◆ size()

INLINE Size gum::NodeGraphPart::size ( ) const

alias for sizeNodes

Definition at line 269 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

269 { return sizeNodes(); }
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart
+ Here is the call graph for this function:

◆ sizeNodes()

INLINE Size gum::NodeGraphPart::sizeNodes ( ) const

returns the number of nodes in the NodeGraphPart

Definition at line 265 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

265  {
266  return (_holes_) ? (_boundVal_ - _holes_->size()) : _boundVal_;
267  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:694
+ Here is the call graph for this function:

◆ toString()

std::string gum::NodeGraphPart::toString ( ) const
virtual

a function to display the set of nodes

Reimplemented in gum::MixedGraph, gum::CliqueGraph, gum::DiGraph, and gum::UndiGraph.

Definition at line 104 of file nodeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

104  {
105  std::stringstream s;
106  bool first = true;
107  s << "{";
108 
109  for (NodeId id = 0; id < _boundVal_; ++id) {
110  if (_inHoles_(id)) continue;
111 
112  if (first) {
113  first = false;
114  } else {
115  s << ",";
116  }
117 
118  s << id;
119  }
120 
121  s << "}";
122 
123  return s.str();
124  }
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
bool _inHoles_(NodeId id) const
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

Friends And Related Function Documentation

◆ gum_tests::NodeGraphPartTestSuite

friend class gum_tests::NodeGraphPartTestSuite
friend

to enable testunits to use check

Definition at line 467 of file nodeGraphPart.h.

◆ NodeGraphPartIterator

friend class NodeGraphPartIterator
friend

Definition at line 462 of file nodeGraphPart.h.

◆ NodeGraphPartIteratorSafe

friend class NodeGraphPartIteratorSafe
friend

Definition at line 463 of file nodeGraphPart.h.

Member Data Documentation

◆ _boundVal_

NodeId gum::NodeGraphPart::_boundVal_
private

the id below which NodeIds may belong to the NodeGraphPart

Definition at line 511 of file nodeGraphPart.h.

◆ _endIteratorSafe_

NodeGraphPartIteratorSafe gum::NodeGraphPart::_endIteratorSafe_
private

the end iterator (used to speed-up parsings of the NodeGraphPart)

Definition at line 508 of file nodeGraphPart.h.

◆ _holes_

NodeSet* gum::NodeGraphPart::_holes_
private

the set of nodes not contained in the NodeGraphPart in the interval 1.

. max

Warning
holes may be nullptr.

Definition at line 499 of file nodeGraphPart.h.

◆ _holes_resize_policy_

bool gum::NodeGraphPart::_holes_resize_policy_
private

value for holes configuration

Definition at line 505 of file nodeGraphPart.h.

◆ _holes_size_

Size gum::NodeGraphPart::_holes_size_
private

value for holes configuration

Definition at line 502 of file nodeGraphPart.h.

◆ onNodeAdded

Signaler1< NodeId > gum::NodeGraphPart::onNodeAdded

Definition at line 271 of file nodeGraphPart.h.

◆ onNodeDeleted

Signaler1< NodeId > gum::NodeGraphPart::onNodeDeleted

Definition at line 272 of file nodeGraphPart.h.


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