From a2f20cc3038ea9d4231f68bdc7ae4507ab0a5173 Mon Sep 17 00:00:00 2001
From: Alec <alec.schmidt@hesge.ch>
Date: Thu, 2 Jun 2022 14:07:23 +0200
Subject: [PATCH] encore des bugfix...

---
 bp_tree.c | 11 ++++++-----
 main.c    |  6 +++---
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/bp_tree.c b/bp_tree.c
index 6b80f94..d562e9e 100644
--- a/bp_tree.c
+++ b/bp_tree.c
@@ -74,6 +74,7 @@ node *bp_split(node *nd) {
     // childs for leaves
     for (int i = 0; i < upto; i++) {
         new->data[i] = nd->data[index + i];
+        new->user[i] = nd->user[index + i];
         nd->data[index + i] = 0;
     }
 
@@ -285,9 +286,8 @@ node *bp_insert_val(node *tree, entry person) {
 // SEARCH ----------------------------------------------------------
 
 entry bp_search_node(node *tree, uint64_t hash) {
-    if (tree == NULL) {
+    if (tree == NULL)
         return CONST_ENTR;
-    }
 
     if (bp_is_leaf(tree)) {
         for (int i = 0; i < M; i++) {
@@ -295,11 +295,12 @@ entry bp_search_node(node *tree, uint64_t hash) {
                 return tree->user[i];
         }
     } else {
-        for (int i = 0; i <= M; i++) {
-            if (tree->data[i] > hash) {
+        for (int i = 0; i < M; i++) {
+            if (tree->data[i] > hash || tree->data[i] == 0) {
                 return bp_search_node(tree->childs[i], hash);
             }
         }
+        return bp_search_node(tree->childs[M], hash);
     }
     return CONST_ENTR;
 }
@@ -400,7 +401,7 @@ void bp_print_as_ll(node *root) {
         return bp_print_as_ll(root->childs[0]);
     }
 
-    printf("|");
+    printf("| ");
     // print every values in the node until hitting 0, then we can get on the
     // next node
     for (int i = 0; i < M; i++) {
diff --git a/main.c b/main.c
index 0d8a31d..8fe32ec 100644
--- a/main.c
+++ b/main.c
@@ -33,15 +33,15 @@ int main() {
     tree = bp_insert_val(tree, person);
 
     strcpy(person.f_name, "Vincent\0");
-    strcpy(person.l_name, "\0");
+    strcpy(person.l_name, "Steinmann\0");
     strcpy(person.phone, "0795787730\0");
     test.day = 24;
     test.month = 5;
-    test.year = 101;
+    test.year = 97;
     person.birth = test;
     tree = bp_insert_val(tree, person);
 
-    char phone_search[11] = {"0788909566"};
+    char phone_search[11] = {"0795787730"};
     bp_print(tree, 0);
     printf("\n|||||||||\n");
     printf("Recherche par n° de téléphone : \n");
-- 
GitLab