CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Attributes
math::Graph< N, E > Class Template Reference

#include <Graph.h>

Classes

class  const_iterator
 
struct  value_type
 

Public Types

using adj_iterator = adj_list::iterator
 
using adj_list = std::vector< edge_list >
 
using const_adj_iterator = adj_list::const_iterator
 
using const_edge_iterator = edge_list::const_iterator
 
using const_edge_range = std::pair< const_edge_iterator, const_edge_iterator >
 
using const_indexer_iterator = typename indexer_type::const_iterator
 
using edge_iterator = edge_list::iterator
 
using edge_list = std::vector< edge_type >
 
using edge_range = std::pair< edge_iterator, edge_iterator >
 
using edge_store = std::vector< E >
 
using edge_type = std::pair< index_type, index_type >
 
using index_result = std::pair< index_type, bool >
 
using index_type = std::vector< double >::size_type
 
using indexer_iterator = typename indexer_type::iterator
 
using indexer_type = std::map< N, index_type >
 
using node_list = std::vector< N >
 

Public Member Functions

void addEdge (const N &from, const N &to, const E &edge)
 
index_type addNode (const N &)
 
adj_iterator begin ()
 
const_adj_iterator begin () const
 
const_iterator begin_iter () const
 
void clear ()
 it clear everything! More...
 
size_t edge_size () const
 
const E & edgeData (index_type i) const
 
edge_range edges (index_type nodeIndex)
 
const_edge_range edges (index_type nodeIndex) const
 
edge_range edges (const N &)
 
const_edge_range edges (const N &) const
 
adj_iterator end ()
 
const_adj_iterator end () const
 
const_iterator end_iter () const
 
void findRoots (edge_list &) const
 
 Graph ()
 
void invert (Graph &g) const
 
const NnodeData (const edge_type &) const
 
const NnodeData (index_type) const
 
const NnodeData (const const_adj_iterator &) const
 
index_result nodeIndex (const N &) const
 
bool replace (const N &oldNode, const N &newNode)
 
bool replaceEdge (const E &ldEdge, const E &newEdge)
 
auto size () const -> adj_list::size_type
 
void swap (Graph< N, E > &)
 
 ~Graph ()
 

Private Attributes

adj_list adjl_
 
edge_store edges_
 
edge_list emptyEdges_
 
indexer_type indexer_
 
node_list nodes_
 

Detailed Description

template<class N, class E>
class math::Graph< N, E >

Definition at line 13 of file Graph.h.

Member Typedef Documentation

◆ adj_iterator

template<class N, class E>
using math::Graph< N, E >::adj_iterator = adj_list::iterator

Definition at line 104 of file Graph.h.

◆ adj_list

template<class N, class E>
using math::Graph< N, E >::adj_list = std::vector<edge_list>

Definition at line 21 of file Graph.h.

◆ const_adj_iterator

template<class N, class E>
using math::Graph< N, E >::const_adj_iterator = adj_list::const_iterator

Definition at line 105 of file Graph.h.

◆ const_edge_iterator

template<class N, class E>
using math::Graph< N, E >::const_edge_iterator = edge_list::const_iterator

Definition at line 114 of file Graph.h.

◆ const_edge_range

template<class N, class E>
using math::Graph< N, E >::const_edge_range = std::pair<const_edge_iterator, const_edge_iterator>

Definition at line 116 of file Graph.h.

◆ const_indexer_iterator

template<class N, class E>
using math::Graph< N, E >::const_indexer_iterator = typename indexer_type::const_iterator

Definition at line 110 of file Graph.h.

◆ edge_iterator

template<class N, class E>
using math::Graph< N, E >::edge_iterator = edge_list::iterator

Definition at line 113 of file Graph.h.

◆ edge_list

template<class N, class E>
using math::Graph< N, E >::edge_list = std::vector<edge_type>

Definition at line 19 of file Graph.h.

◆ edge_range

template<class N, class E>
using math::Graph< N, E >::edge_range = std::pair<edge_iterator, edge_iterator>

Definition at line 115 of file Graph.h.

◆ edge_store

template<class N, class E>
using math::Graph< N, E >::edge_store = std::vector<E>

Definition at line 101 of file Graph.h.

◆ edge_type

template<class N, class E>
using math::Graph< N, E >::edge_type = std::pair<index_type, index_type>

Definition at line 17 of file Graph.h.

◆ index_result

template<class N, class E>
using math::Graph< N, E >::index_result = std::pair<index_type, bool>

Definition at line 117 of file Graph.h.

◆ index_type

template<class N, class E>
using math::Graph< N, E >::index_type = std::vector<double>::size_type

Definition at line 15 of file Graph.h.

◆ indexer_iterator

template<class N, class E>
using math::Graph< N, E >::indexer_iterator = typename indexer_type::iterator

Definition at line 109 of file Graph.h.

◆ indexer_type

template<class N, class E>
using math::Graph< N, E >::indexer_type = std::map<N, index_type>

Definition at line 108 of file Graph.h.

◆ node_list

template<class N, class E>
using math::Graph< N, E >::node_list = std::vector<N>

Definition at line 100 of file Graph.h.

Constructor & Destructor Documentation

◆ Graph()

template<class N, class E>
math::Graph< N, E >::Graph ( )
inline

Definition at line 121 of file Graph.h.

121 : edges_(1) {}
edge_store edges_
Definition: Graph.h:195

◆ ~Graph()

template<class N, class E>
math::Graph< N, E >::~Graph ( )
inline

Definition at line 122 of file Graph.h.

122 {}

Member Function Documentation

◆ addEdge()

template<class N, class E>
void math::Graph< N, E >::addEdge ( const N from,
const N to,
const E &  edge 
)

Definition at line 231 of file Graph.h.

Referenced by DDCompactViewImpl::position().

231  {
232  index_type iFrom = addNode(from);
233  index_type iTo = addNode(to);
234 
235  adjl_[iFrom].emplace_back(edge_type(iTo, edges_.size()));
236  edges_.emplace_back(edge);
237  }
edge_store edges_
Definition: Graph.h:195
std::vector< double >::size_type index_type
Definition: Graph.h:15
index_type addNode(const N &)
Definition: Graph.h:205
std::pair< index_type, index_type > edge_type
Definition: Graph.h:17
adj_list adjl_
Definition: Graph.h:189

◆ addNode()

template<class N, class E >
Graph< N, E >::index_type math::Graph< N, E >::addNode ( const N node)

Definition at line 205 of file Graph.h.

205  {
206  index_type idx = indexer_.size(); // +1;
207  std::pair<indexer_iterator, bool> result = indexer_.insert(typename indexer_type::value_type(node, idx));
208 
209  if (result.second) { // new index!
210  nodes_.emplace_back(node);
211  adjl_.emplace_back(edge_list());
212  } else {
213  idx = result.first->second;
214  }
215  return idx;
216  }
node_list nodes_
Definition: Graph.h:192
std::vector< double >::size_type index_type
Definition: Graph.h:15
std::vector< edge_type > edge_list
Definition: Graph.h:19
indexer_type indexer_
Definition: Graph.h:198
adj_list adjl_
Definition: Graph.h:189

◆ begin() [1/2]

template<class N, class E>
adj_iterator math::Graph< N, E >::begin ( void  )
inline

Definition at line 172 of file Graph.h.

Referenced by TinyDomTest::allNodes(), TinyDomTest2::allNodes(), and GeometryInfoDump::dumpInfo().

172 { return adjl_.begin(); }
adj_list adjl_
Definition: Graph.h:189

◆ begin() [2/2]

template<class N, class E>
const_adj_iterator math::Graph< N, E >::begin ( void  ) const
inline

Definition at line 173 of file Graph.h.

173 { return adjl_.begin(); }
adj_list adjl_
Definition: Graph.h:189

◆ begin_iter()

template<class N, class E>
const_iterator math::Graph< N, E >::begin_iter ( ) const
inline

Definition at line 165 of file Graph.h.

165 { return const_iterator(*this); }

◆ clear()

template<class N , class E >
void math::Graph< N, E >::clear ( void  )

it clear everything!

Definition at line 338 of file Graph.h.

Referenced by BeautifulSoup.Tag::setString().

338  {
339  adjl_.clear();
340  nodes_.clear();
341  edges_.clear();
342  indexer_.clear();
343  }
edge_store edges_
Definition: Graph.h:195
node_list nodes_
Definition: Graph.h:192
indexer_type indexer_
Definition: Graph.h:198
adj_list adjl_
Definition: Graph.h:189

◆ edge_size()

template<class N, class E>
size_t math::Graph< N, E >::edge_size ( ) const
inline

Definition at line 169 of file Graph.h.

169 { return edges_.size(); }
edge_store edges_
Definition: Graph.h:195

◆ edgeData()

template<class N, class E>
const E& math::Graph< N, E >::edgeData ( index_type  i) const
inline

◆ edges() [1/4]

template<class N , class E >
Graph< N, E >::edge_range math::Graph< N, E >::edges ( index_type  nodeIndex)
inline

Definition at line 240 of file Graph.h.

Referenced by DDCompactViewImpl::~DDCompactViewImpl().

240  {
242  return edge_range(edges.begin(), edges.end());
243  }
edge_range edges(index_type nodeIndex)
Definition: Graph.h:240
std::pair< edge_iterator, edge_iterator > edge_range
Definition: Graph.h:115
index_result nodeIndex(const N &) const
Definition: Graph.h:219
std::vector< edge_type > edge_list
Definition: Graph.h:19
adj_list adjl_
Definition: Graph.h:189

◆ edges() [2/4]

template<class N , class E >
Graph< N, E >::const_edge_range math::Graph< N, E >::edges ( index_type  nodeIndex) const
inline

Definition at line 246 of file Graph.h.

246  {
247  const edge_list &edges = adjl_[nodeIndex];
248  return const_edge_range(edges.begin(), edges.end());
249  }
edge_range edges(index_type nodeIndex)
Definition: Graph.h:240
std::pair< const_edge_iterator, const_edge_iterator > const_edge_range
Definition: Graph.h:116
index_result nodeIndex(const N &) const
Definition: Graph.h:219
std::vector< edge_type > edge_list
Definition: Graph.h:19
adj_list adjl_
Definition: Graph.h:189

◆ edges() [3/4]

template<class N, class E >
Graph< N, E >::edge_range math::Graph< N, E >::edges ( const N node)
inline

Definition at line 252 of file Graph.h.

252  {
253  index_result idxResult = nodeIndex(node);
254  edge_range result(emptyEdges_.begin(), emptyEdges_.end());
255  if (idxResult.second) {
256  result = edges(idxResult.first);
257  }
258  return result;
259  }
edge_range edges(index_type nodeIndex)
Definition: Graph.h:240
std::pair< index_type, bool > index_result
Definition: Graph.h:117
std::pair< edge_iterator, edge_iterator > edge_range
Definition: Graph.h:115
edge_list emptyEdges_
Definition: Graph.h:201
index_result nodeIndex(const N &) const
Definition: Graph.h:219

◆ edges() [4/4]

template<class N, class E >
Graph< N, E >::const_edge_range math::Graph< N, E >::edges ( const N node) const
inline

Definition at line 262 of file Graph.h.

262  {
263  index_result idxResult = nodeIndex(node);
265  if (idxResult.second) {
266  result = edges(idxResult.first);
267  }
268  return result;
269  }
edge_range edges(index_type nodeIndex)
Definition: Graph.h:240
std::pair< const_edge_iterator, const_edge_iterator > const_edge_range
Definition: Graph.h:116
std::pair< index_type, bool > index_result
Definition: Graph.h:117
edge_list emptyEdges_
Definition: Graph.h:201
index_result nodeIndex(const N &) const
Definition: Graph.h:219

◆ end() [1/2]

template<class N, class E>
adj_iterator math::Graph< N, E >::end ( void  )
inline

Definition at line 174 of file Graph.h.

Referenced by TinyDomTest::allNodes(), TinyDomTest2::allNodes(), Types.LuminosityBlockRange::cppID(), and Types.EventRange::cppID().

174 { return adjl_.end(); }
adj_list adjl_
Definition: Graph.h:189

◆ end() [2/2]

template<class N, class E>
const_adj_iterator math::Graph< N, E >::end ( void  ) const
inline

Definition at line 175 of file Graph.h.

Referenced by Types.LuminosityBlockRange::cppID(), and Types.EventRange::cppID().

175 { return adjl_.end(); }
adj_list adjl_
Definition: Graph.h:189

◆ end_iter()

template<class N, class E>
const_iterator math::Graph< N, E >::end_iter ( ) const
inline

Definition at line 167 of file Graph.h.

167 { return const_iterator(*this, adjl_.size(), 0); }
adj_list adjl_
Definition: Graph.h:189

◆ findRoots()

template<class N , class E >
void math::Graph< N, E >::findRoots ( edge_list result) const

Definition at line 287 of file Graph.h.

287  {
288  result.clear();
289 
290  const_adj_iterator it = begin();
291  const_adj_iterator ed = end();
292  std::vector<bool> rootCandidate(size(), true);
293 
294  for (; it != ed; ++it) {
295  const edge_list &el = *it;
296  for (auto const &el_it : el) {
297  rootCandidate[el_it.first] = false;
298  }
299  }
301  std::vector<bool>::size_type v_ed = rootCandidate.size();
302  for (; v_sz < v_ed; ++v_sz) {
303  if (rootCandidate[v_sz]) {
304  result.emplace_back(edge_type(v_sz, 0));
305  }
306  }
307  }
auto size() const -> adj_list::size_type
Definition: Graph.h:176
uint16_t size_type
std::pair< index_type, index_type > edge_type
Definition: Graph.h:17
adj_iterator end()
Definition: Graph.h:174
std::vector< edge_type > edge_list
Definition: Graph.h:19
adj_iterator begin()
Definition: Graph.h:172
adj_list::const_iterator const_adj_iterator
Definition: Graph.h:105

◆ invert()

template<class N , class E >
void math::Graph< N, E >::invert ( Graph< N, E > &  g) const

Definition at line 346 of file Graph.h.

346  {
347  adj_list::size_type it = 0;
348  adj_list::size_type ed = adjl_.size();
349  // loop over adjacency-list of this Graph
350  for (; it < ed; ++it) {
351  const edge_list &el = adjl_[it];
352  edge_list::size_type eit = 0;
353  edge_list::size_type eed = el.size();
354  // loop over edges of current node
355  for (; eit < eed; ++eit) {
356  const edge_type &e = el[eit];
357  g.addEdge(nodeData(e.first), nodeData(it), edgeData(e.second));
358  }
359  }
360  }
const N & nodeData(const edge_type &) const
Definition: Graph.h:272
uint16_t size_type
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
std::pair< index_type, index_type > edge_type
Definition: Graph.h:17
std::vector< edge_type > edge_list
Definition: Graph.h:19
const E & edgeData(index_type i) const
Definition: Graph.h:158
adj_list adjl_
Definition: Graph.h:189

◆ nodeData() [1/3]

template<class N , class E >
const N & math::Graph< N, E >::nodeData ( const edge_type edge) const
inline

◆ nodeData() [2/3]

template<class N , class E >
const N & math::Graph< N, E >::nodeData ( index_type  i) const
inline

Definition at line 277 of file Graph.h.

277  {
278  return nodes_[i];
279  }
node_list nodes_
Definition: Graph.h:192

◆ nodeData() [3/3]

template<class N , class E >
const N & math::Graph< N, E >::nodeData ( const const_adj_iterator it) const
inline

Definition at line 282 of file Graph.h.

282  {
283  return nodes_[it - adjl_.begin()];
284  }
node_list nodes_
Definition: Graph.h:192
adj_list adjl_
Definition: Graph.h:189

◆ nodeIndex()

template<class N, class E >
Graph< N, E >::index_result math::Graph< N, E >::nodeIndex ( const N node) const
inline

Definition at line 219 of file Graph.h.

219  {
220  typename indexer_type::const_iterator result = indexer_.find(node);
221  index_type idx = 0;
222  bool flag = false;
223  if (result != indexer_.end()) {
224  flag = true;
225  idx = result->second;
226  }
227  return index_result(idx, flag);
228  }
std::vector< double >::size_type index_type
Definition: Graph.h:15
std::pair< index_type, bool > index_result
Definition: Graph.h:117
indexer_type indexer_
Definition: Graph.h:198

◆ replace()

template<class N, class E >
bool math::Graph< N, E >::replace ( const N oldNode,
const N newNode 
)

Definition at line 310 of file Graph.h.

310  {
311  typename indexer_type::iterator it = indexer_.find(oldNode);
312  if (it != indexer_.end()) {
313  index_type oldIndex = it->second;
314  nodes_[oldIndex] = newNode;
315  indexer_[newNode] = oldIndex;
316  indexer_.erase(it);
317  } else
318  throw(oldNode);
319  return true;
320  }
node_list nodes_
Definition: Graph.h:192
std::vector< double >::size_type index_type
Definition: Graph.h:15
indexer_type indexer_
Definition: Graph.h:198

◆ replaceEdge()

template<class N , class E>
bool math::Graph< N, E >::replaceEdge ( const E &  ldEdge,
const E &  newEdge 
)

Definition at line 323 of file Graph.h.

323  {
324  typename edge_store::size_type it = 0;
325  typename edge_store::size_type ed = edges_.size();
326  bool result = false;
327  for (; it < ed; ++it) {
328  if (edges_[it] == oldEdge) {
329  result = true;
330  edges_[it] = newEdge;
331  break;
332  }
333  }
334  return result;
335  }
edge_store edges_
Definition: Graph.h:195
uint16_t size_type

◆ size()

template<class N, class E>
auto math::Graph< N, E >::size ( void  ) const -> adj_list::size_type
inline

◆ swap()

template<class N, class E>
void math::Graph< N, E >::swap ( Graph< N, E > &  g)

Definition at line 363 of file Graph.h.

Referenced by DDCompactViewImpl::swap().

363  {
364  adjl_.swap(g.adjl_);
365  nodes_.swap(g.nodes_);
366  edges_.swap(g.edges_);
367  indexer_.swap(g.indexer_);
368  emptyEdges_.swap(g.emptyEdges_);
369  }
edge_store edges_
Definition: Graph.h:195
node_list nodes_
Definition: Graph.h:192
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
edge_list emptyEdges_
Definition: Graph.h:201
indexer_type indexer_
Definition: Graph.h:198
adj_list adjl_
Definition: Graph.h:189

Member Data Documentation

◆ adjl_

template<class N, class E>
adj_list math::Graph< N, E >::adjl_
private

◆ edges_

template<class N, class E>
edge_store math::Graph< N, E >::edges_
private

◆ emptyEdges_

template<class N, class E>
edge_list math::Graph< N, E >::emptyEdges_
private

Definition at line 201 of file Graph.h.

◆ indexer_

template<class N, class E>
indexer_type math::Graph< N, E >::indexer_
private

Definition at line 198 of file Graph.h.

◆ nodes_

template<class N, class E>
node_list math::Graph< N, E >::nodes_
private

Definition at line 192 of file Graph.h.