Skip to content

feat: integrate hash table with student management functions#2

Merged
ayoubkad merged 2 commits intomainfrom
erreur
Jan 28, 2026
Merged

feat: integrate hash table with student management functions#2
ayoubkad merged 2 commits intomainfrom
erreur

Conversation

@ayoubkad
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings January 28, 2026 15:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +49 to 50
// Supprime un étudiant de la liste en utilisant son CNE.

Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
// Supprime un étudiant de la liste en utilisant son CNE.

Copilot uses AI. Check for mistakes.
#include "student.h"
#include "hash_table.h"
#include "arbres_binaire.h"
#include "undo_stack.h"
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +318 to +327
// 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;
}
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
* @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) {
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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) {

Copilot uses AI. Check for mistakes.
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);
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
delete_student(table_hachage,my_db, cne_buffer, my_stack);
delete_student(table_hachage, my_db, cne_buffer, my_stack);

Copilot uses AI. Check for mistakes.
Comment on lines +14 to +21
typedef struct {
char nom[20];
char prenom[20];
Date date_naissance;
char CNE[15];
char filiere[30];
float moyenne;
} student_data;
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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.
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
}

static void display_student_arbre(student *student) {
void display_student_arbre(student *student) {
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
void display_student_arbre(student *student) {
static void display_student_arbre(student *student) {

Copilot uses AI. Check for mistakes.
if (ht == NULL || s == NULL) return;

unsigned int index = hash(s->CNE);
const unsigned int index = hash(s->CNE);
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@ayoubkad ayoubkad merged commit 22c30e8 into main Jan 28, 2026
@ayoubkad ayoubkad deleted the erreur branch March 3, 2026 02:45
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