-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 1# #6
base: master
Are you sure you want to change the base?
1 1# #6
Conversation
1_1/main.cpp
Outdated
} | ||
|
||
int Hash(const std::string &s, int i, int table_size, unsigned long long k = 0) { | ||
if (s.empty()) return 0; |
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.
Зачем проверка для пустой строки?
1_1/main.cpp
Outdated
return {false, hash_string == hash0 ? hash : hash_string}; | ||
} else if (hash0 == hash_string && table[hash] == Deleted) { | ||
hash_string = hash; | ||
iteration += 1; |
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.
Эти две строки нужно бы вытащить из ifов
1_1/main.cpp
Outdated
while (iteration <= table.size()) { | ||
if (table[hash] == s) { | ||
return {true, hash}; | ||
} else if (table[hash] == "0") { |
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.
else можно не писать
1_1/main.cpp
Outdated
return {true, hash}; | ||
} else if (table[hash] == "0") { | ||
return {false, hash_string == hash0 ? hash : hash_string}; | ||
} else if (hash0 == hash_string && table[hash] == Deleted) { |
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.
else можно не писать
1_1/main.cpp
Outdated
return true; | ||
} | ||
|
||
void ReTable() { |
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.
Этот метод надо сделать приватным.
1_1/main.cpp
Outdated
|
||
int Hash(const std::string &s, int i, int table_size, unsigned long long k = 0) { | ||
if (s.empty()) return 0; | ||
return (k + i * i / 2 + i / 4) % table_size; |
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.
Почему такой выбор констант квадратичного пробирования перебирает все ячейки? 0ая и 1ая итерация совпадают. Да, вы перебираете от 1ой, но некоторые итерации могут совпадать и дальше. Требуется или доказательство, или использование стандартных констант )
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.
Я там сразу вызываю Hash для 1 итерации, Нужно просто переписать для С1=С2=1/2?
1_1/main.cpp
Outdated
@@ -15,14 +15,22 @@ unsigned long long Sum(const std::string &s, int table_size) { | |||
} | |||
|
|||
int Hash(const std::string &s, int i, int table_size, unsigned long long k = 0) { | |||
if (s.empty()) return 0; | |||
return (k + i * i / 2 + i / 4) % table_size; | |||
return (k + i * i / 2 + i / 2) % table_size; |
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.
Здесь целочисленное деление. Чтобы правильно работало, надо (k + (i * (i + 1))/2)
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.
А никак нельзя задачу на выше чем 2 из 4 исправить?
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.
Принято на 4 )
No description provided.