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
3cadeb57
Commit
3cadeb57
authored
3 years ago
by
Alec
Browse files
Options
Downloads
Patches
Plain Diff
delete made for two cases out of 6, not tested yet tho
parent
343db3f1
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
+68
-0
68 additions, 0 deletions
bp_tree.c
with
68 additions
and
0 deletions
bp_tree.c
+
68
−
0
View file @
3cadeb57
...
@@ -56,6 +56,14 @@ void bp_node_shift(node *nd, int index) {
...
@@ -56,6 +56,14 @@ void bp_node_shift(node *nd, int index) {
}
}
}
}
void
bp_node_shit_del
(
node
*
nd
,
int
index
)
{
for
(
int
i
=
index
;
i
<
M
-
1
;
i
++
)
{
nd
->
user
[
i
]
=
nd
->
user
[
i
+
1
];
nd
->
data
[
i
]
=
nd
->
data
[
i
+
1
];
}
nd
->
data
[
M
-
1
]
=
0
;
}
node
*
bp_split
(
node
*
nd
)
{
node
*
bp_split
(
node
*
nd
)
{
node
*
new
=
bp_create_node
();
node
*
new
=
bp_create_node
();
/*
/*
...
@@ -289,6 +297,66 @@ node *bp_insert_val(node *tree, entry person) {
...
@@ -289,6 +297,66 @@ node *bp_insert_val(node *tree, entry person) {
return
tree
;
return
tree
;
}
}
// DELETE ----------------------------------------------------------
control
bp_delete_from
(
node
*
nd
,
uint64_t
key
)
{
control
c
=
{.
value
=
0
};
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
if
(
nd
->
data
[
i
]
==
key
)
{
nd
->
data
[
i
]
=
0
;
nd
->
count
--
;
if
(
i
!=
M
-
1
&&
nd
->
data
[
i
+
1
]
!=
0
)
{
bp_node_shit_del
(
nd
,
i
);
}
if
(
i
==
0
)
{
c
.
value
=
nd
->
data
[
0
];
}
}
}
return
c
;
}
control
bp_delete
(
node
*
nd
,
uint64_t
key
,
int
depth
)
{
control
c
;
if
(
bp_is_leaf
(
nd
))
{
c
=
bp_delete_from
(
nd
,
key
);
}
else
{
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
if
(
nd
->
data
[
i
]
>
key
||
nd
->
data
[
i
]
==
0
)
{
c
=
bp_delete
(
nd
->
childs
[
i
],
key
,
depth
+
1
);
break
;
}
// if a current key was deleted, we must replace it with the new key
if
(
c
.
value
!=
0
&&
depth
!=
0
)
{
for
(
int
i
=
0
;
i
<
M
;
i
++
)
if
(
nd
->
data
[
i
]
==
key
)
nd
->
data
[
i
]
=
c
.
value
;
return
c
;
}
}
}
if
(
c
.
value
!=
0
)
{
return
c
;
}
return
CONST_CONTR
;
}
node
*
bp_delete_val
(
node
*
tree
,
char
phone
[
11
])
{
uint64_t
hash_i
=
generate_key
(
phone
);
control
c
=
bp_delete
(
tree
,
hash_i
,
0
);
if
(
c
.
value
!=
0
)
{
for
(
int
i
=
0
;
i
<
M
;
i
++
)
if
(
tree
->
data
[
i
]
==
hash_i
)
tree
->
data
[
i
]
=
c
.
value
;
}
return
tree
;
}
// SEARCH ----------------------------------------------------------
// SEARCH ----------------------------------------------------------
entry
bp_search_node
(
node
*
tree
,
uint64_t
hash
)
{
entry
bp_search_node
(
node
*
tree
,
uint64_t
hash
)
{
...
...
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