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
a85cf7ea
Commit
a85cf7ea
authored
3 years ago
by
Alec
Browse files
Options
Downloads
Patches
Plain Diff
derniers bugs corrigés, plus qu'à refactorer
parent
d7a28fbb
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
bp_tree.c
+95
-16
95 additions, 16 deletions
bp_tree.c
bp_tree.h
+8
-0
8 additions, 0 deletions
bp_tree.h
main.c
+11
-2
11 additions, 2 deletions
main.c
with
114 additions
and
18 deletions
bp_tree.c
+
95
−
16
View file @
a85cf7ea
...
@@ -68,13 +68,47 @@ node *bp_split(node *nd) {
...
@@ -68,13 +68,47 @@ node *bp_split(node *nd) {
for
(
int
i
=
0
;
i
<
upto
;
i
++
)
{
for
(
int
i
=
0
;
i
<
upto
;
i
++
)
{
new
->
data
[
i
]
=
nd
->
data
[
index
+
i
];
new
->
data
[
i
]
=
nd
->
data
[
index
+
i
];
nd
->
data
[
index
+
i
]
=
0
;
nd
->
data
[
index
+
i
]
=
0
;
new
->
childs
[
i
]
=
nd
->
childs
[
index
+
i
];
//
new->childs[i] = nd->childs[index + i];
nd
->
childs
[
index
+
i
]
=
NULL
;
//
nd->childs[index + i] = NULL;
}
}
return
new
;
return
new
;
}
}
control
bp_split_unleaf
(
node
*
nd
)
{
control
new
;
node
*
rhs
=
bp_create_node
();
int
index
=
(
int
)
floor
(
M
/
2
);
int
looper
=
index
;
nd
->
count
=
index
;
rhs
->
count
=
index
;
if
(
M
%
2
==
0
)
{
looper
--
;
rhs
->
count
--
;
}
for
(
int
i
=
0
;
i
<=
looper
;
i
++
)
{
rhs
->
childs
[
i
]
=
nd
->
childs
[
index
+
i
+
1
];
nd
->
childs
[
index
+
i
+
1
]
=
NULL
;
}
for
(
int
i
=
0
;
i
<
looper
;
i
++
)
{
rhs
->
data
[
i
]
=
nd
->
data
[
index
+
i
+
1
];
nd
->
data
[
index
+
i
+
1
]
=
0
;
}
new
.
lhs
=
nd
;
new
.
rhs
=
rhs
;
new
.
value
=
nd
->
data
[
index
];
nd
->
data
[
index
]
=
0
;
return
new
;
}
control
bp_insert_into
(
node
*
nd
,
control
val
)
{
control
bp_insert_into
(
node
*
nd
,
control
val
)
{
// look for a 0 in the node (it is guarenteed to exist in this version of
// look for a 0 in the node (it is guarenteed to exist in this version of
// the algorithm)
// the algorithm)
...
@@ -82,7 +116,8 @@ control bp_insert_into(node *nd, control val) {
...
@@ -82,7 +116,8 @@ control bp_insert_into(node *nd, control val) {
// if we plainly find a 0
// if we plainly find a 0
if
(
nd
->
data
[
i
]
==
0
)
{
if
(
nd
->
data
[
i
]
==
0
)
{
nd
->
data
[
i
]
=
val
.
value
;
nd
->
data
[
i
]
=
val
.
value
;
nd
->
childs
[
i
]
=
val
.
lhs
;
// nd->childs[i] = val.lhs;
nd
->
childs
[
i
+
1
]
=
val
.
rhs
;
break
;
break
;
}
}
...
@@ -115,7 +150,7 @@ control bp_insert_into(node *nd, control val) {
...
@@ -115,7 +150,7 @@ control bp_insert_into(node *nd, control val) {
return
CONST_CONTR
;
return
CONST_CONTR
;
}
}
control
bp_insert
(
node
*
nd
,
control
val
)
{
control
bp_insert
(
node
*
nd
,
control
val
,
int
depth
)
{
control
c
;
// will help us to return the pivot, and the two pointers of the
control
c
;
// will help us to return the pivot, and the two pointers of the
// childs-to-be
// childs-to-be
...
@@ -126,11 +161,59 @@ control bp_insert(node *nd, control val) {
...
@@ -126,11 +161,59 @@ control bp_insert(node *nd, control val) {
{
{
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
if
(
nd
->
data
[
i
]
>
val
.
value
||
nd
->
data
[
i
]
==
0
)
{
if
(
nd
->
data
[
i
]
>
val
.
value
||
nd
->
data
[
i
]
==
0
)
{
c
=
bp_insert
(
nd
->
childs
[
i
],
val
);
c
=
bp_insert
(
nd
->
childs
[
i
],
val
,
depth
+
1
);
break
;
}
}
if
(
c
.
value
!=
0
&&
depth
!=
0
)
{
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
// if we plainly find a 0
if
(
nd
->
data
[
i
]
==
0
)
{
nd
->
data
[
i
]
=
c
.
value
;
// nd->childs[i] = val.lhs;
nd
->
childs
[
i
+
1
]
=
c
.
rhs
;
break
;
}
// if we need to insert the value between two values, we need to
// shifter everything greater than our value one case further
if
(
nd
->
data
[
i
]
>
val
.
value
)
{
bp_node_shift
(
nd
,
i
);
nd
->
data
[
i
]
=
val
.
value
;
nd
->
childs
[
i
]
=
val
.
rhs
;
break
;
break
;
}
}
}
}
nd
->
count
++
;
// YA PLUS QU'A SPLIT ICI SI BESOIN
if
(
nd
->
count
==
M
)
{
/*
node *new = bp_create_node();
new->count = 1;
new->childs[0] = nd->childs[3];
new->childs[1] = nd->childs[4];
new->data[0] = nd->data[3];
control test;
test.value = nd->data[2];
test.lhs = nd;
test.rhs = new;
nd->childs[3] = NULL;
nd->childs[4] = NULL;
nd->data[3] = 0;
nd->data[2] = 0;
return test;*/
return
bp_split_unleaf
(
nd
);
}
return
CONST_CONTR
;
}
}
}
// if a split happened
// if a split happened
if
(
c
.
value
!=
0
)
{
if
(
c
.
value
!=
0
)
{
return
c
;
return
c
;
...
@@ -139,16 +222,19 @@ control bp_insert(node *nd, control val) {
...
@@ -139,16 +222,19 @@ control bp_insert(node *nd, control val) {
}
}
node
*
bp_split_root
(
node
*
root
)
{
node
*
bp_split_root
(
node
*
root
)
{
// TEMPORARY FUNC (COPYRIGHT), HARD WRITTEN NEEDS TO BE SOFT
node
*
new
=
bp_create_node
();
node
*
new
=
bp_create_node
();
node
*
rhs
=
bp_create_node
();
node
*
rhs
=
bp_create_node
();
int
index
=
(
int
)
floor
(
M
/
2
);
int
index
=
(
int
)
floor
(
M
/
2
);
int
looper
=
index
;
int
looper
=
index
;
new
->
count
=
1
;
root
->
count
=
index
;
rhs
->
count
=
index
;
if
(
M
%
2
==
0
)
{
if
(
M
%
2
==
0
)
{
looper
--
;
looper
--
;
rhs
->
count
--
;
}
}
for
(
int
i
=
0
;
i
<=
looper
;
i
++
)
{
for
(
int
i
=
0
;
i
<=
looper
;
i
++
)
{
...
@@ -167,19 +253,12 @@ node *bp_split_root(node *root) {
...
@@ -167,19 +253,12 @@ node *bp_split_root(node *root) {
root
->
data
[
index
]
=
0
;
root
->
data
[
index
]
=
0
;
new
->
count
=
1
;
root
->
count
=
index
;
rhs
->
count
=
index
;
if
(
M
%
2
==
0
)
{
rhs
->
count
--
;
}
return
new
;
return
new
;
}
}
node
*
bp_insert_val
(
node
*
tree
,
int
val
)
{
node
*
bp_insert_val
(
node
*
tree
,
int
val
)
{
// Parse the val into a control struct then insert it in the tree
// Parse the val into a control struct then insert it in the tree
control
test
=
bp_insert
(
tree
,
value_to_insert
(
val
));
control
test
=
bp_insert
(
tree
,
value_to_insert
(
val
)
,
0
);
/*
/*
depending on the control item, we act differently
depending on the control item, we act differently
...
...
This diff is collapsed.
Click to expand it.
bp_tree.h
+
8
−
0
View file @
a85cf7ea
...
@@ -10,7 +10,15 @@ typedef struct node {
...
@@ -10,7 +10,15 @@ typedef struct node {
int
count
;
int
count
;
struct
node
*
next
;
struct
node
*
next
;
}
node
;
}
node
;
/*
typedef struct cell {
} cell;
typedef struct page {
struct
} page;
*/
/**
/**
* @brief Print in CLI a B+ Tree
* @brief Print in CLI a B+ Tree
*
*
...
...
This diff is collapsed.
Click to expand it.
main.c
+
11
−
2
View file @
a85cf7ea
...
@@ -8,13 +8,13 @@ int main() {
...
@@ -8,13 +8,13 @@ int main() {
tree
=
bp_insert_val
(
tree
,
3
);
tree
=
bp_insert_val
(
tree
,
3
);
bp_print
(
tree
,
0
);
bp_print
(
tree
,
0
);
printf
(
"
\n
|||||||||
\n
"
);
printf
(
"
\n
|||||||||
\n
"
);
tree
=
bp_insert_val
(
tree
,
6
);
tree
=
bp_insert_val
(
tree
,
4
);
bp_print
(
tree
,
0
);
bp_print
(
tree
,
0
);
printf
(
"
\n
|||||||||
\n
"
);
printf
(
"
\n
|||||||||
\n
"
);
tree
=
bp_insert_val
(
tree
,
5
);
tree
=
bp_insert_val
(
tree
,
5
);
bp_print
(
tree
,
0
);
bp_print
(
tree
,
0
);
printf
(
"
\n
|||||||||
\n
"
);
printf
(
"
\n
|||||||||
\n
"
);
tree
=
bp_insert_val
(
tree
,
4
);
tree
=
bp_insert_val
(
tree
,
6
);
bp_print
(
tree
,
0
);
bp_print
(
tree
,
0
);
printf
(
"
\n
|||||||||
\n
"
);
printf
(
"
\n
|||||||||
\n
"
);
tree
=
bp_insert_val
(
tree
,
7
);
tree
=
bp_insert_val
(
tree
,
7
);
...
@@ -44,6 +44,15 @@ int main() {
...
@@ -44,6 +44,15 @@ int main() {
tree
=
bp_insert_val
(
tree
,
15
);
tree
=
bp_insert_val
(
tree
,
15
);
bp_print
(
tree
,
0
);
bp_print
(
tree
,
0
);
printf
(
"
\n
|||||||||
\n
"
);
printf
(
"
\n
|||||||||
\n
"
);
tree
=
bp_insert_val
(
tree
,
16
);
bp_print
(
tree
,
0
);
printf
(
"
\n
|||||||||
\n
"
);
tree
=
bp_insert_val
(
tree
,
17
);
bp_print
(
tree
,
0
);
printf
(
"
\n
|||||||||
\n
"
);
tree
=
bp_insert_val
(
tree
,
18
);
bp_print
(
tree
,
0
);
printf
(
"
\n
|||||||||
\n
"
);
bp_print_as_ll
(
tree
);
bp_print_as_ll
(
tree
);
bp_destroy
(
tree
);
bp_destroy
(
tree
);
return
0
;
return
0
;
...
...
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