Skip to content
Snippets Groups Projects
Commit 25661ee8 authored by Florian Burgener's avatar Florian Burgener
Browse files

Refactoring

parent 93a9c086
Branches
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ static bool has_maximum_keys(BPTreeNode *node) {
static BPTreeNode *find_leaf(BPTreeNode *root, uint64_t key, BPTreeNodeArray **parents) {
BPTreeNode *current = root;
// TODO : 10 is not enough.
// CAUTION : 10 is not enough.
*parents = BPTreeNodeArray_init(10);
while (!current->is_leaf) {
......@@ -70,11 +70,11 @@ void BPTree_print(BPTreeNode *root, int depth) {
}
IntegerArray_print(root->keys);
// for (int i = 0; i < depth; i++) {
// printf(" ");
// }
// printf("*");
// IntegerArray_print(root->data);
for (int i = 0; i < depth; i++) {
printf(" ");
}
printf("*");
IntegerArray_print(root->data);
for (int i = 0; i < root->children->size; i++) {
BPTree_print(root->children->items[i], depth + 1);
......@@ -281,6 +281,7 @@ static void _merge(BPTreeNode *parent, BPTreeNode *main_node, BPTreeNode *second
static void merge(BPTreeNode *parent, BPTreeNode *node, BPTreeNode *sibling);
static BPTreeNode *find_sibling(BPTreeNode *parent, BPTreeNode *node);
static void deletion_rebalance(BPTreeNode *root, BPTreeNodeArray *parents, BPTreeNode *node, uint64_t key);
static void replace_deleted_key_internal(BPTreeNodeArray *parents, int i, uint64_t key);
static uint64_t find_smallest_key(BPTreeNode *root) {
if (root->is_leaf) {
......
// CAUTION : l'implémentation ne va pas fonctionner avec les records supprimés (deleted variable).
// Je devrais refactor l'implémentation avec le FILE.
// CAUTION : Je devrais refactor l'implémentation avec le FILE.
#include "Directory.h"
......@@ -10,8 +9,8 @@
#include <string.h>
#include "Array.h"
#include "DirectoryRecord.h"
#include "BPTree.h"
#include "DirectoryRecord.h"
static uint64_t hash_string(char *str) {
SHA256_CTX sha256;
......@@ -52,12 +51,18 @@ static void rebuild_index(Directory *directory) {
while (true) {
uint64_t data_ptr = (uint64_t)ftell(fp);
fseek(fp, 1, SEEK_CUR);
char phone_number[PHONE_NUMBER_MAX_LENGTH];
phone_number[PHONE_NUMBER_MAX_LENGTH - 1] = '\0';
fread(phone_number, 1, PHONE_NUMBER_MAX_LENGTH_WITHOUT_NULL_CHARACTER, fp);
BPTree_insert(directory->index, hash_string(phone_number), data_ptr);
fseek(fp, DirectoryRecord_size_on_disk() - 1 - PHONE_NUMBER_MAX_LENGTH_WITHOUT_NULL_CHARACTER, SEEK_CUR);
uint8_t deleted;
fread(&deleted, 1, 1, fp);
if ((bool)deleted) {
fseek(fp, DirectoryRecord_size_on_disk() - 1, SEEK_CUR);
} else {
char phone_number[PHONE_NUMBER_MAX_LENGTH];
phone_number[PHONE_NUMBER_MAX_LENGTH - 1] = '\0';
fread(phone_number, 1, PHONE_NUMBER_MAX_LENGTH_WITHOUT_NULL_CHARACTER, fp);
BPTree_insert(directory->index, hash_string(phone_number), data_ptr);
fseek(fp, DirectoryRecord_size_on_disk() - 1 - PHONE_NUMBER_MAX_LENGTH_WITHOUT_NULL_CHARACTER, SEEK_CUR);
}
if (ftell(fp) == file_size) {
break;
......@@ -99,15 +104,17 @@ void Directory_print(Directory *directory) {
fread(byte_array->items, 1, DirectoryRecord_size_on_disk(), fp);
byte_array->size = DirectoryRecord_size_on_disk();
DirectoryRecord *record = ByteArray_to_DirectoryRecord(byte_array);
DirectoryRecord_print(record);
DirectoryRecord_destroy(&record);
if (!(bool)byte_array->items[0]) {
DirectoryRecord *record = ByteArray_to_DirectoryRecord(byte_array);
DirectoryRecord_print(record);
DirectoryRecord_destroy(&record);
}
ByteArray_destroy(&byte_array);
if (ftell(fp) == file_size) {
break;
} else {
} else if (!(bool)byte_array->items[0]) {
printf("------------------------\n");
}
}
......
#include <assert.h>
// Warning : stdbool
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment