Conversation
| HashTable* createTable(size_t size, int* errorCode) { | ||
| HashTable* table = malloc(sizeof(HashTable)); | ||
| if (table == NULL) { | ||
| *errorCode = -5; |
There was a problem hiding this comment.
Лучше enum завести или хотя бы константы через #deffine, чтобы было понятно, что за -5
| *errorCode = -1; | ||
| return; | ||
| } | ||
| size_t index = hash(key, table->size); |
There was a problem hiding this comment.
hash возвращает int (хотя мог бы size_t), тут оно неявно конвертится к size_t, это стоило как-то более явно написать
| return; | ||
| } | ||
| size_t index = hash(key, table->size); | ||
| size_t index2 = index; |
There was a problem hiding this comment.
Его стоило назвать как-то более говоряще
| return; | ||
| } | ||
| } | ||
| char* newString = malloc(sizeof(char)); |
There was a problem hiding this comment.
Выделяете память под один символ :)
| *errorCode = -5; | ||
| return; | ||
| } | ||
| strcpy(newString, key); |
There was a problem hiding this comment.
Наверное, имелось в виду strdup
| return true; | ||
| } | ||
| hashIndex = (hashIndex + 1) % table->size; | ||
| if (hashIndex == index) { |
There was a problem hiding this comment.
index изначально почему-то 0, так что если мы начали поиск с конца таблицы, мы бросим искать после первого же несовпадения, хотя элемент вполне может быть дальше в таблице
| HashTable* createTable(size_t size, int* errorCode); | ||
|
|
||
| //hash function | ||
| int hash(char* key, size_t size); |
There was a problem hiding this comment.
Этой функции нечего делать в заголовочном файле
|
|
||
| typedef struct HashTable HashTable; | ||
|
|
||
| //function that creates a hash table |
There was a problem hiding this comment.
| //function that creates a hash table | |
| // function that creates a hash table |
| int* errorCode = 0; | ||
| if (!test()) { | ||
| printf("Test is failed"); | ||
| return; |
There was a problem hiding this comment.
return что? Функция обещала int вернуть
| insert(table, "qwe", errorCode); | ||
| insert(table, "qdas", errorCode); | ||
| insert(table, "hhh", errorCode); | ||
| } No newline at end of file |
No description provided.