Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ISC_144 - B+ Tree Project
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
florian.burgener
ISC_144 - B+ Tree Project
Commits
25661ee8
Commit
25661ee8
authored
2 years ago
by
Florian Burgener
Browse files
Options
Downloads
Patches
Plain Diff
Refactoring
parent
93a9c086
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/BPTree.c
+7
-6
7 additions, 6 deletions
src/BPTree.c
src/Directory.c
+20
-13
20 additions, 13 deletions
src/Directory.c
src/main.c
+0
-1
0 additions, 1 deletion
src/main.c
with
27 additions
and
20 deletions
src/BPTree.c
+
7
−
6
View file @
25661ee8
...
...
@@ -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
)
{
...
...
This diff is collapsed.
Click to expand it.
src/Directory.c
+
20
−
13
View file @
25661ee8
// 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
"
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main.c
+
0
−
1
View file @
25661ee8
#include
<assert.h>
// Warning : stdbool
#include
<stdbool.h>
#include
<stdio.h>
#include
<stdlib.h>
...
...
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