GraphLibrary  0.0.1
A simple library that implements various graph algorithms.
 All Classes Namespaces Files Functions Variables Typedefs Macros
Degrees.hpp
Go to the documentation of this file.
1 #ifndef GL_DEGREES_HPP
2 #define GL_DEGREES_HPP
3 
4 #include "../structures/Graph.hpp"
5 
6 namespace gl {
7 namespace algorithm {
8 
15 template <class Graph>
16 typename Graph::idx_list_t degrees (const Graph& graph) {
17  typename Graph::idx_list_t out(graph.numNodes()); // degree node list
18 
19  for (typename Graph::idx_t node = 0; node < graph.numNodes(); ++node) {
20  out[node] = graph.getNodeDegree(node);
21  }
22  return out;
23 }
24 
25 } // namespace algorithm
26 } // namespace gl
27 
28 #endif // GL_DEGREES_HPP
std::vector< idx_t > idx_list_t
Index List type.
Definition: Graph.hpp:48
gl::index_type idx_t
Index type.
Definition: Graph.hpp:44
Stores and implements a Graph.
Definition: Graph.hpp:39
Graph::idx_list_t degrees(const Graph &graph)
Computes the out-degrees of all nodes in a graph.
Definition: Degrees.hpp:16
idx_t numNodes() const
Returns the number of nodes currently in the graph.
Definition: Graph.hpp:406
idx_t getNodeDegree(const idx_t &id) const
Finds the degree of the given node (i.e. count of all in- & outgoing edges).
Definition: Graph.hpp:1285