Skip to content
Snippets Groups Projects
Commit 6960fc76 authored by Daniel Rodriguez's avatar Daniel Rodriguez
Browse files

écriture/lecture des records sur le disque

parent 331607a7
No related branches found
No related tags found
No related merge requests found
*.o
main
.vscode
*.dat
\ No newline at end of file
......@@ -194,12 +194,13 @@ b_tree insert_into_tree(b_tree tree, uint64_t key, record_t* record){
record_t* search(b_tree tree, uint64_t key){
int index = find_insertion_index(tree->keys, tree->count, key);
printf("%d\n", index);
//printf("%d\n", index);
if(!is_leaf(tree)){
return search(tree->children[index], key);
}
else{
printf("leaf: %lu, %lu\n", tree->keys[index-1], key);
//printf("leaf: %lu, %lu\n", tree->keys[index-1], key);
// gerer collisions ?
if(tree->keys[index-1] == key){
return tree->children[index];
}
......
......@@ -4,7 +4,6 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include "b-tree.h"
#include "record.h"
......@@ -28,6 +27,28 @@ uint64_t record_hash(record_t* r){
return hash(r->phone);
}
void write_database_to_disk(char* fileName, record_t* database, int size){
FILE* f;
f = fopen(fileName, "wb");
if(f == NULL){
assert(false);
}
fwrite(database, sizeof(record_t), size, f);
fclose(f);
}
void read_database_from_disk(char* fileName, record_t* database, int size){
FILE* f;
f = fopen(fileName, "rb");
if(f == NULL){
assert(false);
}
fread(database, sizeof(record_t), size, f);
fclose(f);
}
int main(){
//hash("essdfuihfs");
b_tree node = create_node();
......@@ -51,7 +72,13 @@ int main(){
uint64_t a[4] = {0, 2, 4, 5};
printf("%d\n", find_insertion_index(a, 4, 2));
//write_database_to_disk("test.dat", r, 1);
record_t* test = malloc(sizeof(record_t));
read_database_from_disk("test.dat", test, 1);
print_record(*test);
free_b(node);
free(r);
free(test);
return EXIT_SUCCESS;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment