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
58f32dd7
Commit
58f32dd7
authored
1 year ago
by
Mamadu-lamarana Bah
Browse files
Options
Downloads
Patches
Plain Diff
is_ArbreB a été fait, debut suppression
parent
095fd5ca
Branches
Branches containing commit
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
+11
-4
11 additions, 4 deletions
src/BTree.py
src/Node.py
+67
-40
67 additions, 40 deletions
src/Node.py
with
78 additions
and
44 deletions
src/BTree.py
+
11
−
4
View file @
58f32dd7
...
@@ -32,12 +32,12 @@ class Btree() :
...
@@ -32,12 +32,12 @@ class Btree() :
>>>
b
.
insertion
(
10
)
>>>
b
.
insertion
(
10
)
True
True
>>>
b
.
search
(
10
)
>>>
b
.
search
(
10
)
(
Node
([
10
,
1
2
]),
0
)
(
Node
([
1
,
10
,
1
1
]),
1
)
>>>
Btree
(
2
,
Node
([
4
,
10
],
[
Node
([
1
,
3
]),
Node
([
25
]),
Node
([
50
])])).
insertion
(
4
)
>>>
Btree
(
2
,
Node
([
4
,
10
],
[
Node
([
1
,
3
]),
Node
([
25
]),
Node
([
50
])])).
insertion
(
4
)
True
True
"""
"""
fini
,
milieu
,
g
,
d
=
self
.
root
.
insert
(
value
)
fini
,
milieu
,
g
,
d
=
self
.
root
.
insert
(
value
,
self
.
k
)
if
(
not
fini
):
if
(
not
fini
):
new_root
=
Node
([
milieu
],
[
g
,
d
])
new_root
=
Node
([
milieu
],
[
g
,
d
])
self
.
root
=
new_root
self
.
root
=
new_root
...
@@ -53,8 +53,15 @@ class Btree() :
...
@@ -53,8 +53,15 @@ class Btree() :
"""
"""
return
self
.
root
.
linearisation
()
return
self
.
root
.
linearisation
()
def
isBalance
():
def
isBalance
(
self
):
(
truc
,
_
,
_
,
_
)
=
self
.
root
.
is_ArbreB
(
True
)
"""
Exemple(s) :
>>>
b
=
Btree
(
3
,
Node
([
12
,
25
,
50
],
[
Node
([
1
,
11
]),
Node
([
20
]),
Node
([
30
]),
Node
([
100
])]))
>>>
b
.
isBalance
()
True
"""
(
ok
,
_
,
_
,
_
)
=
self
.
root
.
is_ArbreB
(
self
.
k
,
True
)
return
ok
def
__repr__
(
self
)
:
def
__repr__
(
self
)
:
return
f
"
Btree(
{
self
.
root
}
)
"
return
f
"
Btree(
{
self
.
root
}
)
"
...
...
This diff is collapsed.
Click to expand it.
src/Node.py
+
67
−
40
View file @
58f32dd7
from
util
import
recherche_dichotomique
from
util
import
recherche_dichotomique
from
Visualization
import
*
class
Node
()
:
class
Node
()
:
def
__init__
(
self
,
keys
,
childs
=
[]
,
k
=
2
)
:
def
__init__
(
self
,
keys
,
childs
=
[])
:
self
.
keys
=
keys
self
.
keys
=
keys
self
.
childs
=
childs
self
.
childs
=
childs
self
.
k
=
k
def
isLeaf
(
self
):
def
isLeaf
(
self
):
"""
"""
...
@@ -40,59 +40,69 @@ class Node() :
...
@@ -40,59 +40,69 @@ class Node() :
return
self
.
childs
[
index
].
search
(
value
)
return
self
.
childs
[
index
].
search
(
value
)
def
is_ArbreB
(
self
,
is_root
=
False
):
def
is_ArbreB
(
self
,
k
,
is_root
=
False
):
ok
=
(
is_root
or
(
self
.
k
//
2
)
<=
len
(
self
.
keys
))
and
len
(
self
.
keys
)
<=
self
.
k
"""
Exemple(s) :
>>>
Node
([
5
]).
is_ArbreB
(
2
)
(
True
,
0
,
5
,
5
)
>>>
Node
([
5
,
25
]).
is_ArbreB
(
2
)
(
True
,
0
,
5
,
25
)
>>>
node
=
Node
([
12
,
42
],
[
Node
([
2
,
4
],
[
Node
([
0
,
1
]),
Node
([
3
]),
Node
([
7
,
8
])]),
Node
([
25
]),
Node
([
50
])])
>>>
node
.
is_ArbreB
(
2
)
(
False
,
2
,
0
,
50
)
>>>
Node
([
5
,
25
,
3
]).
is_ArbreB
(
2
)
(
False
,
0
,
5
,
3
)
>>>
Node
([
5
,
25
],
[
Node
([
0
,
1
,
2
]),
Node
([
3
,
2
,
5
])]).
is_ArbreB
(
2
)
(
False
,
1
,
0
,
5
)
>>>
Node
([
5
],
[
Node
([
0
]),
Node
([
7
],
[
Node
([
6
]),
Node
([
8
])])]).
is_ArbreB
(
2
)
(
False
,
2
,
0
,
8
)
"""
ok
=
(
is_root
or
(
k
//
2
)
<=
len
(
self
.
keys
))
and
len
(
self
.
keys
)
<=
k
ok
=
ok
and
all
(
self
.
keys
[
i
]
<
self
.
keys
[
i
+
1
]
for
i
in
range
(
len
(
self
.
keys
)
-
1
))
ok
=
ok
and
all
(
self
.
keys
[
i
]
<
self
.
keys
[
i
+
1
]
for
i
in
range
(
len
(
self
.
keys
)
-
1
))
if
(
self
.
isLeaf
()):
if
(
self
.
isLeaf
()):
height
=
0
height
=
0
mini
,
maxi
=
self
.
keys
[
0
],
self
.
keys
[
-
1
]
mini
,
maxi
=
self
.
keys
[
0
],
self
.
keys
[
-
1
]
else
:
else
:
results
=
[
child
.
is_ArbreB
(
False
)
for
child
in
self
.
childs
]
results
=
[
child
.
is_ArbreB
(
k
,
False
)
for
child
in
self
.
childs
]
mins
=
[
mini
for
(
_
,
_
,
mini
,
_
)
in
results
]
mins
=
[
mini
for
(
_
,
_
,
mini
,
_
)
in
results
]
mqxs
=
[
mqxi
for
(
_
,
_
,
_
,
mqxi
)
in
results
]
maxs
=
[
maxi
for
(
_
,
_
,
_
,
maxi
)
in
results
]
ok
=
ok
and
all
(
cle
[
i
]
>
maxs
[
i
]
and
cel
[
i
]
<
mins
[
i
+
1
]
for
i
in
range
(
len
(
cles
)
-
1
))
ok
=
ok
and
all
(
self
.
keys
[
i
]
>
maxs
[
i
]
and
self
.
keys
[
i
]
<
mins
[
i
+
1
]
for
i
in
range
(
len
(
self
.
keys
)
-
1
))
print
(
results
)
heights
=
[
h
for
(
_
,
h
,
_
,
_
)
in
results
]
for
r
in
range
(
0
,
len
(
results
)
-
1
):
ok
=
ok
and
all
(
heights
[
i
]
==
heights
[
i
+
1
]
for
i
in
range
(
len
(
heights
)
-
1
))
(
ok
,
h
,
mini
,
maxi
)
=
results
[
i
]
height
=
1
+
max
(
heights
)
if
(
ok
==
False
):
mini
=
min
(
mins
)
return
False
maxi
=
max
(
maxs
)
(
ok_tmp
,
h_tmp
,
maxi_tmp
,
mini_tmp
)
=
results
[
i
+
1
]
if
(
h
!=
h_tmp
):
return
False
if
(
m
return
(
ok
,
height
,
mini
,
maxi
)
return
(
ok
,
height
,
mini
,
maxi
)
def
insert
(
self
,
value
):
def
insert
(
self
,
value
,
k
):
"""
"""
Exemple(s):
Exemple(s):
>>>
node
=
Node
([
5
])
>>>
node
=
Node
([
5
])
>>>
node
.
insert
(
20
)
>>>
node
.
insert
(
20
,
2
)
(
True
,
None
,
None
,
None
)
(
True
,
None
,
None
,
None
)
>>>
node
.
search
(
20
)
>>>
node
.
search
(
20
)
(
Node
([
5
,
20
]),
1
)
(
Node
([
5
,
20
]),
1
)
>>>
Node
([
5
,
15
]).
insert
(
12
)
>>>
Node
([
5
,
15
]).
insert
(
12
,
2
)
(
False
,
12
,
Node
([
5
]),
Node
([
15
]))
(
False
,
12
,
Node
([
5
]),
Node
([
15
]))
>>>
node
.
search
(
12
)
>>>
node
.
search
(
12
)
>>>
node
=
Node
([
12
,
42
],
[
Node
([
3
]),
Node
([
25
]),
Node
([
50
])])
>>>
node
=
Node
([
12
,
42
],
[
Node
([
3
]),
Node
([
25
]),
Node
([
50
])])
>>>
node
.
insert
(
52
)
>>>
node
.
insert
(
52
,
2
)
(
True
,
None
,
None
,
None
)
(
True
,
None
,
None
,
None
)
>>>
node
.
search
(
52
)
>>>
node
.
search
(
52
)
(
Node
([
50
,
52
]),
1
)
(
Node
([
50
,
52
]),
1
)
>>>
node
=
Node
([
12
,
42
],
[
Node
([
2
,
3
]),
Node
([
25
]),
Node
([
50
])])
>>>
node
=
Node
([
12
,
42
],
[
Node
([
2
,
3
]),
Node
([
25
]),
Node
([
50
])])
>>>
node
.
insert
(
1
)
>>>
node
.
insert
(
1
,
2
)
(
False
,
12
,
Node
([
2
]),
Node
([
42
]))
(
False
,
12
,
Node
([
2
]),
Node
([
42
]))
>>>
node
.
search
(
1
)
>>>
node
.
search
(
1
)
(
Node
([
1
]),
0
)
(
Node
([
1
]),
0
)
>>>
node
=
Node
([
12
,
42
],
[
Node
([
2
,
4
],
[
Node
([
0
,
1
]),
Node
([
3
]),
Node
([
7
,
8
])]),
Node
([
25
]),
Node
([
50
])])
>>>
node
=
Node
([
12
,
42
],
[
Node
([
2
,
4
],
[
Node
([
0
,
1
]),
Node
([
3
]),
Node
([
7
,
8
])]),
Node
([
25
]),
Node
([
50
])])
>>>
node
.
insert
(
6
)
>>>
node
.
insert
(
6
,
2
)
(
False
,
12
,
Node
([
4
]),
Node
([
42
]))
(
False
,
12
,
Node
([
4
]),
Node
([
42
]))
>>>
node
=
Node
([
12
,
42
],
[
Node
([
2
,
3
,
4
]),
Node
([
25
]),
Node
([
50
])]
,
3
)
>>>
node
=
Node
([
12
,
42
],
[
Node
([
2
,
3
,
4
]),
Node
([
25
]),
Node
([
50
])])
>>>
node
.
insert
(
1
)
>>>
node
.
insert
(
1
,
3
)
(
True
,
None
,
None
,
None
)
(
True
,
None
,
None
,
None
)
"""
"""
...
@@ -100,17 +110,17 @@ class Node() :
...
@@ -100,17 +110,17 @@ class Node() :
if
(
not
found
)
:
if
(
not
found
)
:
if
(
self
.
isLeaf
()):
if
(
self
.
isLeaf
()):
self
.
keys
.
insert
(
index
,
value
)
self
.
keys
.
insert
(
index
,
value
)
if
(
len
(
self
.
keys
)
>
self
.
k
):
if
(
len
(
self
.
keys
)
>
k
):
milieu
,
g
,
d
=
self
.
splitNode
()
milieu
,
g
,
d
=
self
.
splitNode
()
return
False
,
milieu
,
g
,
d
return
False
,
milieu
,
g
,
d
return
True
,
None
,
None
,
None
return
True
,
None
,
None
,
None
else
:
else
:
(
fini
,
milieu
,
g
,
d
)
=
self
.
childs
[
index
].
insert
(
value
)
(
fini
,
milieu
,
g
,
d
)
=
self
.
childs
[
index
].
insert
(
value
,
k
)
if
(
not
fini
)
:
if
(
not
fini
)
:
self
.
keys
.
insert
(
index
,
milieu
)
self
.
keys
.
insert
(
index
,
milieu
)
self
.
childs
[
index
]
=
g
self
.
childs
[
index
]
=
g
self
.
childs
.
insert
(
index
+
1
,
d
)
self
.
childs
.
insert
(
index
+
1
,
d
)
if
(
len
(
self
.
keys
)
>
self
.
k
)
:
if
(
len
(
self
.
keys
)
>
k
)
:
milieu
,
g
,
d
=
self
.
splitNode
()
milieu
,
g
,
d
=
self
.
splitNode
()
return
False
,
milieu
,
g
,
d
return
False
,
milieu
,
g
,
d
else
:
else
:
...
@@ -119,18 +129,35 @@ class Node() :
...
@@ -119,18 +129,35 @@ class Node() :
return
True
,
None
,
None
,
None
return
True
,
None
,
None
,
None
else
:
else
:
return
True
,
None
,
None
,
None
return
True
,
None
,
None
,
None
def
suppression
(
self
,
value
,
k
,
is_root
=
False
)
:
(
node
,
index
)
=
self
.
search
(
value
)
if
(
node
.
isLeaf
())
:
removed
=
node
.
keys
.
pop
(
index
)
if
(
not
is_root
):
if
(
k
//
2
<=
len
(
node
.
keys
)
<=
k
):
return
True
,
None
else
:
return
False
,
removed
else
return
True
,
None
else
:
(
ok
,
removed
)
=
self
.
supression
(
value
,
k
)
if
(
not
ok
):
def
suppr
(
self
,
value
)
:
#
def suppr(self,
value
, k
) :
"""
#
"""
>>>
a
=
Node
([
12
,
42
],
[
Node
([
3
]),
Node
([
25
]),
Node
([
50
])])
#
>>> a = Node([12, 42], [Node([3]), Node([25]), Node([50])])
>>>
a
.
suppr
(
11
)
#
>>> a.suppr(11)
False
#
False
"""
#
"""
found
=
self
.
search
(
value
)
#
found = self.search(value)
if
(
found
)
:
#
if (found) :
return
None
#
return None
else
:
#
else :
return
False
#
return False
def
splitNode
(
self
)
:
def
splitNode
(
self
)
:
...
...
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