Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP_Bplus_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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hepia_2021-2022
Prog_Seq
TP_Bplus_Tree
Commits
25b42d79
Commit
25b42d79
authored
3 years ago
by
Alec
Browse files
Options
Downloads
Patches
Plain Diff
faut trouver pourquoi unsigned sort du signed
parent
e09a4e27
No related branches found
No related tags found
No related merge requests found
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
bp_tree.c
+12
-8
12 additions, 8 deletions
bp_tree.c
bp_tree.h
+21
-3
21 additions, 3 deletions
bp_tree.h
hash.c
+30
-0
30 additions, 0 deletions
hash.c
hash.h
+8
-0
8 additions, 0 deletions
hash.h
main.c
+37
-2
37 additions, 2 deletions
main.c
makefile
+7
-3
7 additions, 3 deletions
makefile
with
115 additions
and
16 deletions
bp_tree.c
+
12
−
8
View file @
25b42d79
#include
"bp_tree.h"
#include
"hash.h"
#include
<math.h>
#include
<stdbool.h>
#include
<stdio.h>
...
...
@@ -7,7 +8,7 @@
// UTILS ----------------------------------------------------------
typedef
struct
control
{
int
value
;
u
int
64_t
value
;
node
*
lhs
;
node
*
rhs
;
}
control
;
...
...
@@ -23,10 +24,11 @@ node *bp_create_node() {
nd
->
data
[
i
]
=
0
;
nd
->
count
=
0
;
nd
->
next
=
NULL
;
nd
->
user
=
NULL
;
return
nd
;
}
control
value_to_insert
(
int
val
)
{
control
value_to_insert
(
u
int
64_t
val
)
{
control
c
;
c
.
value
=
val
;
c
.
lhs
=
c
.
rhs
=
NULL
;
...
...
@@ -228,16 +230,18 @@ control bp_insert(node *nd, control val, int depth) {
}
}
// if a split happened
// if a split happened
(reaches this only when in leaves)
if
(
c
.
value
!=
0
)
{
return
c
;
}
return
CONST_CONTR
;
}
node
*
bp_insert_val
(
node
*
tree
,
int
val
)
{
node
*
bp_insert_val
(
node
*
tree
,
entry
person
)
{
uint64_t
hash_i
=
generate_key
(
person
.
phone
);
// Parse the val into a control struct then insert it in the tree
control
test
=
bp_insert
(
tree
,
value_to_insert
(
val
),
0
);
control
test
=
bp_insert
(
tree
,
value_to_insert
(
hash_i
),
0
);
/*
depending on the control item, we act differently
if the control has pointers to node, then we had a split in the direct
...
...
@@ -303,7 +307,7 @@ void bp_print_as_ll(node *root) {
// print every values in the node until hitting 0, then we can get on the
// next node
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
printf
(
" %d |"
,
root
->
data
[
i
]);
printf
(
" %
l
d |"
,
root
->
data
[
i
]);
if
(
root
->
data
[
i
+
1
]
==
0
)
{
printf
(
" -> "
);
return
bp_print_as_ll
(
root
->
next
);
...
...
@@ -317,7 +321,7 @@ void bp_print(node *root, int depth) {
for
(
int
i
=
0
;
i
<
depth
;
i
++
)
printf
(
" "
);
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
printf
(
" %d |"
,
root
->
data
[
i
]);
printf
(
" %
l
d |"
,
root
->
data
[
i
]);
// if we reach a 0, we have seen every values in the node
if
(
root
->
data
[
i
+
1
]
==
0
)
break
;
...
...
@@ -332,7 +336,7 @@ void bp_print(node *root, int depth) {
for
(
int
i
=
0
;
i
<
depth
;
i
++
)
printf
(
" "
);
printf
(
" %d |
\n
"
,
root
->
data
[
i
]);
printf
(
" %
l
d |
\n
"
,
root
->
data
[
i
]);
if
(
root
->
data
[
i
+
1
]
==
0
)
return
bp_print
(
root
->
childs
[
i
+
1
],
depth
+
1
);
...
...
This diff is collapsed.
Click to expand it.
bp_tree.h
+
21
−
3
View file @
25b42d79
#ifndef _BP_TREE_C_
#define _BP_TREE_C_
#define M 4
#include
<stdint.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#define M 4
typedef
struct
date
{
uint8_t
day
;
uint8_t
month
;
// 0 = January, 11 = December
uint8_t
year
;
// value stored is year - 1900
}
date
;
typedef
struct
entry
{
char
phone
[
11
];
char
f_name
[
21
];
char
l_name
[
21
];
struct
date
birth
;
}
entry
;
typedef
struct
node
{
struct
node
*
childs
[
M
+
1
];
int
data
[
M
];
u
int
64_t
data
[
M
];
int
count
;
struct
node
*
next
;
struct
entry
*
user
;
}
node
;
/**
...
...
@@ -40,7 +58,7 @@ node *bp_create_node();
* @param val Value to insert
* @return New root of the tree
*/
node
*
bp_insert_val
(
node
*
tree
,
i
nt
val
);
node
*
bp_insert_val
(
node
*
tree
,
e
nt
ry
person
);
/**
* @brief Print in CLI the leaves of the B+ Tree as a linked list
...
...
This diff is collapsed.
Click to expand it.
hash.c
0 → 100644
+
30
−
0
View file @
25b42d79
#include
"hash.h"
#include
<openssl/sha.h>
#include
<stdint.h>
#include
<stdio.h>
#include
<string.h>
uint64_t
generate_key
(
char
*
string
)
{
unsigned
char
hash
[
SHA256_DIGEST_LENGTH
];
SHA256_CTX
ctx
;
SHA256_Init
(
&
ctx
);
SHA256_Update
(
&
ctx
,
string
,
strlen
(
string
));
SHA256_Final
(
hash
,
&
ctx
);
uint64_t
val
=
0
;
for
(
int
i
=
0
;
i
<
8
;
i
++
)
{
val
|=
hash
[
i
];
val
<<=
8
;
}
// Uncomment to print the full hash value
/*
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);
*/
return
val
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
hash.h
0 → 100644
+
8
−
0
View file @
25b42d79
#ifndef _HASH_H_
#define _HASH_H_
#include
<stdint.h>
#include
<stdio.h>
uint64_t
generate_key
(
char
*
string
);
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main.c
+
37
−
2
View file @
25b42d79
#include
"bp_tree.h"
#include
"hash.h"
#include
<stdio.h>
#include
<stdlib.h>
int
main
()
{
node
*
tree
=
bp_create_node
();
entry
person
;
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
person
.
phone
[
i
]
=
'1'
;
}
person
.
phone
[
10
]
=
'\0'
;
tree
=
bp_insert_val
(
tree
,
person
);
bp_print
(
tree
,
0
);
printf
(
"
\n
|||||||||
\n
"
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
person
.
phone
[
i
]
=
'2'
;
}
tree
=
bp_insert_val
(
tree
,
person
);
bp_print
(
tree
,
0
);
printf
(
"
\n
|||||||||
\n
"
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
person
.
phone
[
i
]
=
'3'
;
}
tree
=
bp_insert_val
(
tree
,
person
);
bp_print
(
tree
,
0
);
printf
(
"
\n
|||||||||
\n
"
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
person
.
phone
[
i
]
=
'4'
;
}
tree
=
bp_insert_val
(
tree
,
3
);
tree
=
bp_insert_val
(
tree
,
person
);
bp_print
(
tree
,
0
);
printf
(
"
\n
|||||||||
\n
"
);
/*
tree = bp_insert_val(tree, 6);
bp_print(tree, 0);
...
...
@@ -68,6 +102,7 @@ int main() {
tree = bp_insert_val(tree, 18);
bp_print(tree, 0);
printf("\n|||||||||\n");
*/
bp_print_as_ll
(
tree
);
bp_destroy
(
tree
);
return
0
;
...
...
This diff is collapsed.
Click to expand it.
makefile
+
7
−
3
View file @
25b42d79
CC
=
gcc
FLAGS
=
-Wall
-Werror
CFLAGS
=
-g
-std
=
c99
FLAGS
=
-Werror
CFLAGS
=
-g
-std
=
c99
-lssl
-lcrypto
LDFLAGS
=
-fsanitize
=
address
-fsanitize
=
leak
exe
:
main
./
$^
main
:
main.o bp_tree.o
main
:
main.o bp_tree.o
hash.o
$(
CC
)
$^
-o
$@
$(
CFLAGS
)
$(
LDFLAGS
)
-lm
main.o
:
main.c
...
...
@@ -15,6 +15,10 @@ main.o: main.c
bp_tree.o
:
bp_tree.c bp_tree.h
$(
CC
)
$(
FLAGS
)
$(
CFLAGS
)
$(
LDFLAGS
)
-c
$<
hash.o
:
hash.c hash.h
$(
CC
)
$(
FLAGS
)
$(
CFLAGS
)
$(
LDFLAGS
)
-c
$<
clean
:
rm
-f
*
.o
test
...
...
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