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
GitLab 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
11a5e65f
Commit
11a5e65f
authored
3 years ago
by
Florian Burgener
Browse files
Options
Downloads
Patches
Plain Diff
Deletion: conversion from iterative to recursive
parent
25661ee8
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Tampermonkey.js
+62
-47
62 additions, 47 deletions
Tampermonkey.js
src/BPTree.c
+42
-50
42 additions, 50 deletions
src/BPTree.c
src/BPTree.h
+1
-1
1 addition, 1 deletion
src/BPTree.h
with
105 additions
and
98 deletions
Tampermonkey.js
+
62
−
47
View file @
11a5e65f
// ==UserScript==
// @name Automation
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.cs.usfca.edu/~galles/visualization/BPlusTree.html
// @icon https://www.google.com/s2/favicons?sz=64&domain=usfca.edu
// @grant none
// ==/UserScript==
(
function
()
{
'
use strict
'
;
window
.
addEventListener
(
'
load
'
,
function
()
{
window
.
addEventListener
(
'
load
'
,
function
()
{
var
table_AlgorithmSpecificControls
=
document
.
getElementById
(
"
AlgorithmSpecificControls
"
);
var
table_AlgorithmSpecificControls
=
document
.
getElementById
(
"
AlgorithmSpecificControls
"
);
var
insert_input
=
table_AlgorithmSpecificControls
.
children
[
0
].
children
[
0
];
var
insert_input
=
table_AlgorithmSpecificControls
.
children
[
0
].
children
[
0
];
...
@@ -38,10 +52,11 @@ window.addEventListener('load', function() {
...
@@ -38,10 +52,11 @@ window.addEventListener('load', function() {
await
timeout
(
500
);
await
timeout
(
500
);
await
insert_keys
([
8
,
12
,
11
,
47
,
22
,
95
,
86
,
40
,
33
,
78
,
28
,
5
,
75
,
88
,
21
,
56
,
82
,
51
,
93
,
66
,
48
,
70
,
57
,
65
,
35
,
4
,
60
,
41
,
49
,
55
]);
await
insert_keys
([
8
,
12
,
11
,
47
,
22
,
95
,
86
,
40
,
33
,
78
,
28
,
5
,
75
,
88
,
21
,
56
,
82
,
51
,
93
,
66
,
48
,
70
,
57
,
65
,
35
,
4
,
60
,
41
,
49
,
55
]);
await
delete_keys
([
65
,
57
,
47
,
28
,
51
]);
await
delete_keys
([
65
,
57
,
47
]);
await
insert_keys
([
100
]);
//
await insert_keys([100]);
await
delete_keys
([
48
,
41
,
60
,
5
,
8
,
21
,
86
,
100
,
88
,
95
,
49
,
56
,
55
]);
//
await delete_keys([48, 41, 60, 5, 8, 21, 86, 100, 88, 95, 49, 56, 55]);
}
}
do_stuff
();
do_stuff
();
},
false
);
},
false
);
})();
This diff is collapsed.
Click to expand it.
src/BPTree.c
+
42
−
50
View file @
11a5e65f
...
@@ -73,7 +73,7 @@ void BPTree_print(BPTreeNode *root, int depth) {
...
@@ -73,7 +73,7 @@ void BPTree_print(BPTreeNode *root, int depth) {
for
(
int
i
=
0
;
i
<
depth
;
i
++
)
{
for
(
int
i
=
0
;
i
<
depth
;
i
++
)
{
printf
(
" "
);
printf
(
" "
);
}
}
printf
(
"
*
"
);
printf
(
"
"
);
IntegerArray_print
(
root
->
data
);
IntegerArray_print
(
root
->
data
);
for
(
int
i
=
0
;
i
<
root
->
children
->
size
;
i
++
)
{
for
(
int
i
=
0
;
i
<
root
->
children
->
size
;
i
++
)
{
...
@@ -280,8 +280,9 @@ static void steal_leaf(BPTreeNode *parent, BPTreeNode *node, int child_index, BP
...
@@ -280,8 +280,9 @@ static void steal_leaf(BPTreeNode *parent, BPTreeNode *node, int child_index, BP
static
void
_merge
(
BPTreeNode
*
parent
,
BPTreeNode
*
main_node
,
BPTreeNode
*
secondary_node
,
int
pivot_index
);
static
void
_merge
(
BPTreeNode
*
parent
,
BPTreeNode
*
main_node
,
BPTreeNode
*
secondary_node
,
int
pivot_index
);
static
void
merge
(
BPTreeNode
*
parent
,
BPTreeNode
*
node
,
BPTreeNode
*
sibling
);
static
void
merge
(
BPTreeNode
*
parent
,
BPTreeNode
*
node
,
BPTreeNode
*
sibling
);
static
BPTreeNode
*
find_sibling
(
BPTreeNode
*
parent
,
BPTreeNode
*
node
);
static
BPTreeNode
*
find_sibling
(
BPTreeNode
*
parent
,
BPTreeNode
*
node
);
static
void
deletion_rebalance
(
BPTreeNode
*
root
,
BPTreeNodeArray
*
parents
,
BPTreeNode
*
node
,
uint64_t
key
);
static
bool
_BPTree_delete
(
BPTreeNode
*
root
,
uint64_t
key
,
BPTreeNode
*
parent
);
static
void
replace_deleted_key_internal
(
BPTreeNodeArray
*
parents
,
int
i
,
uint64_t
key
);
static
BPTreeNode
*
traverse
(
BPTreeNode
*
root
,
uint64_t
key
);
static
void
deletion_rebalance
(
BPTreeNode
*
root
,
BPTreeNode
*
parent
);
static
uint64_t
find_smallest_key
(
BPTreeNode
*
root
)
{
static
uint64_t
find_smallest_key
(
BPTreeNode
*
root
)
{
if
(
root
->
is_leaf
)
{
if
(
root
->
is_leaf
)
{
...
@@ -414,67 +415,58 @@ static BPTreeNode *find_sibling(BPTreeNode *parent, BPTreeNode *node) {
...
@@ -414,67 +415,58 @@ static BPTreeNode *find_sibling(BPTreeNode *parent, BPTreeNode *node) {
return
parent
->
children
->
items
[
child_index
-
1
];
return
parent
->
children
->
items
[
child_index
-
1
];
}
}
static
void
deletion_rebalance
(
BPTreeNode
*
root
,
BPTreeNodeArray
*
parents
,
BPTreeNode
*
node
,
uint64_t
key
)
{
static
BPTreeNode
*
traverse
(
BPTreeNode
*
root
,
uint64_t
key
)
{
BPTreeNode
*
parent
=
NULL
;
int
virtual_insertion_index
=
lower_bound
(
root
->
keys
,
key
)
;
if
(
parents
->
size
>
0
)
{
if
(
virtual_insertion_index
<
root
->
keys
->
size
&&
root
->
keys
->
items
[
virtual_insertion_index
]
==
key
)
{
parent
=
BPTreeNodeArray_pop
(
parents
)
;
virtual_insertion_index
+=
1
;
}
}
if
(
node
!=
root
&&
node
->
keys
->
size
<
node
->
order
)
{
return
root
->
children
->
items
[
virtual_insertion_index
];
int
child_index
=
find_child_index
(
parent
,
node
);
}
BPTreeNode
*
sibling
=
find_sibling
(
parent
,
node
);
if
(
sibling
->
keys
->
size
==
sibling
->
order
)
{
static
void
deletion_rebalance
(
BPTreeNode
*
root
,
BPTreeNode
*
parent
)
{
merge
(
parent
,
node
,
sibling
);
int
child_index
=
find_child_index
(
parent
,
root
);
BPTreeNode
*
sibling
=
find_sibling
(
parent
,
root
);
if
(
parent
==
root
&&
parent
->
keys
->
size
==
0
)
{
if
(
sibling
->
keys
->
size
==
sibling
->
order
)
{
shrink
(
root
);
merge
(
parent
,
root
,
sibling
);
parent
=
NULL
;
}
else
if
(
root
->
is_leaf
)
{
}
steal_leaf
(
parent
,
root
,
child_index
,
sibling
);
}
else
{
if
(
node
->
is_leaf
)
{
steal_leaf
(
parent
,
node
,
child_index
,
sibling
);
}
else
{
}
else
{
steal_internal
(
parent
,
node
,
child_index
,
sibling
);
steal_internal
(
parent
,
root
,
child_index
,
sibling
);
}
}
}
}
}
if
(
parent
!=
NULL
)
{
static
bool
_BPTree_delete
(
BPTreeNode
*
root
,
uint64_t
key
,
BPTreeNode
*
parent
)
{
deletion_rebalance
(
root
,
parents
,
parent
,
key
);
if
(
!
root
->
is_leaf
&&
!
_BPTree_delete
(
traverse
(
root
,
key
),
key
,
root
))
{
}
return
false
;
}
}
static
void
replace_deleted_key_internal
(
BPTreeNodeArray
*
parents
,
int
i
,
uint64_t
key
)
{
if
(
i
<
0
)
{
return
;
}
BPTreeNode
*
node
=
parents
->
items
[
i
];
int
index
;
int
index
;
if
(
IntegerArray_binary_search
(
node
->
keys
,
key
,
&
index
))
{
bool
is_found
=
IntegerArray_binary_search
(
root
->
keys
,
key
,
&
index
);
node
->
keys
->
items
[
index
]
=
find_smallest_key
(
node
->
children
->
items
[
index
+
1
]);
if
(
root
->
is_leaf
&&
!
is_found
)
{
return
false
;
}
}
replace_deleted_key_internal
(
parents
,
i
-
1
,
key
);
if
(
root
->
is_leaf
)
{
IntegerArray_delete_at_index
(
root
->
keys
,
index
);
IntegerArray_delete_at_index
(
root
->
data
,
index
);
}
else
if
(
is_found
)
{
root
->
keys
->
items
[
index
]
=
find_smallest_key
(
root
->
children
->
items
[
index
+
1
]);
}
}
void
BPTree_delete
(
BPTreeNode
*
root
,
uint64_t
key
)
{
if
(
parent
==
NULL
&&
root
->
keys
->
size
==
0
)
{
BPTreeNodeArray
*
parents
;
shrink
(
root
);
BPTreeNode
*
leaf
=
find_leaf
(
root
,
key
,
&
parents
);
int
index
;
if
(
!
IntegerArray_binary_search
(
leaf
->
keys
,
key
,
&
index
))
{
BPTreeNodeArray_destroy
(
&
parents
);
return
;
}
}
IntegerArray_delete_at_index
(
leaf
->
keys
,
index
);
if
(
parent
!=
NULL
&&
root
->
keys
->
size
<
root
->
order
)
{
IntegerArray_delete_at_index
(
leaf
->
data
,
index
);
deletion_rebalance
(
root
,
parent
);
}
re
place_deleted_key_internal
(
parents
,
parents
->
size
-
1
,
key
)
;
re
turn
true
;
deletion_rebalance
(
root
,
parents
,
leaf
,
key
);
}
BPTreeNodeArray_destroy
(
&
parents
);
bool
BPTree_delete
(
BPTreeNode
*
root
,
uint64_t
key
)
{
return
_BPTree_delete
(
root
,
key
,
NULL
);
}
}
This diff is collapsed.
Click to expand it.
src/BPTree.h
+
1
−
1
View file @
11a5e65f
...
@@ -27,6 +27,6 @@ void BPTree_insert(BPTreeNode *root, uint64_t key, uint64_t data);
...
@@ -27,6 +27,6 @@ void BPTree_insert(BPTreeNode *root, uint64_t key, uint64_t data);
// Deletion
// Deletion
void
BPTree_delete
(
BPTreeNode
*
root
,
uint64_t
key
);
bool
BPTree_delete
(
BPTreeNode
*
root
,
uint64_t
key
);
#endif
#endif
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