-
Notifications
You must be signed in to change notification settings - Fork 23
Kulikov Maksimilian #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6f34eb7
7544e3b
43482b2
d2dbb72
c25e7f0
6617e58
82e9026
b1831de
8b5a587
c4c2d35
4364080
79ce8b3
ee0c8bb
db481ef
567f174
868c2fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1 +1,45 @@ | ||||||||||||||||||||||||||||||||||||||
#include "util.hpp" | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
EdgeOrientedGraph::EdgeOrientedGraph(int V, std::vector<std::vector<int>> edges) { | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'edges' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] lib/src/util.hpp:12: - EdgeOrientedGraph(int V, std::vector<std::vector<int>> edges);
+ EdgeOrientedGraph(int V, const std::vector<std::vector<int>>& edges);
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'edges' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] lib/src/util.hpp:12: - EdgeOrientedGraph(int V, std::vector<std::vector<int>> edges);
+ EdgeOrientedGraph(int V, const std::vector<std::vector<int>>& edges);
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'edges' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] lib/src/util.hpp:12: - EdgeOrientedGraph(int V, std::vector<std::vector<int>> edges);
+ EdgeOrientedGraph(int V, const std::vector<std::vector<int>>& edges);
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'edges' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] lib/src/util.hpp:12: - EdgeOrientedGraph(int V, std::vector<std::vector<int>> edges);
+ EdgeOrientedGraph(int V, const std::vector<std::vector<int>>& edges);
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'edges' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] lib/src/util.hpp:12: - EdgeOrientedGraph(int V, std::vector<std::vector<int>> edges);
+ EdgeOrientedGraph(int V, const std::vector<std::vector<int>>& edges);
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'edges' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] lib/src/util.hpp:12: - EdgeOrientedGraph(int V, std::vector<std::vector<int>> edges);
+ EdgeOrientedGraph(int V, const std::vector<std::vector<int>>& edges);
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'edges' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] lib/src/util.hpp:12: - EdgeOrientedGraph(int V, std::vector<std::vector<int>> edges);
+ EdgeOrientedGraph(int V, const std::vector<std::vector<int>>& edges);
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'edges' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] lib/src/util.hpp:12: - EdgeOrientedGraph(int V, std::vector<std::vector<int>> edges);
+ EdgeOrientedGraph(int V, const std::vector<std::vector<int>>& edges);
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'edges' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] lib/src/util.hpp:12: - EdgeOrientedGraph(int V, std::vector<std::vector<int>> edges);
+ EdgeOrientedGraph(int V, const std::vector<std::vector<int>>& edges);
Suggested change
|
||||||||||||||||||||||||||||||||||||||
_ways = std::vector<std::vector<int>>(V); | ||||||||||||||||||||||||||||||||||||||
for (auto x : edges) | ||||||||||||||||||||||||||||||||||||||
_ways[x[0]].push_back(x[1]); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
EdgeOrientedGraph::EdgeOrientedGraph(EdgeOrientedGraph const& graph) : _ways(graph._ways) {} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
int EdgeOrientedGraph::size() { return _ways.size(); } | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int EdgeOrientedGraph::size() { return _ways.size(); }
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int EdgeOrientedGraph::size() { return _ways.size(); }
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int EdgeOrientedGraph::size() { return _ways.size(); }
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int EdgeOrientedGraph::size() { return _ways.size(); }
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int EdgeOrientedGraph::size() { return _ways.size(); }
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int EdgeOrientedGraph::size() { return _ways.size(); }
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int EdgeOrientedGraph::size() { return _ways.size(); }
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int EdgeOrientedGraph::size() { return _ways.size(); }
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int EdgeOrientedGraph::size() { return _ways.size(); }
^ |
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
std::vector<int>& EdgeOrientedGraph::operator[] (int key) { return _ways[key]; } | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
OrientedWeightedGraph::OrientedWeightedGraph(int V) { | ||||||||||||||||||||||||||||||||||||||
_weights = std::vector<std::vector<double>>(V, | ||||||||||||||||||||||||||||||||||||||
std::vector<double>(V, std::numeric_limits<double>::infinity())); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
OrientedWeightedGraph::OrientedWeightedGraph(std::vector<std::vector<double>> const& weights) : _weights(weights) { | ||||||||||||||||||||||||||||||||||||||
int V = weights.size(); | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int V = weights.size();
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'V' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int V = weights.size();
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'V' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int V = weights.size();
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'V' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int V = weights.size();
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'V' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int V = weights.size();
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'V' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int V = weights.size();
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'V' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int V = weights.size();
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'V' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int V = weights.size();
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'V' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int V = weights.size();
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'V' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||||||||||||||||||||||||||||||||||
for (auto& x : weights) | ||||||||||||||||||||||||||||||||||||||
if (V != x.size()) | ||||||||||||||||||||||||||||||||||||||
throw std::exception(); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
OrientedWeightedGraph::OrientedWeightedGraph(OrientedWeightedGraph const& graph) : _weights(graph._weights) {} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
void OrientedWeightedGraph::_zero_vertex() { | ||||||||||||||||||||||||||||||||||||||
for (auto& x : _weights) | ||||||||||||||||||||||||||||||||||||||
x.push_back(std::numeric_limits<double>::infinity()); | ||||||||||||||||||||||||||||||||||||||
_weights.push_back(std::vector<double>(this->size()+1)); | ||||||||||||||||||||||||||||||||||||||
_weights[this->size()-1][this->size()-1] = std::numeric_limits<double>::infinity(); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
void OrientedWeightedGraph::_delete_vertex() { | ||||||||||||||||||||||||||||||||||||||
_weights.pop_back(); | ||||||||||||||||||||||||||||||||||||||
for (auto& x : _weights) | ||||||||||||||||||||||||||||||||||||||
x.pop_back(); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
int OrientedWeightedGraph::size() { return _weights.size(); } | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int OrientedWeightedGraph::size() { return _weights.size(); }
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int OrientedWeightedGraph::size() { return _weights.size(); }
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int OrientedWeightedGraph::size() { return _weights.size(); }
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int OrientedWeightedGraph::size() { return _weights.size(); }
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int OrientedWeightedGraph::size() { return _weights.size(); }
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int OrientedWeightedGraph::size() { return _weights.size(); }
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int OrientedWeightedGraph::size() { return _weights.size(); }
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int OrientedWeightedGraph::size() { return _weights.size(); }
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] int OrientedWeightedGraph::size() { return _weights.size(); }
^ |
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
std::vector<double>& OrientedWeightedGraph::operator[](int first) { return _weights[first]; } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <vector> | ||
#include <limits> | ||
|
||
class EdgeOrientedGraph { | ||
// Contains directions for each corresponding vertex key; | ||
// Key is the order in which vector<int> are stored. | ||
// Keys start from zero. | ||
std::vector<std::vector<int>> _ways; | ||
|
||
public: | ||
// int V : the amount of vertices; | ||
// Vector<vector<int>> : edges of the graph {..., (start_i, end_i), ...}. | ||
EdgeOrientedGraph(int V, std::vector<std::vector<int>> edges); | ||
// Transfers `_ways` | ||
EdgeOrientedGraph(EdgeOrientedGraph const& graph); | ||
|
||
// Returns the amount of vertices in the graph. | ||
int size(); | ||
// Returns all available directions from vertex with same key value. | ||
std::vector<int>& operator[](int key); | ||
}; | ||
|
||
|
||
class OrientedWeightedGraph { | ||
// Matrix of weights. | ||
// First index is a key of the beginning vertex; | ||
// Second index is a key of the end vertex. | ||
std::vector<std::vector<double>> _weights; | ||
public: | ||
// Creates weight matrix with all infinite weights. | ||
// int V : amount of vertices. | ||
OrientedWeightedGraph(int V); | ||
// Creates weight matrix with the same values as the `weights` matrix. | ||
OrientedWeightedGraph(std::vector<std::vector<double>> const& weights); | ||
// Transfers matrix | ||
OrientedWeightedGraph(OrientedWeightedGraph const& graph); | ||
|
||
// Add zero weight vertex needed for Johnson's algorithm. | ||
void _zero_vertex(); | ||
// Deletes the last vertex from the weight matrix. | ||
void _delete_vertex(); | ||
// Returns the amount of vertices in the graph. | ||
int size(); | ||
// Returns the weight of an edge. | ||
// First index is a key of the beginning vertex; | ||
// Second index is a key of the end vertex. | ||
std::vector<double>& operator[](int first); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
#include <gtest/gtest.h> | ||
|
||
TEST(Test, Simple) { | ||
TEST(Topa, Simple) { | ||
// std::vector<int> expected = {0, 3, 2, 1}; | ||
|
||
// std::vector<std::vector<int>> edges = {{0, 3}, {3, 1}, {3, 2}, {2, 1}}; | ||
// OrientedGraph gr(4, edges); | ||
// std::vector<int> result = topo_sort(gr); | ||
ASSERT_EQ(1, 1); // Stack [] | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не экономь на именах |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "topo.hpp" | ||
|
||
void topo_recr(EdgeOrientedGraph& graph, std::stack<int>& vstack, std::vector<int>& vcolor, int current) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не по код стайлу( |
||
vcolor[current] = 1; | ||
for (auto n : graph[current]) { | ||
if (vcolor[n] == 2) | ||
continue; | ||
if (vcolor[n] == 1) { | ||
vstack = {}; | ||
throw std::exception(); // if graph is cyclic | ||
} | ||
topo_recr(graph, vstack, vcolor, n); | ||
} | ||
vcolor[current] = 2; | ||
vstack.push(current); | ||
} | ||
|
||
std::vector<int> topo_sort(EdgeOrientedGraph graph, int from_key) { | ||
std::vector<int> fin_seq; | ||
std::stack<int> vert_stack; | ||
// 0 -- white | ||
// 1 -- grey | ||
// 2 -- black | ||
std::vector<int> vert_color(graph.size()); | ||
vert_color[from_key] = 1; | ||
topo_recr(graph, vert_stack, vert_color, from_key); | ||
|
||
while (!vert_stack.empty()) { | ||
fin_seq.push_back(vert_stack.top()); | ||
vert_stack.pop(); | ||
} | ||
return fin_seq; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <vector> | ||
#include <stack> | ||
#include "util.hpp" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 'util.hpp' file not found [clang-diagnostic-error] #include "util.hpp"
^ |
||
|
||
void topo_recr(EdgeOrientedGraph& graph, std::stack<int>& vstack, std::vector<int>& vcolor, int current); | ||
|
||
std::vector<int> topo_sort(EdgeOrientedGraph graph, int from_key); |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,83 @@ | ||||||||||||||||||||||||||||||||||||||
#include "bell_john.hpp" | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
bool FirstGreater::operator()(std::pair<double, int> const& lhs, | ||||||||||||||||||||||||||||||||||||||
std::pair<double, int> const& rhs) const | ||||||||||||||||||||||||||||||||||||||
{ return lhs.first > rhs.first; } | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
std::vector<double> dijkstra(OrientedWeightedGraph graph, int from_key) | ||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||
double infinity = std::numeric_limits<double>::infinity(); | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'infinity' of type 'double' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'infinity' of type 'double' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'infinity' of type 'double' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'infinity' of type 'double' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'infinity' of type 'double' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'infinity' of type 'double' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'infinity' of type 'double' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'infinity' of type 'double' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'infinity' of type 'double' can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||||||||||||||||||||||||||||||||||
// 0 -- haven't visited this vertex yet | ||||||||||||||||||||||||||||||||||||||
// 1 -- have already visited this vertex | ||||||||||||||||||||||||||||||||||||||
std::vector<double> visited(graph.size(), 0); | ||||||||||||||||||||||||||||||||||||||
std::vector<double> distances(graph.size(), infinity); | ||||||||||||||||||||||||||||||||||||||
std::priority_queue<std::pair<double, int>, | ||||||||||||||||||||||||||||||||||||||
std::vector<std::pair<double, int>>, | ||||||||||||||||||||||||||||||||||||||
FirstGreater> queue; | ||||||||||||||||||||||||||||||||||||||
int N = graph.size(), current; | ||||||||||||||||||||||||||||||||||||||
distances[from_key] = 0; | ||||||||||||||||||||||||||||||||||||||
queue.push(std::make_pair(distances[from_key], from_key)); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
while (!queue.empty()) { | ||||||||||||||||||||||||||||||||||||||
current = queue.top().second; | ||||||||||||||||||||||||||||||||||||||
queue = {}; | ||||||||||||||||||||||||||||||||||||||
for(int i=0; i<N; ++i) { | ||||||||||||||||||||||||||||||||||||||
if (visited[i] == 1 || i == current) | ||||||||||||||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||||||||||||||
if (distances[current] + graph[current][i] < distances[i]) | ||||||||||||||||||||||||||||||||||||||
distances[i] = distances[current] + graph[current][i]; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
visited[current] = 1; | ||||||||||||||||||||||||||||||||||||||
for(int i=0; i<N; ++i) | ||||||||||||||||||||||||||||||||||||||
if (!visited[i]) | ||||||||||||||||||||||||||||||||||||||
queue.push(std::make_pair(distances[i], i)); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
return distances; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
std::vector<double> bellman(OrientedWeightedGraph graph, int from_key, int iterations) { | ||||||||||||||||||||||||||||||||||||||
if (iterations == std::numeric_limits<int>::infinity()) | ||||||||||||||||||||||||||||||||||||||
iterations = graph.size(); | ||||||||||||||||||||||||||||||||||||||
std::vector<double> distances(graph.size(), std::numeric_limits<double>::infinity()), | ||||||||||||||||||||||||||||||||||||||
infinite_row = distances; | ||||||||||||||||||||||||||||||||||||||
std::vector<std::vector<double>> paths = {}; | ||||||||||||||||||||||||||||||||||||||
int V = graph.size(); | ||||||||||||||||||||||||||||||||||||||
distances[from_key] = 0; | ||||||||||||||||||||||||||||||||||||||
paths.push_back(distances); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
for(int step=1; step<iterations; ++step) { | ||||||||||||||||||||||||||||||||||||||
paths.push_back(infinite_row); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
for(int from=0; from<V; ++from) { | ||||||||||||||||||||||||||||||||||||||
double current_weight = paths[step-1][from]; | ||||||||||||||||||||||||||||||||||||||
if (current_weight == std::numeric_limits<double>::infinity()) | ||||||||||||||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
for(int to=0; to<graph[from].size(); ++to) { | ||||||||||||||||||||||||||||||||||||||
if (current_weight + graph[from][to] < paths[step][to]) | ||||||||||||||||||||||||||||||||||||||
paths[step][to] = current_weight + graph[from][to]; | ||||||||||||||||||||||||||||||||||||||
if (current_weight + graph[from][to] < distances[to]) | ||||||||||||||||||||||||||||||||||||||
distances[to] = current_weight + graph[from][to]; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
return distances; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
std::vector<double> johnson(OrientedWeightedGraph graph, int from_key) { | ||||||||||||||||||||||||||||||||||||||
graph._zero_vertex(); | ||||||||||||||||||||||||||||||||||||||
std::vector<double> bel_dist = bellman(graph, graph.size()-1); | ||||||||||||||||||||||||||||||||||||||
graph._delete_vertex(); | ||||||||||||||||||||||||||||||||||||||
int V = graph.size(); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
for(int i=0; i<V; ++i) | ||||||||||||||||||||||||||||||||||||||
for(int j=0; j<V; ++j) | ||||||||||||||||||||||||||||||||||||||
graph[i][j] += bel_dist[i] - bel_dist[j]; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
std::vector<double> res_dist = dijkstra(graph, from_key); | ||||||||||||||||||||||||||||||||||||||
for(int i=0; i<V; ++i) | ||||||||||||||||||||||||||||||||||||||
res_dist[i] -= bel_dist[from_key] - bel_dist[i]; | ||||||||||||||||||||||||||||||||||||||
return res_dist; | ||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <limits> | ||
#include <vector> | ||
#include <queue> | ||
#include <map> | ||
#include "util.hpp" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 'util.hpp' file not found [clang-diagnostic-error] #include "util.hpp"
^ |
||
|
||
struct FirstGreater { | ||
bool operator()(std::pair<double, int> const& lhs, | ||
std::pair<double, int> const& rhs) const; | ||
}; | ||
|
||
std::vector<double> dijkstra(OrientedWeightedGraph graph, int from_key); | ||
|
||
std::vector<double> bellman(OrientedWeightedGraph graph, int from_key, int iterations = std::numeric_limits<int>::infinity()); | ||
|
||
std::vector<double> johnson(OrientedWeightedGraph graph, int from_key); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,8 +1,18 @@ | ||||||
|
||||||
#include <gtest/gtest.h> | ||||||
|
||||||
#include "topology_sort.hpp" | ||||||
|
||||||
TEST(TopologySort, Simple) { | ||||||
TEST(Johnson, Simple) { | ||||||
// std::vector<double> expected = {-4., -2., 3., 0., -6.}; | ||||||
|
||||||
// double inf = std::numeric_limits<double>::infinity(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'inf' of type 'double' can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
// std::vector<std::vector<double>> weights = { | ||||||
// {inf, 6, 7, inf, inf}, | ||||||
// {inf, inf, 8, 5, -4 }, | ||||||
// {inf, inf, inf, -3, 9 }, | ||||||
// {inf, -2, inf, inf, inf}, | ||||||
// {2, inf, inf, 7, inf} | ||||||
// }; | ||||||
// OrientedWeightedGraph graph(weights); | ||||||
// std::vector<double> result = johnson(graph, from); | ||||||
ASSERT_EQ(1, 1); // Stack [] | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <vector> | ||
#include <queue> | ||
#include <map> | ||
#include "util.hpp" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 'util.hpp' file not found [clang-diagnostic-error] #include "util.hpp"
^ |
||
|
||
struct FirstGreater { | ||
bool operator()(std::pair<double, int> const& lhs, | ||
std::pair<double, int> const& rhs) const; | ||
}; | ||
|
||
|
||
std::vector<double> dijkstra(OrientedWeightedGraph graph, int from_key); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "dijkstra.hpp" | ||
|
||
bool FirstGreater::operator()(std::pair<double, int> const& lhs, | ||
std::pair<double, int> const& rhs) const | ||
{ return lhs.first > rhs.first; } | ||
|
||
|
||
std::vector<double> dijkstra(OrientedWeightedGraph graph, int from_key) | ||
{ | ||
double infinity = std::numeric_limits<double>::infinity(); | ||
// 0 -- haven't visited this vertex yet | ||
// 1 -- have already visited this vertex | ||
std::vector<double> visited(graph.size(), 0); | ||
std::vector<double> distances(graph.size(), infinity); | ||
std::priority_queue<std::pair<double, int>, | ||
std::vector<std::pair<double, int>>, | ||
FirstGreater> queue; | ||
int N = graph.size(), current; | ||
distances[from_key] = 0; | ||
queue.push(std::make_pair(distances[from_key], from_key)); | ||
|
||
while (!queue.empty()) { | ||
current = queue.top().second; | ||
queue = {}; | ||
for(int i=0; i<N; ++i) { | ||
if (visited[i] == 1 || i == current) | ||
continue; | ||
if (distances[current] + graph[current][i] < distances[i]) | ||
distances[i] = distances[current] + graph[current][i]; | ||
} | ||
visited[current] = 1; | ||
for(int i=0; i<N; ++i) | ||
if (!visited[i]) | ||
queue.push(std::make_pair(distances[i], i)); | ||
} | ||
|
||
return distances; | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,19 @@ | ||||||||||
|
||||||||||
#include <gtest/gtest.h> | ||||||||||
|
||||||||||
TEST(TopologySort, Simple) { | ||||||||||
TEST(Dijkstra, Simple) { | ||||||||||
// std::vector<double> expected = {0., 7., 9., 20., 20., 11.}; | ||||||||||
|
||||||||||
// double inf = std::numeric_limits<double>::infinity(); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'inf' of type 'double' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'inf' of type 'double' can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||||||
// std::vector<std::vector<double>> weights = { | ||||||||||
// {inf, 7, 9, inf, inf, 14}, | ||||||||||
// {7, inf, 10, inf, inf, inf}, | ||||||||||
// {9, 10, inf, 11, inf, 2}, | ||||||||||
// {inf, inf, 11, inf, 6, inf}, | ||||||||||
// {inf, inf, inf, 6, inf, 9}, | ||||||||||
// {14, inf, 2, inf, 9, inf} | ||||||||||
// }; | ||||||||||
// OrientedWeightedGraph graph(weights); | ||||||||||
// std::vector<double> result = dijkstra_alg(graph, 0); | ||||||||||
ASSERT_EQ(1, 1); // Stack [] | ||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,32 @@ | ||||||||||||||||||||||||||||||||||||||
#include <vector> | ||||||||||||||||||||||||||||||||||||||
#include <cmath> | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
template<class Comparator> | ||||||||||||||||||||||||||||||||||||||
std::vector<std::vector<double>> sparse_table(std::vector<double> vals, Comparator comp) { | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'vals' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] std::vector<std::vector<double>> sparse_table(std::vector<double> vals, Comparator comp) {
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'vals' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] std::vector<std::vector<double>> sparse_table(std::vector<double> vals, Comparator comp) {
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'vals' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] std::vector<std::vector<double>> sparse_table(std::vector<double> vals, Comparator comp) {
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'vals' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] std::vector<std::vector<double>> sparse_table(std::vector<double> vals, Comparator comp) {
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'vals' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] std::vector<std::vector<double>> sparse_table(std::vector<double> vals, Comparator comp) {
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'vals' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] std::vector<std::vector<double>> sparse_table(std::vector<double> vals, Comparator comp) {
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'vals' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] std::vector<std::vector<double>> sparse_table(std::vector<double> vals, Comparator comp) {
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'vals' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] std::vector<std::vector<double>> sparse_table(std::vector<double> vals, Comparator comp) {
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: the parameter 'vals' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] std::vector<std::vector<double>> sparse_table(std::vector<double> vals, Comparator comp) {
^ |
||||||||||||||||||||||||||||||||||||||
int K = static_cast<int>(std::log2(vals.size()))+1; | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||||||||||||||||||||||||||||||||||
std::vector<std::vector<double>> sparse_table; | ||||||||||||||||||||||||||||||||||||||
sparse_table.push_back(vals); | ||||||||||||||||||||||||||||||||||||||
int power = 1; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
for(int i=1; i<K; ++i) { | ||||||||||||||||||||||||||||||||||||||
std::vector<double> vali = {}; | ||||||||||||||||||||||||||||||||||||||
for(int j = 0; j < sparse_table[i-1].size()-power; ++j) { | ||||||||||||||||||||||||||||||||||||||
(comp(sparse_table[i-1][j], sparse_table[i-1][j+power])) ? | ||||||||||||||||||||||||||||||||||||||
vali.push_back(sparse_table[i-1][j]) : vali.push_back(sparse_table[i-1][j+power]); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
sparse_table.push_back(vali); | ||||||||||||||||||||||||||||||||||||||
power*=2; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
return sparse_table; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
template<class Comparator> | ||||||||||||||||||||||||||||||||||||||
double rmq(int start, int finish, std::vector<std::vector<double>> sparse_table, Comparator comp) { | ||||||||||||||||||||||||||||||||||||||
int K = static_cast<int>(std::log2(finish - start + 1)); | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'K' of type 'int' can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||||||||||||||||||||||||||||||||||
int power = 1; | ||||||||||||||||||||||||||||||||||||||
for(int p=0; p<K; ++p) | ||||||||||||||||||||||||||||||||||||||
power *= 2; | ||||||||||||||||||||||||||||||||||||||
double result = (comp(sparse_table[K][start], sparse_table[K][finish-power+1])) ? | ||||||||||||||||||||||||||||||||||||||
sparse_table[K][start] : sparse_table[K][finish-power+1]; | ||||||||||||||||||||||||||||||||||||||
return result; | ||||||||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: the parameter 'edges' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
lib/src/util.hpp:12: