m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-01-06 16:55:23 -0500
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-01-06 16:55:23 -0500
commitdf2c6a608a5b238e7b2e5265e05e48535e036263 (patch)
tree738e18a6a63389d3e67cdc04655ed93a0e0704cf /src
parented0ac6791435c36e8374b218454ebfa7485f0845 (diff)
Refactor
- Remove unnecessary include - Improve whitespace - Remove unnecessary variable declaration - Move function call to more logical place
Diffstat (limited to 'src')
-rw-r--r--src/brandes.cc7
-rw-r--r--src/dependency_calculator.h2
-rw-r--r--src/graph.h1
-rw-r--r--src/parse.h4
4 files changed, 10 insertions, 4 deletions
diff --git a/src/brandes.cc b/src/brandes.cc
index c4c14cd..2d81610 100644
--- a/src/brandes.cc
+++ b/src/brandes.cc
@@ -48,16 +48,20 @@ void init() {
int next_vertex() {
std::lock_guard<std::mutex> lock(queue_mutex);
+
if (vertices_to_process.empty()) {
return -1;
}
+
int vertex = vertices_to_process.front();
vertices_to_process.pop();
+
return vertex;
}
void update_betweenness(int vertex, DependencyCalculator& dc) {
std::lock_guard<std::mutex> lock(betweenness_mutex);
+
for (int v = 0; v < graph.get_number_vertices(); v++) {
if (v != vertex ) {
betweenness[v] += dc.get_dependency(v);
@@ -90,7 +94,8 @@ void print_betweenness() {
for (int vertex = 0; vertex < graph.get_number_vertices(); vertex++) {
if (graph.has_out_edges(vertex)) {
- fout << graph.get_real_vertex(vertex) << " " << betweenness[vertex] << std::endl;
+ fout << graph.get_real_vertex(vertex) << " "
+ << betweenness[vertex] << std::endl;
}
}
}
diff --git a/src/dependency_calculator.h b/src/dependency_calculator.h
index c24f5ef..6141a82 100644
--- a/src/dependency_calculator.h
+++ b/src/dependency_calculator.h
@@ -3,7 +3,6 @@
#include <queue>
#include <stack>
-#include <unordered_map>
#include <vector>
#include "graph.h"
@@ -23,6 +22,7 @@ public:
private:
const Graph& graph_; // (V, E)
int vertex_; // s
+
std::stack<int> stack_; // S
std::vector<std::vector<int>> shortest_path_predecessors_; // P
std::vector<int> shortest_paths_; // sigma
diff --git a/src/graph.h b/src/graph.h
index 85c66e7..7978c95 100644
--- a/src/graph.h
+++ b/src/graph.h
@@ -14,6 +14,7 @@ public:
if (vertices_.find(vertex) == vertices_.end()) {
vertices_.insert(vertex);
orderable_vertices_.push_back(vertex);
+
graph_.push_back(std::vector<int>());
has_out_edges_.push_back(false);
number_vertices_++;
diff --git a/src/parse.h b/src/parse.h
index 095232a..2265618 100644
--- a/src/parse.h
+++ b/src/parse.h
@@ -10,10 +10,8 @@
class Parser {
public:
Parser(std::string filename) : graph_(), input_file_(filename) {
- std::string edge;
read_file_();
add_vertices_();
- graph_.done_with_vertices();
add_edges_();
}
@@ -46,6 +44,8 @@ private:
graph_.add_vertex(edge.first);
graph_.add_vertex(edge.second);
}
+
+ graph_.done_with_vertices();
}
void add_edges_() {