diff --git a/README.md b/README.md index ff2a03c93046840e023278f4164e8084e8f938d2..fedb47e33bffde858b8b3fa60a9efa6a69283c8f 100644 --- a/README.md +++ b/README.md @@ -68,4 +68,4 @@ Suite suppression, fonctionne pour le cas d'une feuille. ### emaine 12 -Création du Readme, suite suppression. \ No newline at end of file +Suite suppression. \ No newline at end of file diff --git a/src/ArbreB/Graph.gv b/src/ArbreB/Graph.gv deleted file mode 100644 index 40c16205029aa9c865e2911afcf96e17b99f010a..0000000000000000000000000000000000000000 --- a/src/ArbreB/Graph.gv +++ /dev/null @@ -1,12 +0,0 @@ -graph { - "[12, 42]" - "[2, 3]" - "[12, 42]" -- "[2, 3]" - "[2, 3]" - "[25]" - "[12, 42]" -- "[25]" - "[25]" - "[50]" - "[12, 42]" -- "[50]" - "[50]" -} diff --git a/src/ArbreB/Graph.gv.svg b/src/ArbreB/Graph.gv.svg deleted file mode 100644 index b9aafa075da3a40a4dc6c31134db139d96f77a38..0000000000000000000000000000000000000000 --- a/src/ArbreB/Graph.gv.svg +++ /dev/null @@ -1,52 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" - "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> -<!-- Generated by graphviz version 2.43.0 (0) - --> -<!-- Title: %3 Pages: 1 --> -<svg width="230pt" height="116pt" - viewBox="0.00 0.00 230.34 116.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> -<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 112)"> -<title>%3</title> -<polygon fill="white" stroke="transparent" points="-4,4 -4,-112 226.34,-112 226.34,4 -4,4"/> -<!-- [12, 42] --> -<g id="node1" class="node"> -<title>[12, 42]</title> -<ellipse fill="none" stroke="black" cx="117.1" cy="-90" rx="46.59" ry="18"/> -<text text-anchor="middle" x="117.1" y="-86.3" font-family="Times,serif" font-size="14.00">[12, 42]</text> -</g> -<!-- [2, 3] --> -<g id="node2" class="node"> -<title>[2, 3]</title> -<ellipse fill="none" stroke="black" cx="35.1" cy="-18" rx="35.19" ry="18"/> -<text text-anchor="middle" x="35.1" y="-14.3" font-family="Times,serif" font-size="14.00">[2, 3]</text> -</g> -<!-- [12, 42]--[2, 3] --> -<g id="edge1" class="edge"> -<title>[12, 42]--[2, 3]</title> -<path fill="none" stroke="black" d="M98.49,-73.12C84.69,-61.34 66.01,-45.39 52.51,-33.86"/> -</g> -<!-- [25] --> -<g id="node3" class="node"> -<title>[25]</title> -<ellipse fill="none" stroke="black" cx="117.1" cy="-18" rx="29.5" ry="18"/> -<text text-anchor="middle" x="117.1" y="-14.3" font-family="Times,serif" font-size="14.00">[25]</text> -</g> -<!-- [12, 42]--[25] --> -<g id="edge2" class="edge"> -<title>[12, 42]--[25]</title> -<path fill="none" stroke="black" d="M117.1,-71.7C117.1,-60.85 117.1,-46.92 117.1,-36.1"/> -</g> -<!-- [50] --> -<g id="node4" class="node"> -<title>[50]</title> -<ellipse fill="none" stroke="black" cx="193.1" cy="-18" rx="29.5" ry="18"/> -<text text-anchor="middle" x="193.1" y="-14.3" font-family="Times,serif" font-size="14.00">[50]</text> -</g> -<!-- [12, 42]--[50] --> -<g id="edge3" class="edge"> -<title>[12, 42]--[50]</title> -<path fill="none" stroke="black" d="M134.34,-73.12C147.31,-61.18 164.92,-44.95 177.47,-33.39"/> -</g> -</g> -</svg> diff --git a/src/Node.py b/src/Node.py index cc4dee2556dcb23166ff308ee7743dd09f721e8e..7a40bb35eccf504183e034ef5c261289d2fcc829 100644 --- a/src/Node.py +++ b/src/Node.py @@ -96,12 +96,12 @@ class Node() : (Node([50, 52]), 1) >>> node = Node([12, 42], [Node([2, 3]), Node([25]), Node([50])]) >>> node.insert(1, 2) - (False, 12, Node([2]), Node([42])) + (False, 12, Node([2], [Node([1]), Node([3])]), Node([42], [Node([25]), Node([50])])) >>> node.search(1) (Node([1]), 0) >>> node = Node([12, 42], [Node([2, 4], [Node([0, 1]), Node([3]), Node([7, 8])]), Node([25]), Node([50])]) >>> node.insert(6, 2) - (False, 12, Node([4]), Node([42])) + (False, 12, Node([4], [Node([2], [Node([0, 1]), Node([3])]), Node([7], [Node([6]), Node([8])])]), Node([42], [Node([25]), Node([50])])) >>> node = Node([12, 42], [Node([2, 3, 4]), Node([25]), Node([50])]) >>> node.insert(1, 3) @@ -137,8 +137,20 @@ class Node() : Exemple(s): >>> node = Node([12, 42], [Node([3, 4]), Node([25, 26]), Node([50, 58])]) >>> node.suppression(50, 2) - - + True + >>> node.search(50) + >>> node.suppression(26, 2) + True + >>> node.search(26) + >>> node.suppression(25, 2) + True + >>> node.search(25) + >>> node.suppression(12, 2) + True + >>> node + >>> node.suppression(3, 2) + True + >>> node """ (found, index) = recherche_dichotomique(value, self.keys) if (self.isLeaf()) : @@ -147,33 +159,32 @@ class Node() : else: (ok) = self.childs[index].suppression(value, k, False) if (not ok): - if(index - 1 >= 0 and (len(self.childs[index-1].keys) >= k//2)): + if(index - 1 >= 0 and (len(self.childs[index-1].keys) - 1 >= k//2)): borrowed = self.childs[index-1].keys.pop() replaced = self.keys.pop(0) self.keys.insert(0, borrowed) self.childs[index].keys.insert(0, replaced) - elif(index + 1 < len(self.childs) and (len(self.childs[index+1].keys) >= k//2)): - borrowed = self.childs[index+1].keys.pop(0) + elif(index + 1 < len(self.childs) and (len(self.childs[index+1].keys) - 1 >= k//2)): + borrowed = self.childs[index+1].keys.pop() replaced = self.keys.pop() - self.keys.insert(len(self.keys), borrowed) - self.childs[index].keys.insert(len(self.childs), replaced) - - - return ok - - -# def suppr(self, value, k) : -# """ -# >>> a = Node([12, 42], [Node([3]), Node([25]), Node([50])]) -# >>> a.suppr(11) -# False -# """ -# found = self.search(value) -# if (found) : -# return None -# else : -# return False - + self.childs[index].keys.insert(len(self.keys), borrowed) + self.childs[index].keys.insert(len(self.childs[index].keys), replaced) # len(self.childs) + else: + if(index-1 >= 0): + replaced = self.keys.pop(index-1) + borrowed = self.childs[index-1].keys.pop() + self.childs[index].keys.insert(len(self.childs[index].keys), replaced) + self.childs[index].keys.insert(0, borrowed) + del self.childs[index-1] + elif(index + 1 < len(self.childs)): + replaced = self.keys.pop(index) + borrowed = self.childs[index+1].keys.pop() + self.childs[index].keys.insert(0, borrowed) + self.childs[index].keys.insert(len(self.childs[index].keys), replaced) + del self.childs[index+1] + ok = not ok + + return ok def splitNode(self) : """ @@ -208,8 +219,7 @@ class Node() : res.extend(self.childs[len(self.childs)-1].linearisation()) return res - - + def __repr__(self) : return (f"Node({self.keys}" + (f", {self.childs})" if len(self.childs) > 0 else ")")) diff --git a/src/Visualization.py b/src/Visualization.py index 7059052fb04b9b743065882e9b9e9191c8b86568..6493999b2b4049406954fa54c90fee49e794884c 100644 --- a/src/Visualization.py +++ b/src/Visualization.py @@ -20,6 +20,6 @@ class Visualization() : self.add_node_to_graph(childKeys) def render(self): - self.g.format = 'svg' + self.g.format = 'jpg' self.g.render(directory='ArbreB', view=True) \ No newline at end of file