Skip to content

Kulaga Grisha - #21

Open
Climentorii wants to merge 8 commits into
DafeMipt213:mainfrom
Climentorii:main
Open

Kulaga Grisha#21
Climentorii wants to merge 8 commits into
DafeMipt213:mainfrom
Climentorii:main

Conversation

@Climentorii

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread task_01/src/main.cpp Outdated
graph[tmp_from].push_back(tmp_to);
}

std::vector<int> vec = top_sort(graph);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'vec' of type 'std::vector' can be declared 'const' [misc-const-correctness]

Suggested change
std::vector<int> vec = top_sort(graph);
std::vector<int> const vec = top_sort(graph);

Comment thread task_01/src/topology_sort.cpp Outdated
void dfs (int v, std::vector<bool> &used, std::vector<int> &result, std::vector< std::vector<int> > &graph) {
used[v] = true;
for (int i = 0; i < graph[v].size(); ++i) {
int to = graph[v][i];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'to' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int to = graph[v][i];
int const to = graph[v][i];

Comment thread task_03/src/main.cpp Outdated
int cost;
};

int main () {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: an exception may be thrown in function 'main' which should not throw exceptions [bugprone-exception-escape]

int main () {
    ^

Comment thread task_03/src/main.cpp Outdated
};

int main () {
int n = 5, m = 8;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'n' of type 'int' can be declared 'const' [misc-const-correctness]

    int n = 5, m = 8;
    ^

Comment thread task_03/src/main.cpp Outdated
{1, 2, 3}, {1, 3, 2}, {1, 4, 2},
{3, 2, 5}, {3, 1, 1},
{4, 3, -3}};
int v = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
int v = 0;
int const v = 0;

Comment thread task_05/src/RMQ.cpp Outdated
int dist = b - a + 1;
int log_dist = floor(log2(dist));

int k = std::min (vec2D[log_dist][a], vec2D[log_dist][dist - pow(2, log_dist)]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'double' to 'size_type' (aka 'unsigned long') [cppcoreguidelines-narrowing-conversions]

    int k = std::min (vec2D[log_dist][a], vec2D[log_dist][dist - pow(2, log_dist)]);
                                                          ^

Comment thread task_05/src/main.cpp Outdated
vec.push_back(tmp);
}

std::vector< std::vector<int> > vec2D = table_construct(n, vec);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'vec2D' of type 'std::vector<std::vector>' can be declared 'const' [misc-const-correctness]

Suggested change
std::vector< std::vector<int> > vec2D = table_construct(n, vec);
std::vector< std::vector<int> > const vec2D = table_construct(n, vec);

Comment thread task_05/src/main.cpp Outdated
int a, b;
std::cin >> a >> b;

int k = RMQ(a, b, vec2D);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 k = RMQ(a, b, vec2D);
int const k = RMQ(a, b, vec2D);

Comment thread task_05/src/main.cpp Outdated
int a, b;
std::cin >> a >> b;

int k = RMQ(a, b, vec2D);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: Value stored to 'k' during its initialization is never read [clang-analyzer-deadcode.DeadStores]

    int k = RMQ(a, b, vec2D);
        ^
Additional context

task_05/src/main.cpp:25: Value stored to 'k' during its initialization is never read

    int k = RMQ(a, b, vec2D);
        ^

Comment thread task_05/src/test.cpp
@@ -1,6 +1,35 @@

#include <gtest/gtest.h>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'gtest/gtest.h' file not found [clang-diagnostic-error]

#include <gtest/gtest.h>
         ^

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread task_01/src/main.cpp
graph[tmp_from].push_back(tmp_to);
}

std::vector<int> vec = top_sort(graph);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'vec' of type 'std::vector' can be declared 'const' [misc-const-correctness]

Suggested change
std::vector<int> vec = top_sort(graph);
std::vector<int> const vec = top_sort(graph);

std::vector<std::vector<int> > &graph) {
used[v] = true;
for (int i = 0; i < graph[v].size(); ++i) {
int to = graph[v][i];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'to' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int to = graph[v][i];
int const to = graph[v][i];

Comment thread task_04/src/main.cpp Outdated

int start, end;
cin >> start >> end;
int k = Deijkstra(start, end, graph);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 k = Deijkstra(start, end, graph);
int const k = Deijkstra(start, end, graph);

Comment thread task_05/src/RMQ.cpp
const int INF = 1e9;

std::vector<std::vector<int> > table_construct(int n, std::vector<int> &vec) {
int new_size = ceil(log2(n));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'new_size' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int new_size = ceil(log2(n));
int const new_size = ceil(log2(n));

Comment thread task_05/src/RMQ.cpp
int tmp = 1;
int count = 1;
std::vector<std::vector<int> > vec2D;
vec2D.resize(pow(2, new_size));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'double' to 'size_type' (aka 'unsigned long') [cppcoreguidelines-narrowing-conversions]

  vec2D.resize(pow(2, new_size));
               ^

Comment thread task_05/src/RMQ.cpp
int dist = b - a + 1;
int log_dist = floor(log2(dist));

int k =

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 k =
int const k =

Comment thread task_05/src/RMQ.cpp
int log_dist = floor(log2(dist));

int k =
std::min(vec2D[log_dist][a], vec2D[log_dist][dist - pow(2, log_dist)]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'double' to 'size_type' (aka 'unsigned long') [cppcoreguidelines-narrowing-conversions]

      std::min(vec2D[log_dist][a], vec2D[log_dist][dist - pow(2, log_dist)]);
                                                   ^

Comment thread task_05/src/main.cpp
vec.push_back(tmp);
}

std::vector<std::vector<int> > vec2D = table_construct(n, vec);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'vec2D' of type 'std::vector<std::vector>' can be declared 'const' [misc-const-correctness]

Suggested change
std::vector<std::vector<int> > vec2D = table_construct(n, vec);
std::vector<std::vector<int> > const vec2D = table_construct(n, vec);

Comment thread task_05/src/main.cpp
int a, b;
std::cin >> a >> b;

int k = RMQ(a, b, vec2D);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 k = RMQ(a, b, vec2D);
int const k = RMQ(a, b, vec2D);

Comment thread task_05/src/main.cpp
int a, b;
std::cin >> a >> b;

int k = RMQ(a, b, vec2D);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: Value stored to 'k' during its initialization is never read [clang-analyzer-deadcode.DeadStores]

  int k = RMQ(a, b, vec2D);
      ^
Additional context

task_05/src/main.cpp:24: Value stored to 'k' during its initialization is never read

  int k = RMQ(a, b, vec2D);
      ^

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread task_03/src/main.cpp Outdated
int cost;
};

int main() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: an exception may be thrown in function 'main' which should not throw exceptions [bugprone-exception-escape]

int main() {
    ^

Comment thread task_03/src/main.cpp Outdated
};

int main() {
int n = 5, m = 8;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'n' of type 'int' can be declared 'const' [misc-const-correctness]

  int n = 5, m = 8;
  ^

Comment thread task_03/src/main.cpp Outdated
std::vector<int> vec(n, INF);
std::vector<edge> edges = {{0, 1, -1}, {0, 2, 4}, {1, 2, 3}, {1, 3, 2},
{1, 4, 2}, {3, 2, 5}, {3, 1, 1}, {4, 3, -3}};
int v = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
int v = 0;
int const v = 0;

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread task_02/src/AllFunc.cpp
#include "AllFunc.hpp"

void AllFunc(std::vector<std::vector<int> > &graph,
std::set<std::pair<int, int> > &result, std::set<int> &cpvector) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: parameter 'cpvector' is unused [misc-unused-parameters]

Suggested change
std::set<std::pair<int, int> > &result, std::set<int> &cpvector) {
std::set<std::pair<int, int> > &result, std::set<int> & /*cpvector*/) {

Comment thread task_02/src/test.cpp
@@ -1,6 +1,72 @@

#include <gtest/gtest.h>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'gtest/gtest.h' file not found [clang-diagnostic-error]

#include <gtest/gtest.h>
         ^

Comment thread task_06/src/LCA.cpp
if (l == r)
lca_tree[i] = lca_dfs_list[l];
else {
int m = (l + r) >> 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'm' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int m = (l + r) >> 1;
int const m = (l + r) >> 1;

Comment thread task_06/src/LCA.cpp
if (graph.size() == 1) {
OnlyRoot = true;
} else {
int n = (int)graph.size();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'n' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int n = (int)graph.size();
int const n = (int)graph.size();

Comment thread task_06/src/LCA.cpp
} else {
int n = (int)graph.size();
lca_h.resize(n);
lca_dfs_list.reserve(n * 2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: performing an implicit widening conversion to type 'size_type' (aka 'unsigned long') of a multiplication performed in type 'int' [bugprone-implicit-widening-of-multiplication-result]

      lca_dfs_list.reserve(n * 2);
                           ^
Additional context

task_06/src/LCA.cpp:43: make conversion explicit to silence this warning

      lca_dfs_list.reserve(n * 2);
                           ^

task_06/src/LCA.cpp:43: perform multiplication in a wider type

      lca_dfs_list.reserve(n * 2);
                           ^

Comment thread task_06/src/LCA.cpp
int sm = (sl + sr) >> 1;
if (r <= sm) return lca_tree_min(i + i, sl, sm, l, r);
if (l > sm) return lca_tree_min(i + i + 1, sm + 1, sr, l, r);
int ans1 = lca_tree_min(i + i, sl, sm, l, sm);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'ans1' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int ans1 = lca_tree_min(i + i, sl, sm, l, sm);
int const ans1 = lca_tree_min(i + i, sl, sm, l, sm);

Comment thread task_06/src/LCA.cpp
if (r <= sm) return lca_tree_min(i + i, sl, sm, l, r);
if (l > sm) return lca_tree_min(i + i + 1, sm + 1, sr, l, r);
int ans1 = lca_tree_min(i + i, sl, sm, l, sm);
int ans2 = lca_tree_min(i + i + 1, sm + 1, sr, sm + 1, r);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'ans2' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int ans2 = lca_tree_min(i + i + 1, sm + 1, sr, sm + 1, r);
int const ans2 = lca_tree_min(i + i + 1, sm + 1, sr, sm + 1, r);

Comment thread task_06/src/test.cpp
@@ -1,6 +1,42 @@

#include <gtest/gtest.h>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'gtest/gtest.h' file not found [clang-diagnostic-error]

#include <gtest/gtest.h>
         ^

Comment thread task_06/src/test.cpp
}

TEST(LCA, Empty) {
graph g = {};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'g' of type 'graph' (aka 'int') can be declared 'const' [misc-const-correctness]

Suggested change
graph g = {};
graph const g = {};

Comment thread task_06/src/test.cpp
}

TEST(LCA, Only_Root) {
graph g = {{}};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'g' of type 'graph' (aka 'int') can be declared 'const' [misc-const-correctness]

Suggested change
graph g = {{}};
graph const g = {{}};

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread task_03/src/Johnson.cpp
std::vector<std::vector<int>> Johnson(std::vector<edge> &edges, int m, int n) {
std::vector<int> vec(n, INF);
std::vector<edge> tmp_edges = edges;
int v = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
int v = 0;
int const v = 0;

Comment thread task_03/src/Johnson.cpp
}
}
}
if (x != -1) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: The left operand of '!=' is a garbage value [clang-analyzer-core.UndefinedBinaryOperatorResult]

  if (x != -1) {
        ^
Additional context

task_03/src/Johnson.cpp:9: Assuming 'i' is >= 'n'

  for (int i = 0; i < n; ++i) {
                  ^

task_03/src/Johnson.cpp:9: Loop condition is false. Execution continues on line 14

  for (int i = 0; i < n; ++i) {
  ^

task_03/src/Johnson.cpp:16: 'x' declared without an initial value

  int x;
  ^

task_03/src/Johnson.cpp:17: 'i' is >= 'n'

  for (int i = 0; i < n; ++i) {
                  ^

task_03/src/Johnson.cpp:17: Loop condition is false. Execution continues on line 31

  for (int i = 0; i < n; ++i) {
  ^

task_03/src/Johnson.cpp:30: The left operand of '!=' is a garbage value

  if (x != -1) {
        ^

Comment thread task_03/src/Johnson.cpp
}

for (int i = 0; i < n; ++i) {
res.push_back(Deijkstra(i, graph));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop [performance-inefficient-vector-operation]

task_03/src/Johnson.cpp:46:

-   for (int i = 0; i < n; ++i) {
+   res.reserve(n);
+ for (int i = 0; i < n; ++i) {

Comment thread task_03/src/test.cpp
@@ -1,6 +1,42 @@

#include <gtest/gtest.h>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'gtest/gtest.h' file not found [clang-diagnostic-error]

#include <gtest/gtest.h>
         ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant