Conversation
| std::vector<int> find_two_nums(int target, std::vector<int> arr) { | ||
| int left = 0; | ||
| int right = arr.size() - 1; | ||
| int sum = arr[right] + arr[left]; |
There was a problem hiding this comment.
warning: Value stored to 'sum' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
int sum = arr[right] + arr[left];
^Additional context
task_01/src/task_01.cpp:5: Value stored to 'sum' during its initialization is never read
int sum = arr[right] + arr[left];
^There was a problem hiding this comment.
поправь это замечание от clang-tidy
и лучше поправить все замечания от clang-tidy
|
|
||
| #include "buy_fish.hpp" | ||
|
|
||
| int totalFishBought(const std::vector<int>& purchases) { |
There was a problem hiding this comment.
warning: function 'totalFishBought' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]
| int totalFishBought(const std::vector<int>& purchases) { | |
| static int totalFishBought(const std::vector<int>& purchases) { |
There was a problem hiding this comment.
это не обязательно исправлять, но лучше исправить
для исправления можно просто обернуть все в безымянный namespace
namespace {
int totalFishBought(const std::vector<int>& purchases) {
...
}
bool isValidSchedule(const std::vector<int>& purchases, int k) {
...
}
}
| return total; | ||
| } | ||
|
|
||
| bool isValidSchedule(const std::vector<int>& purchases, int k) { |
There was a problem hiding this comment.
warning: function 'isValidSchedule' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]
| bool isValidSchedule(const std::vector<int>& purchases, int k) { | |
| static bool isValidSchedule(const std::vector<int>& purchases, int k) { |
|
|
||
| #include "QuickSort.hpp" | ||
|
|
||
| bool isSorted(const std::vector<int>& arr) { |
There was a problem hiding this comment.
warning: function 'isSorted' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]
| bool isSorted(const std::vector<int>& arr) { | |
| static bool isSorted(const std::vector<int>& arr) { |
| for (const auto& entry : table[i]) { | ||
| std::cout << "(" << entry.first << ": " << entry.second << ") "; | ||
| } | ||
| std::cout << std::endl; |
There was a problem hiding this comment.
warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
| std::cout << std::endl; | |
| std::cout << '\n'; |
|
|
||
| auto res = ht.find("apple"); | ||
| ASSERT_TRUE(res.has_value()); | ||
| EXPECT_EQ(res.value(), 10); |
There was a problem hiding this comment.
warning: unchecked access to optional value [bugprone-unchecked-optional-access]
EXPECT_EQ(res.value(), 10);
^|
|
||
| res = ht.find("banana"); | ||
| ASSERT_TRUE(res.has_value()); | ||
| EXPECT_EQ(res.value(), 20); |
There was a problem hiding this comment.
warning: unchecked access to optional value [bugprone-unchecked-optional-access]
EXPECT_EQ(res.value(), 20);
^|
|
||
| res = ht.find("orange"); | ||
| ASSERT_TRUE(res.has_value()); | ||
| EXPECT_EQ(res.value(), 30); |
There was a problem hiding this comment.
warning: unchecked access to optional value [bugprone-unchecked-optional-access]
EXPECT_EQ(res.value(), 30);
^|
|
||
| auto res = ht.find("apple"); | ||
| ASSERT_TRUE(res.has_value()); | ||
| EXPECT_EQ(res.value(), 50); |
There was a problem hiding this comment.
warning: unchecked access to optional value [bugprone-unchecked-optional-access]
EXPECT_EQ(res.value(), 50);
^|
|
||
| res = ht.find("banana"); | ||
| ASSERT_TRUE(res.has_value()); | ||
| EXPECT_EQ(res.value(), 20); |
There was a problem hiding this comment.
warning: unchecked access to optional value [bugprone-unchecked-optional-access]
EXPECT_EQ(res.value(), 20);
^| for (int i = 0; i < 1000; ++i) { | ||
| auto val = ht.find("key" + std::to_string(i)); | ||
| ASSERT_TRUE(val.has_value()); | ||
| EXPECT_EQ(val.value(), i); |
There was a problem hiding this comment.
warning: unchecked access to optional value [bugprone-unchecked-optional-access]
EXPECT_EQ(val.value(), i);
^| #pragma once | ||
| #include <vector> | ||
|
|
||
| std::vector<int> find_two_nums(int target, std::vector<int> arr); No newline at end of file |
There was a problem hiding this comment.
передавай массив по конфстантной ссылке что бы не было копирования
| #include <vector> | ||
|
|
||
| template <typename T> | ||
| class Stack { |
There was a problem hiding this comment.
давай хотя бы еще метод Size добавим, а лучше и ещё IsEpty (можно и просто Empty)
| return result; | ||
| } | ||
|
|
||
| T getmax() { |
| private: | ||
| std::vector<int> data_; | ||
| std::vector<T> data_; | ||
| std::vector<T> data_mins; |
There was a problem hiding this comment.
data_mins_ для data_ добавили подчеркивание что бы обозначить что это private поле, а для data_mins не добавили, чем оно хуже)
There was a problem hiding this comment.
добавь своих тестов, например с пустым стэком
| @@ -1 +1,18 @@ | |||
| #include "topology_sort.hpp" | |||
|
|
|||
| std::vector<int> days_until_warmer(const std::vector<int>& temperatures) { | |||
There was a problem hiding this comment.
переименуй файл плиз) название из прошлого семестра осталось) (алгоритмы 2 семетр)
There was a problem hiding this comment.
добавь тестов на пустой массив
| @@ -0,0 +1,26 @@ | |||
| #include "QuickSort.hpp" | |||
|
|
|||
| void quickSortwrap(std::vector<int>& arr, int low, int high) { | |||
There was a problem hiding this comment.
Функция quickSortwrap не предназначена для внешнего использования, поместить в анонимное пространство имён (и убрать из hpp)
| int right = arr.size() - 1; | ||
|
|
||
| while (left <= right) { | ||
| int pivotIndex = left + rand() % (right - left + 1); |
There was a problem hiding this comment.
pivot_index по кодстайлу)
|
|
||
| #include <iostream> | ||
|
|
||
| struct Node { |
There was a problem hiding this comment.
лучше сделать внутреннем классом AVLTree (в private). это часть реализации, ее лучше скрывать
| Node(int k) : key(k), left(nullptr), right(nullptr), height(1) {} | ||
| }; | ||
|
|
||
| class AVLTree { |
There was a problem hiding this comment.
выделение памяти через new есть, а деструктора нет, значит есть утечка памяти
| #include <vector> | ||
|
|
||
| template <typename T> | ||
| class HashTable { |
There was a problem hiding this comment.
давай добавим методы Size и IsEmpty
| Node* left{nullptr}; | ||
| Node* right{nullptr}; | ||
| int height; | ||
| Node(int k) : key(k), left(nullptr), right(nullptr), height(1) {} |
There was a problem hiding this comment.
warning: member initializer for 'left' is redundant [cppcoreguidelines-use-default-member-init]
| Node(int k) : key(k), left(nullptr), right(nullptr), height(1) {} | |
| Node(int k) : key(k), , right(nullptr), height(1) {} |
| Node* left{nullptr}; | ||
| Node* right{nullptr}; | ||
| int height; | ||
| Node(int k) : key(k), left(nullptr), right(nullptr), height(1) {} |
There was a problem hiding this comment.
warning: member initializer for 'right' is redundant [cppcoreguidelines-use-default-member-init]
| Node(int k) : key(k), left(nullptr), right(nullptr), height(1) {} | |
| Node(int k) : key(k), left(nullptr), , height(1) {} |
| Node* left{nullptr}; | ||
| Node* right{nullptr}; | ||
| int height; | ||
| Node(int k) : key(k), left(nullptr), right(nullptr), height(1) {} |
There was a problem hiding this comment.
warning: use default member initializer for 'height' [cppcoreguidelines-use-default-member-init]
| Node(int k) : key(k), left(nullptr), right(nullptr), height(1) {} | |
| int height{1}; | |
| Node(int k) : key(k), left(nullptr), right(nullptr), {} |
|
|
||
| Node* root = nullptr; | ||
|
|
||
| int height(Node* n) { return n ? n->height : 0; } |
There was a problem hiding this comment.
warning: Use of memory after it is freed [clang-analyzer-cplusplus.NewDelete]
int height(Node* n) { return n ? n->height : 0; }
^Additional context
task_07/src/test.cpp:63: Calling 'AVLTree::erase'
tree.erase(15);
^task_07/src/AVLTree.hpp:144: Calling 'AVLTree::erase'
void erase(int key) { root = erase(root, key); }
^task_07/src/AVLTree.hpp:97: 'node' is non-null
if (!node) return node;
^task_07/src/AVLTree.hpp:97: Taking false branch
if (!node) return node;
^task_07/src/AVLTree.hpp:99: Assuming 'key' is >= field 'key'
if (key < node->key)
^task_07/src/AVLTree.hpp:99: Taking false branch
if (key < node->key)
^task_07/src/AVLTree.hpp:101: Assuming 'key' is <= field 'key'
else if (key > node->key)
^task_07/src/AVLTree.hpp:101: Taking false branch
else if (key > node->key)
^task_07/src/AVLTree.hpp:104: Field 'left' is null
if (!node->left || !node->right) {
^task_07/src/AVLTree.hpp:104: Left side of '||' is true
if (!node->left || !node->right) {
^task_07/src/AVLTree.hpp:105: Field 'left' is null
Node* temp = node->left ? node->left : node->right;
^task_07/src/AVLTree.hpp:105: '?' condition is false
Node* temp = node->left ? node->left : node->right;
^task_07/src/AVLTree.hpp:106: 'temp' is non-null
if (!temp) {
^task_07/src/AVLTree.hpp:106: Taking false branch
if (!temp) {
^task_07/src/AVLTree.hpp:112: Calling '~Node'
delete temp;
^task_07/src/AVLTree.hpp:13: Memory is released
delete left;
^task_07/src/AVLTree.hpp:112: Returning from '~Node'
delete temp;
^task_07/src/AVLTree.hpp:120: 'node' is non-null
if (!node) return node;
^task_07/src/AVLTree.hpp:120: Taking false branch
if (!node) return node;
^task_07/src/AVLTree.hpp:122: Calling 'AVLTree::balance'
return balance(node);
^task_07/src/AVLTree.hpp:57: Calling 'AVLTree::updateHeight'
updateHeight(n);
^task_07/src/AVLTree.hpp:27: Calling 'AVLTree::height'
n->height = 1 + std::max(height(n->left), height(n->right));
^task_07/src/AVLTree.hpp:20: 'n' is non-null
int height(Node* n) { return n ? n->height : 0; }
^task_07/src/AVLTree.hpp:20: '?' condition is true
int height(Node* n) { return n ? n->height : 0; }
^task_07/src/AVLTree.hpp:20: Use of memory after it is freed
int height(Node* n) { return n ? n->height : 0; }
^| } | ||
|
|
||
| void updateHeight(Node* n) { | ||
| n->height = 1 + std::max(height(n->left), height(n->right)); |
There was a problem hiding this comment.
warning: Use of memory after it is freed [clang-analyzer-cplusplus.NewDelete]
n->height = 1 + std::max(height(n->left), height(n->right));
^Additional context
task_07/src/AVLTree.hpp:144: Calling 'AVLTree::erase'
void erase(int key) { root = erase(root, key); }
^task_07/src/AVLTree.hpp:97: Assuming 'node' is non-null
if (!node) return node;
^task_07/src/AVLTree.hpp:97: Taking false branch
if (!node) return node;
^task_07/src/AVLTree.hpp:99: Assuming 'key' is >= field 'key'
if (key < node->key)
^task_07/src/AVLTree.hpp:99: Taking false branch
if (key < node->key)
^task_07/src/AVLTree.hpp:101: Assuming 'key' is > field 'key'
else if (key > node->key)
^task_07/src/AVLTree.hpp:101: Taking true branch
else if (key > node->key)
^task_07/src/AVLTree.hpp:102: Calling 'AVLTree::erase'
node->right = erase(node->right, key);
^task_07/src/AVLTree.hpp:97: Assuming 'node' is non-null
if (!node) return node;
^task_07/src/AVLTree.hpp:97: Taking false branch
if (!node) return node;
^task_07/src/AVLTree.hpp:99: Assuming 'key' is < field 'key'
if (key < node->key)
^task_07/src/AVLTree.hpp:99: Taking true branch
if (key < node->key)
^task_07/src/AVLTree.hpp:100: Calling 'AVLTree::erase'
node->left = erase(node->left, key);
^task_07/src/AVLTree.hpp:97: Assuming 'node' is non-null
if (!node) return node;
^task_07/src/AVLTree.hpp:97: Taking false branch
if (!node) return node;
^task_07/src/AVLTree.hpp:99: Assuming 'key' is < field 'key'
if (key < node->key)
^task_07/src/AVLTree.hpp:99: Taking true branch
if (key < node->key)
^task_07/src/AVLTree.hpp:100: Calling 'AVLTree::erase'
node->left = erase(node->left, key);
^task_07/src/AVLTree.hpp:97: Assuming 'node' is non-null
if (!node) return node;
^task_07/src/AVLTree.hpp:97: Taking false branch
if (!node) return node;
^task_07/src/AVLTree.hpp:99: Assuming 'key' is >= field 'key'
if (key < node->key)
^task_07/src/AVLTree.hpp:99: Taking false branch
if (key < node->key)
^task_07/src/AVLTree.hpp:101: Assuming 'key' is <= field 'key'
else if (key > node->key)
^task_07/src/AVLTree.hpp:101: Taking false branch
else if (key > node->key)
^task_07/src/AVLTree.hpp:104: Assuming field 'left' is null
if (!node->left || !node->right) {
^task_07/src/AVLTree.hpp:104: Left side of '||' is true
if (!node->left || !node->right) {
^task_07/src/AVLTree.hpp:105: Field 'left' is null
Node* temp = node->left ? node->left : node->right;
^task_07/src/AVLTree.hpp:105: '?' condition is false
Node* temp = node->left ? node->left : node->right;
^task_07/src/AVLTree.hpp:106: Assuming 'temp' is non-null
if (!temp) {
^task_07/src/AVLTree.hpp:106: Taking false branch
if (!temp) {
^task_07/src/AVLTree.hpp:112: Calling '~Node'
delete temp;
^task_07/src/AVLTree.hpp:13: Memory is released
delete left;
^task_07/src/AVLTree.hpp:112: Returning from '~Node'
delete temp;
^task_07/src/AVLTree.hpp:120: 'node' is non-null
if (!node) return node;
^task_07/src/AVLTree.hpp:120: Taking false branch
if (!node) return node;
^task_07/src/AVLTree.hpp:122: Calling 'AVLTree::balance'
return balance(node);
^task_07/src/AVLTree.hpp:57: Calling 'AVLTree::updateHeight'
updateHeight(n);
^task_07/src/AVLTree.hpp:27: Use of memory after it is freed
n->height = 1 + std::max(height(n->left), height(n->right));
^|
|
||
| class AVLTreeTest : public ::testing::Test { | ||
| protected: | ||
| AVLTree tree; |
There was a problem hiding this comment.
warning: member variable 'tree' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]
AVLTree tree;
^| private: | ||
| std::vector<std::list<std::pair<std::string, T>>> table; | ||
| int capacity; | ||
| int size; |
There was a problem hiding this comment.
warning: use default member initializer for 'size' [cppcoreguidelines-use-default-member-init]
| int size; | |
| int size{0}; |
task_08/src/HashTable.hpp:41:
- HashTable(int init_capacity = 8) : capacity(init_capacity), size(0) {
+ HashTable(int init_capacity = 8) : capacity(init_capacity), {
All tasks done with tests