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 (const N &)
 
const_edge_range edges (const N &) const
 
edge_range edges (index_type nodeIndex)
 
const_edge_range edges (index_type nodeIndex) 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 const_adj_iterator &) const
 
const NnodeData (const edge_type &) const
 
const NnodeData (index_type) 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) {}

◆ ~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.

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  }

Referenced by DDCompactViewImpl::position().

◆ 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  }

◆ 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.

172 { return adjl_.begin(); }

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

◆ 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(); }

◆ 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.

338  {
339  adjl_.clear();
340  nodes_.clear();
341  edges_.clear();
342  indexer_.clear();
343  }

Referenced by BeautifulSoup.Tag::setString().

◆ 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(); }

◆ 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 ( 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  }

◆ edges() [2/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  }

◆ edges() [3/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.

240  {
242  return edge_range(edges.begin(), edges.end());
243  }

Referenced by DDCompactViewImpl::~DDCompactViewImpl().

◆ edges() [4/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  }

◆ end() [1/2]

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

◆ 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.

175 { return adjl_.end(); }

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

◆ 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); }

◆ 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  }

◆ 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  }

◆ nodeData() [1/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  }

◆ nodeData() [2/3]

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

◆ nodeData() [3/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  }

◆ 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  }

◆ 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  }

◆ 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  }

◆ 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.

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  }

Referenced by DDCompactViewImpl::swap().

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.

math::Graph::index_result
std::pair< index_type, bool > index_result
Definition: Graph.h:117
math::Graph::edges_
edge_store edges_
Definition: Graph.h:195
mps_fire.i
i
Definition: mps_fire.py:428
math::Graph::addNode
index_type addNode(const N &)
Definition: Graph.h:205
math::Graph::edge_type
std::pair< index_type, index_type > edge_type
Definition: Graph.h:17
math::Graph::nodes_
node_list nodes_
Definition: Graph.h:192
to
math::Graph::adjl_
adj_list adjl_
Definition: Graph.h:189
math::Graph::indexer_
indexer_type indexer_
Definition: Graph.h:198
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
math::Graph::edge_list
std::vector< edge_type > edge_list
Definition: Graph.h:19
math::Graph::nodeIndex
index_result nodeIndex(const N &) const
Definition: Graph.h:219
math::Graph::size
auto size() const -> adj_list::size_type
Definition: Graph.h:176
math::Graph::emptyEdges_
edge_list emptyEdges_
Definition: Graph.h:201
math::Graph::edgeData
const E & edgeData(index_type i) const
Definition: Graph.h:158
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
math::Graph::begin
adj_iterator begin()
Definition: Graph.h:172
math::Graph::const_edge_range
std::pair< const_edge_iterator, const_edge_iterator > const_edge_range
Definition: Graph.h:116
math::Graph::index_type
std::vector< double >::size_type index_type
Definition: Graph.h:15
math::Graph::end
adj_iterator end()
Definition: Graph.h:174
mps_fire.result
result
Definition: mps_fire.py:311
math::Graph::edges
edge_range edges(index_type nodeIndex)
Definition: Graph.h:240
math::Graph::nodeData
const N & nodeData(const edge_type &) const
Definition: Graph.h:272
math::Graph::edge_range
std::pair< edge_iterator, edge_iterator > edge_range
Definition: Graph.h:115
g
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
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
math::Graph::const_adj_iterator
adj_list::const_iterator const_adj_iterator
Definition: Graph.h:105