Skip to content

Commit 6767c01

Browse files
committed
Added function for get NodeVector and EdgeVector
1 parent 71a2b64 commit 6767c01

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

include/CXXGraph/Graph/Graph_decl.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <cmath>
2626
#include <cstring>
27+
#include <deque>
2728
#include <fstream>
2829
#include <functional>
2930
#include <iostream>
@@ -60,9 +61,15 @@ using shared = std::shared_ptr<T>;
6061
template <typename T>
6162
using T_EdgeSet = std::unordered_set<shared<const Edge<T>>, edgeHash<T>>;
6263

64+
template <typename T>
65+
using T_EdgeVector = std::vector<shared<const Edge<T>>>;
66+
6367
template <typename T>
6468
using T_NodeSet = std::unordered_set<shared<const Node<T>>, nodeHash<T>>;
6569

70+
template <typename T>
71+
using T_NodeVector = std::vector<shared<const Node<T>>>;
72+
6673
template <typename T>
6774
class Graph;
6875

@@ -125,6 +132,16 @@ class Graph {
125132
*/
126133
virtual const T_EdgeSet<T> &getEdgeSet() const;
127134

135+
/**
136+
* \brief
137+
* Function that return the Edge set of the Graph
138+
* Note: No Thread Safe
139+
*
140+
* @returns a list of Edges of the graph
141+
*
142+
*/
143+
virtual T_EdgeVector<T> getEdgeVector() const;
144+
128145
/**
129146
* \brief
130147
* Function set the Edge Set of the Graph
@@ -278,6 +295,16 @@ class Graph {
278295
*/
279296
virtual const T_NodeSet<T> getNodeSet() const;
280297

298+
/**
299+
* \brief
300+
* Function that return the Node Set of the Graph
301+
* Note: No Thread Safe
302+
*
303+
* @returns a list of Nodes of the graph
304+
*
305+
*/
306+
virtual const T_NodeVector<T> getNodeVector() const;
307+
281308
/**
282309
* \brief
283310
* Function that return the Set of isolated nodes

include/CXXGraph/Graph/Graph_impl.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ const T_EdgeSet<T> &Graph<T>::getEdgeSet() const {
5959
return edgeSet;
6060
}
6161

62+
template <typename T>
63+
T_EdgeVector<T> Graph<T>::getEdgeVector() const {
64+
T_EdgeVector<T> edgeVector(edgeSet.begin(), edgeSet.end());
65+
return edgeVector;
66+
}
67+
6268
template <typename T>
6369
void Graph<T>::setEdgeSet(const T_EdgeSet<T> &edgeSet) {
6470
this->edgeSet.clear();
@@ -311,6 +317,17 @@ const T_NodeSet<T> Graph<T>::getNodeSet() const {
311317
return nodeSet;
312318
}
313319

320+
template <typename T>
321+
const T_NodeVector<T> Graph<T>::getNodeVector() const {
322+
auto &nodeSet = getNodeSet();
323+
T_NodeVector<T> nodeVector(nodeSet.begin(), nodeSet.end());
324+
// Merge with the isolated nodes
325+
nodeVector.insert(nodeVector.end(), this->isolatedNodesSet.begin(),
326+
this->isolatedNodesSet.end());
327+
328+
return nodeVector;
329+
}
330+
314331
template <typename T>
315332
const T_NodeSet<T> Graph<T>::getIsolatedNodeSet() const {
316333
return isolatedNodesSet;

0 commit comments

Comments
 (0)