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
0f4a4574
Commit
0f4a4574
authored
1 year ago
by
Loic Scoth
Browse files
Options
Downloads
Patches
Plain Diff
ajout des test, a modifier + avancé sur split et insertion
parent
eb302b8e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/BTree.py
+37
-14
37 additions, 14 deletions
src/BTree.py
src/node.py
+72
-19
72 additions, 19 deletions
src/node.py
src/util.py
+3
-21
3 additions, 21 deletions
src/util.py
with
112 additions
and
54 deletions
src/BTree.py
+
37
−
14
View file @
0f4a4574
import
Node
as
Bnode
#import Node as Bnode
from
node
import
*
class
Btree
()
:
class
Btree
()
:
...
@@ -11,18 +12,35 @@ class Btree() :
...
@@ -11,18 +12,35 @@ class Btree() :
return
self
.
root
.
search
(
value
)
return
self
.
root
.
search
(
value
)
# incomplet
# incomplet
def
insertion
(
self
,
value
):
# def insertion(self, value):
if
(
self
.
root
==
None
):
#
self
.
root
=
Bnode
.
Node
(
self
.
k
)
# if (self.root == None):
self
.
root
.
keys
[
0
]
=
value
# self.root = Bnode.Node(self.k)
else
:
# self.root.keys[0] = value
if
(
len
(
self
.
root
)
==
self
.
k
):
# else :
new_root
=
Bnode
.
Node
(
self
.
k
)
# if ( len(self.root) == self.k):
new_root
.
childs
[
0
]
=
self
.
root
# new_root = Bnode.Node(self.k)
# new_root.childs[0] = self.root
if
(
self
)
#
else
:
# if (self) :
self
.
root
.
insert_not_full
(
value
)
# ##TODO
# return None
# else:
# 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
])
"""
...
@@ -40,4 +58,9 @@ class Btree() :
...
@@ -40,4 +58,9 @@ class Btree() :
#def getNbKeys () :
#def getNbKeys () :
#def getSize () :
#def getSize () :
#def changeRoot() :
#def changeRoot() :
#def isEqual() :
#def isEqual() :
\ No newline at end of file
if
__name__
==
'
__main__
'
:
import
doctest
doctest
.
testmod
(
verbose
=
True
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/node.py
+
72
−
19
View file @
0f4a4574
...
@@ -2,44 +2,93 @@ from util import recherche_dichotomique
...
@@ -2,44 +2,93 @@ from util import recherche_dichotomique
class
Node
()
:
class
Node
()
:
def
__init__
(
self
,
k
)
:
def
__init__
(
self
,
keys
,
childs
=
[],
k
=
2
)
:
self
.
parent
=
self
.
keys
=
keys
self
.
keys
=
[]
self
.
childs
=
childs
self
.
childs
=
[]
self
.
k
=
k
self
.
k
=
k
def
isLeaf
():
def
isLeaf
(
self
):
"""
>>>
Node
([
12
,
42
]).
isLeaf
()
True
>>>
Node
([
12
,
42
],
[
Node
([
1
]),
Node
([
25
]),
Node
([
50
])]).
isLeaf
()
False
"""
return
(
len
(
self
.
childs
)
==
0
)
return
(
len
(
self
.
childs
)
==
0
)
def
getSize
(
self
)
:
def
getSize
(
self
)
:
return
len
(
Keys
)
return
len
(
Keys
)
def
serach
(
self
,
value
):
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
)
"""
(
found
,
index
)
=
recherche_dichotomique
(
value
,
self
.
keys
)
(
found
,
index
)
=
recherche_dichotomique
(
value
,
self
.
keys
)
if
(
found
):
if
(
found
):
return
(
node
,
index
)
return
(
self
,
index
)
elif
(
node
.
isLeaf
()
):
elif
(
self
.
isLeaf
()
):
return
None
return
None
else
:
else
:
self
.
childs
[
index
].
search
(
value
)
self
.
childs
[
index
].
search
(
value
)
def
insert_not_full
(
self
,
value
):
def
insert
(
self
,
value
,
k
):
"""
>>>
Node
([
5
,
15
]).
insert
(
12
,
3
)
Node
([
5
,
12
,
15
])
>>>
Node
([
5
,
15
]).
insert
(
20
,
4
)
Node
([
5
,
15
,
20
])
"""
(
found
,
index
)
=
self
.
search
(
value
)
(
found
,
index
)
=
self
.
search
(
value
)
if
(
self
.
isLeaf
())
:
if
(
self
.
isLeaf
())
:
if
(
not
found
):
if
(
not
found
):
self
.
keys
.
insert
(
)
=
value
self
.
keys
.
insert
(
index
,
value
)
else
:
else
:
if
(
len
(
self
.
childs
[
index
])
==
self
.
k
)
:
(
fini
,
milieu
,
g
,
d
)
=
self
.
childs
[
index
].
insert
(
value
,
k
)
self
.
childs
[
index
].
splitNode
(
index
)
if
not
fini
:
if
(
value
>
self
.
keys
[
index
])
:
return
None
index
+=
1
#TODO
self
.
childs
[
index
].
insert_not_full
(
value
)
if
(
len
(
self
.
keys
)
>
k
)
:
(
m
,
g
,
d
)
=
self
.
splitNode
()
f
=
False
else
:
return
None
#TODO
# def splitNode(self) :
# parent = Node(self.k)
# m = self.keys[(len(self.node.keys))//2]
# j'ai pas encore bien compris comment m'y prendre
def
splitNode
(
self
)
:
def
splitNode
(
self
)
:
parent
=
Node
(
self
.
k
)
"""
m
=
self
.
keys
[(
len
(
self
.
node
.
keys
))
//
2
]
>>>
Node
([
10
,
20
,
25
]).
splitNode
()
(
20
,
Node
([
10
]),
Node
([
25
])
"""
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
)
...
@@ -49,4 +98,8 @@ class Node() :
...
@@ -49,4 +98,8 @@ class Node() :
#def setNewChild() :
#def setNewChild() :
#def removeChild() :
#def removeChild() :
#def isLeaf() :
#def isLeaf() :
\ No newline at end of file
if
__name__
==
'
__main__
'
:
import
doctest
doctest
.
testmod
(
verbose
=
True
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/util.py
+
3
−
21
View file @
0f4a4574
...
@@ -70,24 +70,6 @@ def recherche_dichotomique(x, l, cmp = compare):
...
@@ -70,24 +70,6 @@ def recherche_dichotomique(x, l, cmp = compare):
for
j
in
range
(
len
(
l
)))
for
j
in
range
(
len
(
l
)))
return
(
False
,
index
)
return
(
False
,
index
)
## LOIC
if
__name__
==
'
__main__
'
:
def
dicho
(
self
,
listKeys
,
key
)
:
import
doctest
t
=
len
(
listKeys
)
-
1
doctest
.
testmod
(
verbose
=
True
)
d
,
f
=
0
,
t
\ No newline at end of file
while
(
f
>=
d
)
:
m
=
(
d
+
f
)
//
2
if
(
listKeys
[
m
]
==
key
)
:
return
m
if
(
listKeys
[
m
]
>
key
):
f
=
m
-
1
#if ( f< t and listKeys[f] == key) :
# return True,f
else
:
d
=
m
+
1
#if (d < t and listKeys[d] == key) :
# return True, d
return
-
1
doctest
.
testmod
()
\ 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