Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tp_B+Tree
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
daniel.rodrigue1
tp_B+Tree
Commits
6960fc76
Commit
6960fc76
authored
3 years ago
by
Daniel Rodriguez
Browse files
Options
Downloads
Patches
Plain Diff
écriture/lecture des records sur le disque
parent
331607a7
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+2
-1
2 additions, 1 deletion
.gitignore
b-tree.c
+3
-2
3 additions, 2 deletions
b-tree.c
main.c
+28
-1
28 additions, 1 deletion
main.c
with
33 additions
and
4 deletions
.gitignore
+
2
−
1
View file @
6960fc76
*.o
main
.vscode
*.dat
\ No newline at end of file
This diff is collapsed.
Click to expand it.
b-tree.c
+
3
−
2
View file @
6960fc76
...
...
@@ -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
];
}
...
...
This diff is collapsed.
Click to expand it.
main.c
+
28
−
1
View file @
6960fc76
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment