Skip to content
Snippets Groups Projects
Commit 1120d127 authored by omar.alkheja's avatar omar.alkheja
Browse files

getting done few things instead nothing

parent 6d16df21
No related branches found
No related tags found
No related merge requests found
......@@ -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
#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
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment