From d29479e93370b577adeeb133116ced99dc4f81ff Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Thu, 5 Jan 2017 13:38:51 -0500 Subject: Refactor - Reorder includes - Unify reference style - Improve whitespace --- src/brandes.cc | 18 +++++++++--------- src/dependency_calculator.h | 9 +++++---- src/graph.h | 6 +++--- src/parse.h | 8 +++++--- 4 files changed, 22 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/brandes.cc b/src/brandes.cc index 5060a9d..7d12ec6 100644 --- a/src/brandes.cc +++ b/src/brandes.cc @@ -1,13 +1,13 @@ -#include #include #include -#include -#include #include +#include +#include +#include -#include "parse.h" -#include "graph.h" #include "dependency_calculator.h" +#include "graph.h" +#include "parse.h" int threads; std::string input_file; @@ -16,9 +16,10 @@ std::string output_file; Graph graph; std::unordered_map betweenness; std::queue vertices_to_process; + +std::vector threads_list; std::mutex queue_mutex; std::mutex betweenness_mutex; -std::vector threads_list; void parse_args(int argc, char *argv[]) { if (argc < 4) { @@ -50,13 +51,12 @@ int next_vertex() { if (vertices_to_process.empty()) { return -1; } - int vertex; - vertex = vertices_to_process.front(); + int vertex = vertices_to_process.front(); vertices_to_process.pop(); return vertex; } -void update_betweenness(int vertex, DependencyCalculator & dc) { +void update_betweenness(int vertex, DependencyCalculator& dc) { std::lock_guard lock(betweenness_mutex); for (int v : graph.get_vertices()) { if (v != vertex ) { diff --git a/src/dependency_calculator.h b/src/dependency_calculator.h index be6aeb7..93a751e 100644 --- a/src/dependency_calculator.h +++ b/src/dependency_calculator.h @@ -1,16 +1,16 @@ #ifndef DEPENDENCY_CALCULATOR_H #define DEPENDENCY_CALCULATOR_H -#include #include -#include +#include #include +#include #include "graph.h" class DependencyCalculator { public: - DependencyCalculator(const Graph &graph, int vertex) : graph_(graph), + DependencyCalculator(const Graph& graph, int vertex) : graph_(graph), vertex_(vertex) { init_(); find_shortest_paths_(); @@ -21,7 +21,7 @@ public: return dependency_.find(vertex)->second; } private: - const Graph &graph_; // (V, E) + const Graph& graph_; // (V, E) int vertex_; // s std::stack stack_; // S std::unordered_map> shortest_path_predecessors_; // P @@ -67,6 +67,7 @@ private: while (!stack_.empty()) { int vertex = stack_.top(); stack_.pop(); + for (int predecessor : shortest_path_predecessors_[vertex]) { double shortest_path_ratio = (double) shortest_paths_[predecessor] / diff --git a/src/graph.h b/src/graph.h index 47dce16..317024e 100644 --- a/src/graph.h +++ b/src/graph.h @@ -29,16 +29,16 @@ public: std::sort(orderable_vertices_.begin(), orderable_vertices_.end()); } - const std::vector & get_vertices() const { + const std::vector& get_vertices() const { return orderable_vertices_; } - const std::vector & get_neighbors(int vertex) const { + const std::vector& get_neighbors(int vertex) const { return graph_.find(vertex)->second; } bool has_out_edges(int vertex) const { - return has_out_edges_.count(vertex) > 0; + return has_out_edges_.find(vertex) == has_out_edges_.end(); } private: diff --git a/src/parse.h b/src/parse.h index 1d37083..31fa7c6 100644 --- a/src/parse.h +++ b/src/parse.h @@ -2,9 +2,9 @@ #define PARSE_H #include -#include #include #include + #include "graph.h" class Parser { @@ -17,7 +17,7 @@ public: graph_.sort_vertices(); } - const Graph & get_graph() { + const Graph& get_graph() { return graph_; } private: @@ -25,9 +25,11 @@ private: std::ifstream input_file_; void parse_edge_(std::string edge) { - int from, to; std::stringstream sstream(edge); + + int from, to; sstream >> from >> to; + graph_.add_edge(from, to); } }; -- cgit v1.2.3