Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
projet_s6_loic.scoth.etu_mamadulamarana.bah.etu
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
Loic Scoth
projet_s6_loic.scoth.etu_mamadulamarana.bah.etu
Commits
b7801ac8
Commit
b7801ac8
authored
1 year ago
by
Mamadu-lamarana Bah
Browse files
Options
Downloads
Patches
Plain Diff
test de searcch et debut de insertion
parent
0f4a4574
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/BTree.py
+16
-9
16 additions, 9 deletions
src/BTree.py
src/node.py
+47
-21
47 additions, 21 deletions
src/node.py
with
63 additions
and
30 deletions
src/BTree.py
+
16
−
9
View file @
b7801ac8
...
...
@@ -9,6 +9,15 @@ class Btree() :
self
.
k
=
k
def
search
(
self
,
value
):
"""
Exemple(s):
>>>
Btree
(
2
,
Node
([
5
,
25
])).
search
(
25
)
(
Node
([
5
,
25
]),
1
)
>>>
Btree
(
2
,
Node
([
12
,
42
],
[
Node
([
1
]),
Node
([
25
]),
Node
([
50
])])).
search
(
1
)
(
Node
([
1
]),
0
)
True
>>>
Btree
(
2
,
Node
([
12
,
42
],
[
Node
([
1
]),
Node
([
25
]),
Node
([
50
])])).
search
(
2
)
"""
return
self
.
root
.
search
(
value
)
# incomplet
...
...
@@ -29,15 +38,13 @@ class Btree() :
# self.root.insert_not_full(value)
#
def
insertion
(
self
,
value
):
"""
>>>
Node
([
5
,
25
]).
insertion
(
10
)
Node
([
5
,
10
,
25
])
>>>
Node
([]).
insertion
(
1
)
Node
([
1
])
>>>
Node
([
5
,
25
]).
insertion
(
50
)
Node
([
5
,
25
,
50
])
"""
#def insertion(self,value):
# >>> Node([5,25]).insertion(10)
# Node([5,10,25])
# >>> Node([]).insertion(1)
# Node([1])
# >>> Node([5,25]).insertion(50)
# Node([5,25,50])
...
...
This diff is collapsed.
Click to expand it.
src/node.py
+
47
−
21
View file @
b7801ac8
...
...
@@ -21,10 +21,15 @@ class Node() :
def
search
(
self
,
value
):
"""
>>>
Node
([
5
,
25
]).
search
(
5
)
(
Node
([
5
,
25
]),
0
)
>>>
Node
([
5
,
25
],[
Node
[
1
],
Node
[
18
],
Node
[
100
]]).
search
(
18
)
(
Node
[
18
],
0
)
Exemple(s):
>>>
Node
([
5
,
25
]).
search
(
5
)
(
Node
([
5
,
25
]),
0
)
>>>
Node
([
12
,
42
]).
search
(
12
)
(
Node
([
12
,
42
]),
0
)
>>>
Node
([
12
,
42
]).
search
(
1
)
>>>
Node
([
12
,
42
],
[
Node
([
1
]),
Node
([
25
]),
Node
([
50
])]).
search
(
1
)
(
Node
([
1
]),
0
)
>>>
Node
([
12
,
42
],
[
Node
([
1
]),
Node
([
25
]),
Node
([
50
])]).
search
(
2
)
"""
(
found
,
index
)
=
recherche_dichotomique
(
value
,
self
.
keys
)
if
(
found
):
...
...
@@ -32,7 +37,7 @@ class Node() :
elif
(
self
.
isLeaf
()
):
return
None
else
:
self
.
childs
[
index
].
search
(
value
)
return
self
.
childs
[
index
].
search
(
value
)
def
insert
(
self
,
value
,
k
):
"""
...
...
@@ -41,20 +46,32 @@ class Node() :
>>>
Node
([
5
,
15
]).
insert
(
20
,
4
)
Node
([
5
,
15
,
20
])
"""
(
found
,
index
)
=
self
.
search
(
value
)
if
(
self
.
isLeaf
()
)
:
if
(
not
found
):
(
node
,
index
)
=
self
.
search
(
value
)
if
(
node
==
None
)
:
if
(
self
.
isLeaf
()
):
self
.
keys
.
insert
(
index
,
value
)
else
:
(
fini
,
milieu
,
g
,
d
)
=
self
.
childs
[
index
].
insert
(
value
,
k
)
if
not
fini
:
return
None
#TODO
if
(
len
(
self
.
keys
)
>
k
)
:
(
m
,
g
,
d
)
=
self
.
splitNode
()
f
=
False
else
:
return
None
else
:
(
fini
,
milieu
,
g
,
d
)
=
self
.
childs
[
index
].
insert
(
value
,
k
)
if
(
not
fini
)
:
self
.
keys
.
insert
(
index
,
milieu
)
self
.
childs
[
index
]
=
g
self
.
childs
.
insert
(
index
+
1
,
d
)
# else :
# (fini, milieu, g, d) = self.childs[index].insert(value, k)
# if not fini:
# return None
# #TODO
# if (len(self.keys) > k) :
# (m, g, d) = self.splitNode()
# f = False
# else:
# return None
#TODO
...
...
@@ -66,14 +83,23 @@ class Node() :
def
splitNode
(
self
)
:
"""
>>>
Node
([
10
,
20
,
25
]).
splitNode
()
(
20
,
Node
([
10
]),
Node
([
25
])
(
20
,
Node
([
10
]),
Node
([
25
]))
>>>
Node
([
12
,
20
,
22
,
40
]).
splitNode
()
(
22
,
Node
([
12
,
20
]),
Node
([
40
]))
>>>
Node
([
3
,
5
]).
splitNode
()
(
5
,
Node
([
3
]),
Node
([]))
"""
milieu
=
len
(
self
.
keys
)
//
2
parent
=
self
.
keys
[
milieu
]
g
=
Node
(
self
.
keys
[:
milieu
],
self
.
childs
[:
milieu
+
1
])
d
=
Node
(
self
.
keys
[
milieu
+
1
:],
self
.
childs
[
milieu
+
1
:])
return
(
milieu
,
g
,
d
)
return
(
parent
,
g
,
d
)
def
__repr__
(
self
)
:
return
f
"
Node(
{
self
.
keys
}
)
"
...
...
@@ -102,4 +128,4 @@ class Node() :
if
__name__
==
'
__main__
'
:
import
doctest
doctest
.
testmod
(
verbose
=
True
)
\ No newline at end of file
doctest
.
testmod
(
verbose
=
False
)
\ No newline at end of file
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