m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/dependency_calculator.h
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-01-06 15:57:28 -0500
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-01-06 15:57:28 -0500
commited0ac6791435c36e8374b218454ebfa7485f0845 (patch)
tree4b0b48afa48f9e09ef9ab1f9ba27f68f9f118840 /src/dependency_calculator.h
parentdc88e19199f056d6f2e17c481737a71fcab70398 (diff)
Optimalize by using vectors over maps and sets
- Can iterate over vertices with for (int v = 0; v < number_vertices; v++) loop - This required internally remapping the vertices from their actual names to 0, 1, ..., number_vertices - 1. - Use Graph::get_real_vertex(vertex) to get original value
Diffstat (limited to 'src/dependency_calculator.h')
-rw-r--r--src/dependency_calculator.h20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/dependency_calculator.h b/src/dependency_calculator.h
index 93a751e..c24f5ef 100644
--- a/src/dependency_calculator.h
+++ b/src/dependency_calculator.h
@@ -18,24 +18,24 @@ public:
}
double get_dependency(int vertex) const {
- return dependency_.find(vertex)->second;
+ return dependency_[vertex];
}
private:
const Graph& graph_; // (V, E)
int vertex_; // s
std::stack<int> stack_; // S
- std::unordered_map<int, std::vector<int>> shortest_path_predecessors_; // P
- std::unordered_map<int, int> shortest_paths_; // sigma
- std::unordered_map<int, int> distance_; // d
+ std::vector<std::vector<int>> shortest_path_predecessors_; // P
+ std::vector<int> shortest_paths_; // sigma
+ std::vector<int> distance_; // d
std::queue<int> queue_; // Q
- std::unordered_map<int, double> dependency_; // delta
+ std::vector<double> dependency_; // delta
void init_() {
- for (int vertex : graph_.get_vertices()) {
- shortest_path_predecessors_[vertex] = std::vector<int>();
- shortest_paths_[vertex] = 0;
- distance_[vertex] = -1;
- dependency_[vertex] = 0;
+ for (int vertex = 0; vertex < graph_.get_number_vertices(); vertex++) {
+ shortest_path_predecessors_.emplace_back();
+ shortest_paths_.push_back(0);
+ distance_.push_back(-1);
+ dependency_.push_back(0);
}
shortest_paths_[vertex_] = 1;