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
e09a4e27
Commit
e09a4e27
authored
3 years ago
by
Alec
Browse files
Options
Downloads
Patches
Plain Diff
refactor
parent
71cbafd4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bp_tree.c
+15
-46
15 additions, 46 deletions
bp_tree.c
with
15 additions
and
46 deletions
bp_tree.c
+
15
−
46
View file @
e09a4e27
...
...
@@ -152,31 +152,33 @@ control bp_split_unleaf(node *nd) {
return
new
;
}
// INSERT ----------------------------------------------------------
control
bp_insert_into
(
node
*
nd
,
control
val
)
{
void
bp_do_the_insert
(
node
*
nd
,
control
val
)
{
// look for a 0 in the node (it is guarenteed to exist in this version of
// the algorithm)
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
// if we plainly find a 0
if
(
nd
->
data
[
i
]
==
0
)
{
nd
->
data
[
i
]
=
val
.
value
;
// nd->childs[i] = val.lhs;
nd
->
childs
[
i
+
1
]
=
val
.
rhs
;
break
;
}
// if we need to insert the value between two values, we need to
// shift
er
everything greater than our value one case further
// shift 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
;
nd
->
childs
[
i
+
1
]
=
val
.
rhs
;
break
;
}
}
nd
->
count
++
;
}
// INSERT ----------------------------------------------------------
control
bp_insert_into
(
node
*
nd
,
control
val
)
{
bp_do_the_insert
(
nd
,
val
);
// if the node is now full, we split
if
(
nd
->
count
==
M
)
{
control
v
;
...
...
@@ -213,26 +215,10 @@ control bp_insert(node *nd, control val, int depth) {
break
;
}
}
// treat the control return here
// if a split happened and we are not the root
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
;
}
}
nd
->
count
++
;
bp_do_the_insert
(
nd
,
c
);
// if after the child split, the node is full, split the node
if
(
nd
->
count
==
M
)
...
...
@@ -252,33 +238,16 @@ control bp_insert(node *nd, control val, int depth) {
node
*
bp_insert_val
(
node
*
tree
,
int
val
)
{
// Parse the val into a control struct then insert it in the tree
control
test
=
bp_insert
(
tree
,
value_to_insert
(
val
),
0
);
/*
depending on the control item, we act differently
if the control has pointers to node, then we had a split in the direct
childs of the root. We must add the values upringed to the root
childs of the root. We must add the values upringed to the root
*/
if
(
test
.
rhs
!=
NULL
)
{
/*
if the root isn't a leaf, first we add the value into the node
we can't use bp_insert_into() as if we need a split, the way we
do it is slightly different
*/
// if the root isn't a leaf, first we add the value into the node
if
(
!
bp_is_leaf
(
tree
))
{
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
if
(
tree
->
data
[
i
]
==
0
)
{
tree
->
childs
[
i
+
1
]
=
test
.
rhs
;
tree
->
data
[
i
]
=
test
.
value
;
break
;
}
if
(
tree
->
data
[
i
]
>
test
.
value
)
{
bp_node_shift
(
tree
,
i
);
tree
->
data
[
i
]
=
test
.
value
;
tree
->
childs
[
i
+
1
]
=
test
.
rhs
;
break
;
}
}
tree
->
count
++
;
bp_do_the_insert
(
tree
,
test
);
// If the root is full, we must split it
if
(
tree
->
count
==
M
)
{
return
bp_split_root
(
tree
);
...
...
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