diff --git a/bpt.c b/bpt.c index dcbb7580f3cffcc501000ed0b9bc5ab5c53f8bb9..8a669265a4ce99da4f5b14f6b6cadb95a0bf30cb 100644 --- a/bpt.c +++ b/bpt.c @@ -75,6 +75,7 @@ node *split(node *nd) { return parent; } node *insert_key(node *nd, int value) { + // insertion in case its a leaf if (is_a_leaf(nd)) { for (int i = 0; i < ORDER; i++) { // printf("im here 1 %d: et i : %d et ordrer is: %d\n", @@ -96,6 +97,7 @@ node *insert_key(node *nd, int value) { // return nd; // } } + // verifing if the leaf is full, if yes doint the split if (nd->NbOfElementsInTable == ORDER) { printf("u have to split\n"); nd->key[ORDER] = value; @@ -104,8 +106,9 @@ node *insert_key(node *nd, int value) { free(nd); return tmp; } + // doing the insertion if its not a leaf } else { - if (value < nd->key) { + if (value < nd->kids[1]) { insert_key(nd->kids[0], value); } else { insert_key(nd->kids[1], value); @@ -157,56 +160,38 @@ void print_tree(node *nd, int depth) { } return; } - -void bp_print(node *root, int depth) { - // if we are on a leaf, we can print the values directly next to each other - if (is_a_leaf(root)) { - for (int i = 0; i < depth; i++) - printf(" "); - for (int i = 0; i < ORDER; i++) { - printf(" %d |", root->key[i]); - // if we reach a 0, we have seen every values in the node - if (root->key[i + 1] == 0) - break; - } - printf("\n"); +const annuaire err_person = {.PhoneNum = "ERROR\0"}; +void print_data_annuaire(annuaire someone) { + if (someone.PhoneNum == err_person.PhoneNum) { + printf("this person doesn't exist \n"); return; } - - for (int i = 0; i < root->NbOfElementsInTable; i++) { - bp_print(root->kids[i], depth + 1); - printf("\n"); - - for (int i = 0; i < depth; i++) - printf(" "); - - printf(" %d |\n", root->key[i]); - - if (root->key[i + 1] == 0) - bp_print(root->kids[i + 1], depth + 1); - } - printf("\n"); + printf("Family name : %s\n", someone.Name); + printf("First name : %s\n", someone.FirstName); + printf("Phone number : %s\n", someone.PhoneNum); + printf("Birthday YYYY/MM/DD : %d%d%d\n", someone.Birthday->YYYY, + someone.Birthday->MM, someone.Birthday->DD); } // fuction to hash keys and transforming them into integers -/* -void hash(char *key, int length) { - unsigned char hash[SHA256_DIGEST_LENGTH]; - SHA256_CTX ctx; - SHA256_Init(&ctx); - SHA256_Update(&ctx, &key, length); - SHA256_Final(hash, &ctx); - uint64_t val = 0; - // pour passer de char à int - for (int i = 0; i < 8; i++) { - val |= hash[i]; - val <<= 8; - } - printf("%ld\n", val); - unsigned char outputBuffer[65]; - for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { - sprintf(outputBuffer + (i * 2), "%02x", hash[i]); - } - outputBuffer[64] = 0; - printf("%s\n", outputBuffer); -}*/ \ No newline at end of file +// void hash(char *key, int length) { + +// unsigned char hash[SHA256_DIGEST_LENGTH]; +// SHA256_CTX ctx; +// SHA256_Init(&ctx); +// SHA256_Update(&ctx, &key, length); +// SHA256_Final(hash, &ctx); +// uint64_t val = 0; +// // pour passer de char à int +// for (int i = 0; i < 8; i++) { +// val |= hash[i]; +// val <<= 8; +// } +// printf("%ld\n", val); +// unsigned char outputBuffer[65]; +// for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { +// sprintf(outputBuffer + (i * 2), "%02x", hash[i]); +// } +// outputBuffer[64] = 0; +// printf("%s\n", outputBuffer); +// } \ No newline at end of file diff --git a/bpt.h b/bpt.h index 2b043b943bb4e7ebfb23c3cbc7f3f83e4d1b9b3a..2e9ae9f91537d7d076f9fa2a8fb26f840e355b7f 100644 --- a/bpt.h +++ b/bpt.h @@ -1,13 +1,13 @@ #include <limits.h> #include <openssl/sha.h> #include <stdbool.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #ifndef B_PLUS_TREE #define B_PLUS_TREE - #define ORDER 4 typedef struct node { int NbOfElementsInTable; @@ -15,6 +15,15 @@ typedef struct node { struct node *kids[ORDER + 1]; struct node *next; } node; +typedef struct annuaire { + char PhoneNum[11]; + char Name[21]; + char FirstName[21]; + struct date *Birthday; +} annuaire; +typedef struct date { + uint8_t YYYY, DD, MM; +} date; node *creat_node(); bool is_a_leaf(node *nd); node *insert_key(node *nd, int value); @@ -23,4 +32,5 @@ node *delete_key(node *nd, int key); void destroy(node *nd); void print_tree(node *nd, int depth); void hash(char *key, int length); +void print_data_annuaire(annuaire someone); #endif diff --git a/main.c b/main.c index 00119a30fcd8de87d879b19f462a10307346db9b..88f1e5ae7269de9431aa550e035d4c663364066e 100644 --- a/main.c +++ b/main.c @@ -21,7 +21,7 @@ int main() { printf("\n"); printf("--------------------------------------\n"); - // new = insert_key(new, 7); + new = insert_key(new, 7); // new = insert_key(new, 4); // new = insert_key(new, 5); print_tree(new, 0);