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
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
93a9c086
Commit
93a9c086
authored
2 years ago
by
Florian Burgener
Browse files
Options
Downloads
Patches
Plain Diff
Refactoring + fix bug
parent
6f558433
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
Tampermonkey.js
+47
-0
47 additions, 0 deletions
Tampermonkey.js
src/Array.c
+6
-7
6 additions, 7 deletions
src/Array.c
src/Array.h
+1
-1
1 addition, 1 deletion
src/Array.h
src/BPTree.c
+28
-21
28 additions, 21 deletions
src/BPTree.c
src/main.c
+12
-0
12 additions, 0 deletions
src/main.c
with
94 additions
and
29 deletions
Tampermonkey.js
0 → 100644
+
47
−
0
View file @
93a9c086
window
.
addEventListener
(
'
load
'
,
function
()
{
var
table_AlgorithmSpecificControls
=
document
.
getElementById
(
"
AlgorithmSpecificControls
"
);
var
insert_input
=
table_AlgorithmSpecificControls
.
children
[
0
].
children
[
0
];
var
insert_button
=
table_AlgorithmSpecificControls
.
children
[
1
].
children
[
0
];
var
delete_input
=
table_AlgorithmSpecificControls
.
children
[
2
].
children
[
0
];
var
delete_button
=
table_AlgorithmSpecificControls
.
children
[
3
].
children
[
0
];
var
table_GeneralAnimationControls
=
document
.
getElementById
(
"
GeneralAnimationControls
"
);
var
skip_button
=
table_GeneralAnimationControls
.
children
[
4
].
children
[
0
];
function
timeout
(
ms
)
{
return
new
Promise
(
resolve
=>
setTimeout
(
resolve
,
ms
));
}
async
function
insert_keys
(
keys
)
{
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
insert_input
.
value
=
keys
[
i
];
insert_button
.
click
();
skip_button
.
click
();
await
timeout
(
10
);
}
}
async
function
delete_keys
(
keys
)
{
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
delete_input
.
value
=
keys
[
i
];
delete_button
.
click
();
skip_button
.
click
();
await
timeout
(
10
);
}
}
async
function
do_stuff
()
{
var
inputs_MaxDegree
=
document
.
getElementsByName
(
"
MaxDegree
"
);
var
input_MaxDegree
=
inputs_MaxDegree
[
2
];
input_MaxDegree
.
checked
=
true
;
input_MaxDegree
.
click
();
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
delete_keys
([
65
,
57
,
47
,
28
,
51
]);
await
insert_keys
([
100
]);
await
delete_keys
([
48
,
41
,
60
,
5
,
8
,
21
,
86
,
100
,
88
,
95
,
49
,
56
,
55
]);
}
do_stuff
();
},
false
);
This diff is collapsed.
Click to expand it.
src/Array.c
+
6
−
7
View file @
93a9c086
...
@@ -96,13 +96,6 @@ void IntegerArray_delete_at_index(IntegerArray *array, int index) {
...
@@ -96,13 +96,6 @@ void IntegerArray_delete_at_index(IntegerArray *array, int index) {
array
->
size
--
;
array
->
size
--
;
}
}
int
IntegerArray_delete_sorted
(
IntegerArray
*
array
,
uint64_t
item
)
{
int
index
;
IntegerArray_binary_search
(
array
,
item
,
&
index
);
IntegerArray_delete_at_index
(
array
,
index
);
return
index
;
}
void
IntegerArray_print
(
IntegerArray
*
array
)
{
void
IntegerArray_print
(
IntegerArray
*
array
)
{
printf
(
"["
);
printf
(
"["
);
...
@@ -164,6 +157,12 @@ void BPTreeNodeArray_delete_at_index(BPTreeNodeArray *array, int index) {
...
@@ -164,6 +157,12 @@ void BPTreeNodeArray_delete_at_index(BPTreeNodeArray *array, int index) {
array
->
size
--
;
array
->
size
--
;
}
}
BPTreeNode
*
BPTreeNodeArray_pop
(
BPTreeNodeArray
*
array
)
{
BPTreeNode
*
item
=
array
->
items
[
array
->
size
-
1
];
BPTreeNodeArray_delete_at_index
(
array
,
array
->
size
-
1
);
return
item
;
}
void
BPTreeNodeArray_clear
(
BPTreeNodeArray
*
array
)
{
void
BPTreeNodeArray_clear
(
BPTreeNodeArray
*
array
)
{
array
->
size
=
0
;
array
->
size
=
0
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/Array.h
+
1
−
1
View file @
93a9c086
...
@@ -21,7 +21,6 @@ void IntegerArray_insert_at_index(IntegerArray *array, int index, uint64_t item)
...
@@ -21,7 +21,6 @@ void IntegerArray_insert_at_index(IntegerArray *array, int index, uint64_t item)
void
IntegerArray_append
(
IntegerArray
*
array
,
uint64_t
item
);
void
IntegerArray_append
(
IntegerArray
*
array
,
uint64_t
item
);
bool
IntegerArray_binary_search
(
IntegerArray
*
array
,
uint64_t
item
,
int
*
index
);
bool
IntegerArray_binary_search
(
IntegerArray
*
array
,
uint64_t
item
,
int
*
index
);
void
IntegerArray_delete_at_index
(
IntegerArray
*
array
,
int
index
);
void
IntegerArray_delete_at_index
(
IntegerArray
*
array
,
int
index
);
int
IntegerArray_delete_sorted
(
IntegerArray
*
array
,
uint64_t
item
);
void
IntegerArray_print
(
IntegerArray
*
array
);
void
IntegerArray_print
(
IntegerArray
*
array
);
void
IntegerArray_clear
(
IntegerArray
*
array
);
void
IntegerArray_clear
(
IntegerArray
*
array
);
void
IntegerArray_copy
(
IntegerArray
*
src
,
IntegerArray
*
dest
);
void
IntegerArray_copy
(
IntegerArray
*
src
,
IntegerArray
*
dest
);
...
@@ -41,6 +40,7 @@ void BPTreeNodeArray_destroy(BPTreeNodeArray **array);
...
@@ -41,6 +40,7 @@ void BPTreeNodeArray_destroy(BPTreeNodeArray **array);
void
BPTreeNodeArray_insert_at_index
(
BPTreeNodeArray
*
array
,
int
index
,
BPTreeNode
*
item
);
void
BPTreeNodeArray_insert_at_index
(
BPTreeNodeArray
*
array
,
int
index
,
BPTreeNode
*
item
);
void
BPTreeNodeArray_append
(
BPTreeNodeArray
*
array
,
BPTreeNode
*
item
);
void
BPTreeNodeArray_append
(
BPTreeNodeArray
*
array
,
BPTreeNode
*
item
);
void
BPTreeNodeArray_delete_at_index
(
BPTreeNodeArray
*
array
,
int
index
);
void
BPTreeNodeArray_delete_at_index
(
BPTreeNodeArray
*
array
,
int
index
);
BPTreeNode
*
BPTreeNodeArray_pop
(
BPTreeNodeArray
*
array
);
void
BPTreeNodeArray_clear
(
BPTreeNodeArray
*
array
);
void
BPTreeNodeArray_clear
(
BPTreeNodeArray
*
array
);
void
BPTreeNodeArray_copy
(
BPTreeNodeArray
*
src
,
BPTreeNodeArray
*
dest
);
void
BPTreeNodeArray_copy
(
BPTreeNodeArray
*
src
,
BPTreeNodeArray
*
dest
);
...
...
This diff is collapsed.
Click to expand it.
src/BPTree.c
+
28
−
21
View file @
93a9c086
...
@@ -70,11 +70,11 @@ void BPTree_print(BPTreeNode *root, int depth) {
...
@@ -70,11 +70,11 @@ void BPTree_print(BPTreeNode *root, int depth) {
}
}
IntegerArray_print
(
root
->
keys
);
IntegerArray_print
(
root
->
keys
);
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
++
)
{
BPTree_print
(
root
->
children
->
items
[
i
],
depth
+
1
);
BPTree_print
(
root
->
children
->
items
[
i
],
depth
+
1
);
...
@@ -227,8 +227,7 @@ static void insert_full(BPTreeNode *root, BPTreeNodeArray *parents, BPTreeNode *
...
@@ -227,8 +227,7 @@ static void insert_full(BPTreeNode *root, BPTreeNodeArray *parents, BPTreeNode *
if
(
node
==
root
)
{
if
(
node
==
root
)
{
grow
(
root
,
median_value
,
split_right_node
);
grow
(
root
,
median_value
,
split_right_node
);
}
else
{
}
else
{
BPTreeNode
*
parent
=
parents
->
items
[
parents
->
size
-
1
];
BPTreeNode
*
parent
=
BPTreeNodeArray_pop
(
parents
);
BPTreeNodeArray_delete_at_index
(
parents
,
parents
->
size
-
1
);
if
(
has_maximum_keys
(
parent
))
{
if
(
has_maximum_keys
(
parent
))
{
// 0 is passed instead of data because the recursion is necessarily done on an internal node.
// 0 is passed instead of data because the recursion is necessarily done on an internal node.
...
@@ -281,7 +280,7 @@ static void steal_leaf(BPTreeNode *parent, BPTreeNode *node, int child_index, BP
...
@@ -281,7 +280,7 @@ 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
_BPTree_delet
e
(
BPTreeNode
*
root
,
BPTreeNodeArray
*
parents
,
BPTreeNode
*
node
,
uint64_t
key
);
static
void
deletion_rebalanc
e
(
BPTreeNode
*
root
,
BPTreeNodeArray
*
parents
,
BPTreeNode
*
node
,
uint64_t
key
);
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,17 +413,11 @@ static BPTreeNode *find_sibling(BPTreeNode *parent, BPTreeNode *node) {
...
@@ -414,17 +413,11 @@ static BPTreeNode *find_sibling(BPTreeNode *parent, BPTreeNode *node) {
return
parent
->
children
->
items
[
child_index
-
1
];
return
parent
->
children
->
items
[
child_index
-
1
];
}
}
static
void
_BPTree_delet
e
(
BPTreeNode
*
root
,
BPTreeNodeArray
*
parents
,
BPTreeNode
*
node
,
uint64_t
key
)
{
static
void
deletion_rebalanc
e
(
BPTreeNode
*
root
,
BPTreeNodeArray
*
parents
,
BPTreeNode
*
node
,
uint64_t
key
)
{
BPTreeNode
*
parent
=
NULL
;
BPTreeNode
*
parent
=
NULL
;
if
(
parents
->
size
>
0
)
{
if
(
parents
->
size
>
0
)
{
parent
=
parents
->
items
[
parents
->
size
-
1
];
parent
=
BPTreeNodeArray_pop
(
parents
);
BPTreeNodeArray_delete_at_index
(
parents
,
parents
->
size
-
1
);
}
if
(
node
->
is_leaf
)
{
int
index
=
IntegerArray_delete_sorted
(
node
->
keys
,
key
);
IntegerArray_delete_at_index
(
node
->
data
,
index
);
}
}
if
(
node
!=
root
&&
node
->
keys
->
size
<
node
->
order
)
{
if
(
node
!=
root
&&
node
->
keys
->
size
<
node
->
order
)
{
...
@@ -447,14 +440,23 @@ static void _BPTree_delete(BPTreeNode *root, BPTreeNodeArray *parents, BPTreeNod
...
@@ -447,14 +440,23 @@ static void _BPTree_delete(BPTreeNode *root, BPTreeNodeArray *parents, BPTreeNod
}
}
}
}
if
(
parent
!=
NULL
)
{
deletion_rebalance
(
root
,
parents
,
parent
,
key
);
}
}
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
(
!
node
->
is_leaf
&&
node
->
children
->
size
>
0
&&
IntegerArray_binary_search
(
node
->
keys
,
key
,
&
index
))
{
if
(
IntegerArray_binary_search
(
node
->
keys
,
key
,
&
index
))
{
node
->
keys
->
items
[
index
]
=
find_smallest_key
(
node
->
children
->
items
[
index
+
1
]);
node
->
keys
->
items
[
index
]
=
find_smallest_key
(
node
->
children
->
items
[
index
+
1
]);
}
}
if
(
parent
!=
NULL
)
{
replace_deleted_key_internal
(
parents
,
i
-
1
,
key
);
_BPTree_delete
(
root
,
parents
,
parent
,
key
);
}
}
}
void
BPTree_delete
(
BPTreeNode
*
root
,
uint64_t
key
)
{
void
BPTree_delete
(
BPTreeNode
*
root
,
uint64_t
key
)
{
...
@@ -467,6 +469,11 @@ void BPTree_delete(BPTreeNode *root, uint64_t key) {
...
@@ -467,6 +469,11 @@ void BPTree_delete(BPTreeNode *root, uint64_t key) {
return
;
return
;
}
}
_BPTree_delete
(
root
,
parents
,
leaf
,
key
);
IntegerArray_delete_at_index
(
leaf
->
keys
,
index
);
IntegerArray_delete_at_index
(
leaf
->
data
,
index
);
replace_deleted_key_internal
(
parents
,
parents
->
size
-
1
,
key
);
deletion_rebalance
(
root
,
parents
,
leaf
,
key
);
BPTreeNodeArray_destroy
(
&
parents
);
BPTreeNodeArray_destroy
(
&
parents
);
}
}
This diff is collapsed.
Click to expand it.
src/main.c
+
12
−
0
View file @
93a9c086
...
@@ -38,6 +38,18 @@ int main() {
...
@@ -38,6 +38,18 @@ int main() {
BPTree_delete
(
root
,
48
);
BPTree_delete
(
root
,
48
);
BPTree_delete
(
root
,
41
);
BPTree_delete
(
root
,
41
);
BPTree_delete
(
root
,
60
);
BPTree_delete
(
root
,
60
);
BPTree_delete
(
root
,
5
);
BPTree_delete
(
root
,
8
);
BPTree_delete
(
root
,
21
);
BPTree_delete
(
root
,
86
);
BPTree_delete
(
root
,
100
);
BPTree_delete
(
root
,
88
);
BPTree_delete
(
root
,
95
);
BPTree_delete
(
root
,
49
);
BPTree_delete
(
root
,
56
);
BPTree_delete
(
root
,
55
);
BPTree_print
(
root
,
0
);
BPTree_print
(
root
,
0
);
IntegerArray_destroy
(
&
keys
);
IntegerArray_destroy
(
&
keys
);
...
...
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