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
32ea3562
Commit
32ea3562
authored
1 year ago
by
Mamadu-lamarana Bah
Browse files
Options
Downloads
Patches
Plain Diff
search et insert
parent
072d024b
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
+26
-5
26 additions, 5 deletions
src/BTree.py
src/node.py
+8
-30
8 additions, 30 deletions
src/node.py
src/util.py
+33
-13
33 additions, 13 deletions
src/util.py
with
67 additions
and
48 deletions
src/BTree.py
+
26
−
5
View file @
32ea3562
import
Node
as
Bnode
class
Btree
()
:
def
__init__
(
self
,
root
)
:
def
__init__
(
self
,
k
,
root
=
None
)
:
self
.
root
=
root
self
.
k
=
k
def
recherche
(
self
,
valeur
):
if
(
self
.
root
!=
None
)
:
index
=
0
while
index
def
search
(
self
,
value
,
node
=
self
.
root
):
(
found
,
index
)
=
node
.
search
(
value
)
if
(
found
):
return
(
node
,
index
)
elif
(
node
.
isLeaf
()
):
return
None
else
:
self
.
search
(
value
,
node
.
childs
[
index
])
def
insertion
(
self
,
value
):
if
(
self
.
root
==
None
):
self
.
root
=
Bnode
.
Node
(
self
.
k
)
self
.
root
.
keys
[
0
]
=
value
else
:
if
(
len
(
self
.
root
)
==
self
.
k
):
new_root
=
Bnode
.
Node
(
self
.
k
)
new_root
.
childs
[
0
]
=
self
.
root
#def search() :
...
...
This diff is collapsed.
Click to expand it.
src/node.py
+
8
−
30
View file @
32ea3562
import
util
from
util
import
recherche_dichotomique
class
n
ode
()
:
class
N
ode
()
:
def
__init__
(
self
,
k
,
kmin
,
kmax
)
:
def
__init__
(
self
,
nbKey
)
:
self
.
keys
=
[]
self
.
childs
=
[]
self
.
kmin
=
kmin
self
.
kmax
=
kmax
def
search
(
self
,
Key
):
return
util
.
recherche_dichotomique
(
key
,
self
.
childs
)
def
isLeaf
(
):
return
(
len
(
self
.
childs
)
==
0
)
def
getSize
(
self
)
:
return
len
(
Keys
)
def
addKey
(
self
)
:
def
dicho
(
self
,
listKeys
,
key
)
:
t
=
len
(
listKeys
)
-
1
d
,
f
=
0
,
t
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
def
serach
(
self
,
k
):
return
recherche_dichotomique
(
k
,
self
.
keys
)
#def getSizeNode() :
#def getPos() :
...
...
This diff is collapsed.
Click to expand it.
src/util.py
+
33
−
13
View file @
32ea3562
...
...
@@ -35,26 +35,46 @@ def recherche_dichotomique(x, l, cmp = compare):
:Exemples:
>>>
recherche_dichotomique
(
1
,
[])
(
False
,
-
1
)
(
False
,
0
)
>>>
l
=
list
(
range
(
10
))
>>>
recherche_dichotomique
(
5
,
l
)
(
True
,
5
)
>>>
recherche_dichotomique
(
5.5
,
l
)
(
False
,
-
1
)
(
False
,
6
)
"""
n
=
len
(
l
)
debut
,
fin
=
0
,
n
taille
=
len
(
l
)
debut
,
fin
=
0
,
taille
index
=
0
while
debut
<
fin
:
m
=
(
debut
+
fin
)
//
2
if
cmp
(
x
,
l
[
m
])
==
0
:
return
(
True
,
m
)
elif
cmp
(
x
,
l
[
m
])
>
0
:
index
+
=
m
debut
=
m
+
1
m
ilieu
=
(
debut
+
fin
)
//
2
if
cmp
(
x
,
l
[
m
ilieu
])
==
0
:
return
(
True
,
m
ilieu
)
elif
cmp
(
x
,
l
[
m
ilieu
])
>
0
:
index
=
m
ilieu
+
1
debut
=
m
ilieu
+
1
else
:
fin
=
m
index
=
0
return
(
False
,
-
1
)
fin
=
milieu
index
=
milieu
return
(
False
,
index
)
## LOIC
def
dicho
(
self
,
listKeys
,
key
)
:
t
=
len
(
listKeys
)
-
1
d
,
f
=
0
,
t
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