Conversation
There was a problem hiding this comment.
Pull request overview
This PR integrates a hash table data structure with the existing student management system to improve search performance. The hash table provides O(1) average-case lookup time for students by CNE (student ID), replacing the previous O(n) linear search through the linked list.
Changes:
- Integrated hash table alongside the existing linked list structure for efficient student lookups
- Updated all student management functions (add, delete, search, delete_all) to maintain both data structures
- Fixed critical bugs including assignment operator misuse and struct syntax errors
- Improved header file dependencies by using forward declarations to reduce circular includes
Reviewed changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| undo_stack.h | Added hash_table parameter to undo functions; moved student_data definition here; added forward declarations |
| undo_stack.c | Updated execute_undo to accept hash_table and propagate it to add/delete operations |
| student.h | Removed duplicate student_data definition; updated function signatures to include hash_table; removed merge sort functions |
| student.c | Updated add_student, delete_student, search_student_by_cne, and delete_all_students to work with hash table; fixed NULL check bug; added populate_hash_table function |
| hash_table.h | Fixed struct syntax error; replaced include with forward declaration; renamed search to search_hash |
| hash_table.c | Added student.h include; made index const; removed print statement from search function |
| main.c | Created and initialized hash table; updated all function calls with hash_table parameter; moved variable declaration to top |
| arbres_binaire.h | Replaced undo_stack.h include with forward declaration |
| arbres_binaire.c | Added student.h include; removed BOM character |
| my_data.db | Binary database file added to repository |
| mini_db | Binary executable added to repository |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Supprime un étudiant de la liste en utilisant son CNE. | ||
|
|
There was a problem hiding this comment.
Moving the comment to a separate line improves code readability, but consider keeping the comment on the same line as the function declaration or removing it entirely since it duplicates information from the function name.
| // Supprime un étudiant de la liste en utilisant son CNE. |
| #include "student.h" | ||
| #include "hash_table.h" | ||
| #include "arbres_binaire.h" | ||
| #include "undo_stack.h" |
There was a problem hiding this comment.
The student_data type is now defined in undo_stack.h and used in both save_database and load_database functions. This creates a potentially confusing dependency where student.c must include undo_stack.h just to get the student_data structure definition, even though these database functions are not related to undo functionality. Consider moving student_data to student.h or creating a separate types header to maintain better separation of concerns.
| // Réinitialiser le pointeur next (sera défini correctement manuellement) | ||
| new_student->next = NULL; | ||
|
|
||
| // Ajouter l'étudiant à la fin de la liste chaînée | ||
| // Cela reconstruit la structure de liste originale | ||
| add_student(list, new_student, NULL); | ||
| if (list->tete == NULL) { | ||
| list->tete = new_student; | ||
| list->queues = new_student; | ||
| } else { | ||
| list->queues->next = new_student; | ||
| list->queues = new_student; | ||
| } |
There was a problem hiding this comment.
The load_database function has been changed to manually add students to the list instead of calling add_student. This avoids calling add_student which would now try to insert into the hash table (which hasn't been populated yet during loading). However, the hash table is populated separately after load_database returns via populate_hash_table on line 26 of main.c. This approach is correct but the comment should be updated to reflect that the hash table population happens separately after loading.
| * @param stack Structure de donnee pour stocker historique de suppression | ||
| */ | ||
| void delete_student(list_student *list, char *cne_to_delete, UndoStack *stack) { | ||
| void delete_student(hash_table* ht ,list_student *list, char *cne_to_delete, UndoStack *stack) { |
There was a problem hiding this comment.
Missing space after the comma in the parameter list. Should be "hash_table* ht, list_student *list" or preferably "hash_table *ht, list_student *list" for consistency with C style conventions where the asterisk is placed next to the variable name rather than the type.
| void delete_student(hash_table* ht ,list_student *list, char *cne_to_delete, UndoStack *stack) { | |
| void delete_student(hash_table *ht, list_student *list, char *cne_to_delete, UndoStack *stack) { |
| fgets(cne_buffer, 15, stdin); | ||
| cne_buffer[strcspn(cne_buffer, "\n")] = 0; | ||
| delete_student(my_db, cne_buffer, my_stack); | ||
| delete_student(table_hachage,my_db, cne_buffer, my_stack); |
There was a problem hiding this comment.
Missing space after the comma in the function call. Should be "delete_student(table_hachage, my_db, cne_buffer, my_stack);" for consistency with formatting conventions.
| delete_student(table_hachage,my_db, cne_buffer, my_stack); | |
| delete_student(table_hachage, my_db, cne_buffer, my_stack); |
| typedef struct { | ||
| char nom[20]; | ||
| char prenom[20]; | ||
| Date date_naissance; | ||
| char CNE[15]; | ||
| char filiere[30]; | ||
| float moyenne; | ||
| } student_data; |
There was a problem hiding this comment.
The Date type is used in student_data but is not defined in this header file. While undo_stack.c includes student.h before undo_stack.h (making Date available), any other file that includes undo_stack.h directly will encounter a compilation error. Add a forward declaration or include to make undo_stack.h self-sufficient: either add "typedef struct Date Date;" at the top or ensure Date is defined before use.
| void add_student(list_student *list, student *new_student, UndoStack *stack); // Ajoute un étudiant à la fin de la liste. | ||
| void add_student(hash_table *ht, list_student *list, student *new_student, UndoStack *stack); | ||
|
|
||
| // Ajoute un étudiant à la fin de la liste. |
There was a problem hiding this comment.
Moving the comment to a separate line improves code readability, but consider keeping the comment on the same line as the function declaration or removing it entirely since it duplicates information from the function name and documentation.
| } | ||
|
|
||
| static void display_student_arbre(student *student) { | ||
| void display_student_arbre(student *student) { |
There was a problem hiding this comment.
The change from static to non-static function visibility is inconsistent with the original design. This function was intentionally made static (file-scoped) to encapsulate implementation details. Making it public without a clear reason in the PR description may expose internal implementation details unnecessarily. Consider whether this function needs to be called from other files, and if not, keep it static.
| void display_student_arbre(student *student) { | |
| static void display_student_arbre(student *student) { |
| if (ht == NULL || s == NULL) return; | ||
|
|
||
| unsigned int index = hash(s->CNE); | ||
| const unsigned int index = hash(s->CNE); |
There was a problem hiding this comment.
The const qualifier is added to the index variable, but index is assigned once and never modified, so this is a good practice. However, since this variable is local and immediately used, the const keyword provides minimal benefit. This is acceptable but not critical.
…lude hash_table parameter
No description provided.