Skip to content

Comments

rewriting(20.12.2024)#41

Open
Andrw-404 wants to merge 1 commit intomainfrom
rewriting(20.12.2024)
Open

rewriting(20.12.2024)#41
Andrw-404 wants to merge 1 commit intomainfrom
rewriting(20.12.2024)

Conversation

@Andrw-404
Copy link
Owner

No description provided.

HashTable* createTable(size_t size, int* errorCode) {
HashTable* table = malloc(sizeof(HashTable));
if (table == NULL) {
*errorCode = -5;

Choose a reason for hiding this comment

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

Лучше enum завести или хотя бы константы через #deffine, чтобы было понятно, что за -5

*errorCode = -1;
return;
}
size_t index = hash(key, table->size);

Choose a reason for hiding this comment

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

hash возвращает int (хотя мог бы size_t), тут оно неявно конвертится к size_t, это стоило как-то более явно написать

return;
}
size_t index = hash(key, table->size);
size_t index2 = index;

Choose a reason for hiding this comment

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

Его стоило назвать как-то более говоряще

return;
}
}
char* newString = malloc(sizeof(char));

Choose a reason for hiding this comment

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

Выделяете память под один символ :)

*errorCode = -5;
return;
}
strcpy(newString, key);

Choose a reason for hiding this comment

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

Наверное, имелось в виду strdup

return true;
}
hashIndex = (hashIndex + 1) % table->size;
if (hashIndex == index) {

Choose a reason for hiding this comment

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

index изначально почему-то 0, так что если мы начали поиск с конца таблицы, мы бросим искать после первого же несовпадения, хотя элемент вполне может быть дальше в таблице

HashTable* createTable(size_t size, int* errorCode);

//hash function
int hash(char* key, size_t size);

Choose a reason for hiding this comment

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

Этой функции нечего делать в заголовочном файле


typedef struct HashTable HashTable;

//function that creates a hash table

Choose a reason for hiding this comment

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

Suggested change
//function that creates a hash table
// function that creates a hash table

int* errorCode = 0;
if (!test()) {
printf("Test is failed");
return;

Choose a reason for hiding this comment

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

return что? Функция обещала int вернуть

insert(table, "qwe", errorCode);
insert(table, "qdas", errorCode);
insert(table, "hhh", errorCode);
} No newline at end of file

Choose a reason for hiding this comment

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

Надо её удалить ещё

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.

2 participants