Skip to content

Commit

Permalink
Added function for get NodeVector and EdgeVector
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigRazor committed Dec 2, 2024
1 parent 71a2b64 commit 6767c01
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
27 changes: 27 additions & 0 deletions include/CXXGraph/Graph/Graph_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
Expand Down Expand Up @@ -60,9 +61,15 @@ using shared = std::shared_ptr<T>;
template <typename T>
using T_EdgeSet = std::unordered_set<shared<const Edge<T>>, edgeHash<T>>;

template <typename T>
using T_EdgeVector = std::vector<shared<const Edge<T>>>;

template <typename T>
using T_NodeSet = std::unordered_set<shared<const Node<T>>, nodeHash<T>>;

template <typename T>
using T_NodeVector = std::vector<shared<const Node<T>>>;

template <typename T>
class Graph;

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

/**
* \brief
* Function that return the Edge set of the Graph
* Note: No Thread Safe
*
* @returns a list of Edges of the graph
*
*/
virtual T_EdgeVector<T> getEdgeVector() const;

/**
* \brief
* Function set the Edge Set of the Graph
Expand Down Expand Up @@ -278,6 +295,16 @@ class Graph {
*/
virtual const T_NodeSet<T> getNodeSet() const;

/**
* \brief
* Function that return the Node Set of the Graph
* Note: No Thread Safe
*
* @returns a list of Nodes of the graph
*
*/
virtual const T_NodeVector<T> getNodeVector() const;

/**
* \brief
* Function that return the Set of isolated nodes
Expand Down
17 changes: 17 additions & 0 deletions include/CXXGraph/Graph/Graph_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ const T_EdgeSet<T> &Graph<T>::getEdgeSet() const {
return edgeSet;
}

template <typename T>
T_EdgeVector<T> Graph<T>::getEdgeVector() const {
T_EdgeVector<T> edgeVector(edgeSet.begin(), edgeSet.end());
return edgeVector;
}

template <typename T>
void Graph<T>::setEdgeSet(const T_EdgeSet<T> &edgeSet) {
this->edgeSet.clear();
Expand Down Expand Up @@ -311,6 +317,17 @@ const T_NodeSet<T> Graph<T>::getNodeSet() const {
return nodeSet;
}

template <typename T>
const T_NodeVector<T> Graph<T>::getNodeVector() const {
auto &nodeSet = getNodeSet();
T_NodeVector<T> nodeVector(nodeSet.begin(), nodeSet.end());
// Merge with the isolated nodes
nodeVector.insert(nodeVector.end(), this->isolatedNodesSet.begin(),
this->isolatedNodesSet.end());

return nodeVector;
}

template <typename T>
const T_NodeSet<T> Graph<T>::getIsolatedNodeSet() const {
return isolatedNodesSet;
Expand Down

0 comments on commit 6767c01

Please sign in to comment.