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
b4f49d51
Commit
b4f49d51
authored
3 years ago
by
Florian Burgener
Browse files
Options
Downloads
Patches
Plain Diff
Duplicates should no work
parent
b4337e59
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
__main__.py
+22
-15
22 additions, 15 deletions
__main__.py
with
22 additions
and
15 deletions
__main__.py
+
22
−
15
View file @
b4f49d51
...
...
@@ -39,12 +39,14 @@ def array_insert_sorted(array, value):
def
insert
(
root
,
key
):
leaf_node
=
root
parents
=
[]
while
not
leaf_node
.
is_leaf
:
parents
.
append
(
leaf_node
)
index
=
array_binary_search
(
leaf_node
.
keys
,
key
)
leaf_node
=
leaf_node
.
children
[
index
]
if
node_is_full
(
leaf_node
):
insert_full
(
root
,
leaf_node
,
key
,
None
)
insert_full
(
root
,
parents
,
leaf_node
,
key
,
None
)
else
:
insert_non_full
(
leaf_node
,
key
,
None
)
...
...
@@ -56,7 +58,7 @@ def insert_non_full(node, key, right_child_node):
node
.
children
.
insert
(
inserted_at_index
+
1
,
right_child_node
)
def
insert_full
(
root
,
node
,
key
,
right_child_node
):
def
insert_full
(
root
,
parents
,
node
,
key
,
right_child_node
):
if
node
.
is_leaf
:
abc
,
split_right
=
split_leaf
(
node
,
key
)
else
:
...
...
@@ -65,10 +67,10 @@ def insert_full(root, node, key, right_child_node):
if
node
==
root
:
increase_height
(
root
,
abc
,
split_right
)
else
:
parent
=
find_
parent
(
root
,
node
)
parent
=
parent
s
.
pop
(
)
if
node_is_full
(
parent
):
insert_full
(
root
,
parent
,
abc
,
split_right
)
insert_full
(
root
,
parents
,
parent
,
abc
,
split_right
)
else
:
insert_non_full
(
parent
,
abc
,
split_right
)
...
...
@@ -110,7 +112,6 @@ def split_internal(node, key, right_child_node):
split_right
.
children
=
node
.
children
[
split_index
+
1
:]
node
.
children
=
node
.
children
[:
split_index
+
1
]
split_right
.
children
.
insert
(
0
,
right_child_node
)
pass
return
abc
,
split_right
...
...
@@ -127,6 +128,10 @@ def split_leaf(node, key):
else
:
abc
=
key
if
key
==
node
.
keys
[
len
(
node
.
keys
)
//
2
]:
# I don't like it but without it the duplicates can't work.
split_index
=
len
(
node
.
keys
)
//
2
split_right
=
Node
(
node
.
order
)
split_right
.
is_leaf
=
node
.
is_leaf
split_right
.
keys
=
node
.
keys
[
split_index
:]
...
...
@@ -136,6 +141,7 @@ def split_leaf(node, key):
array_insert_sorted
(
node
.
keys
,
key
)
else
:
array_insert_sorted
(
split_right
.
keys
,
key
)
return
abc
,
split_right
...
...
@@ -149,15 +155,6 @@ def increase_height(root, key, right_child_node):
root
.
children
=
[
left_child_node
,
right_child_node
]
def
find_parent
(
root
,
node
):
while
not
root
.
is_leaf
:
for
child
in
root
.
children
:
if
node
==
child
:
return
root
root
=
root
.
children
[
array_binary_search
(
root
.
keys
,
node
.
keys
[
0
])]
return
None
def
tree_print
(
root
,
depth
=
0
):
if
len
(
root
.
keys
)
==
0
:
return
...
...
@@ -171,10 +168,20 @@ def tree_print(root, depth=0):
def
main
():
order
=
2
root
=
Node
(
order
)
keys
=
[
10
,
20
,
50
,
70
,
1
,
11
,
40
,
30
,
90
,
60
,
110
,
80
,
15
,
54
,
42
,
41
,
12
,
14
,
16
,
19
,
20
,
120
,
130
,
140
,
150
,
160
,
161
]
# keys = [10, 20, 50, 70, 1, 11, 40, 30, 90, 60, 110, 80, 15, 54, 42, 41, 12, 14, 16, 19, 20, 17, 18]
keys
=
[
10
,
20
,
50
,
70
,
1
,
11
,
40
,
30
,
90
,
60
,
110
]
for
key
in
keys
:
insert
(
root
,
key
)
insert
(
root
,
80
)
# insert(root, 42)
# insert(root, 42)
# insert(root, 42)
insert
(
root
,
20
)
insert
(
root
,
20
)
insert
(
root
,
20
)
# insert(root, 20)
tree_print
(
root
)
...
...
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