diff --git a/src/BTree.py b/src/BTree.py index 12f8f793231dd8fb3091d9725f7fb4b3bd1cb072..00acd74d27cc3f69f898198b8de73e1c3e6a951f 100644 --- a/src/BTree.py +++ b/src/BTree.py @@ -1,6 +1,4 @@ -#import Node as Bnode from Node import Node -#from Visualization import Visualization class Btree() : @@ -36,20 +34,20 @@ class Btree() : # >>> Btree(2, Node([4, 10], [Node([1, 3]), Node([25]), Node([50])])).insertion(4) # True >>> c = Btree(2,Node([1, 10])) - >>> print(c.insertion(15)) + >>> c.insertion(15) + True """ - print(self.root) fini, milieu, g, d = self.root.insert(value, self.k) if (not fini): new_root = Node([milieu], [g, d]) self.root = new_root - print(self.root) return True def linearisation(self): """ + Exemple(s): >>> a =Btree(2, Node([12, 42], [Node([2, 3]), Node([25]), Node([50])])) >>> a.linearisation() @@ -59,20 +57,36 @@ class Btree() : def isBalance(self): """ + Verification de l'équilibrage de l'arbre + • Toutes les feuilles ont la même profondeur, à savoir la hauteur h de l’arbre. + • k/2 ≤ n ≤ k. Taux de remplissage min = 50%, et moyen 75%. + n = nombre de clés contenus dans le nœud x + • Si x n’est pas une feuille : + • pour 2<=i<=n, pour toute clef x du filsi : clesi <= x <=clesi+1 + • Pour toute clef x du fils1 : x <= cles1 + • Si x n’est pas la racine, n est compris entre k/2 et k. + + Return : + bool : true si l'arbre est bien équilibré et false sinon. + Exemple(s) : - >>> b= Btree(3, Node([12,25,50], [Node([1,11]), Node([20]), Node([30]), Node([100])])) + >>> b = Btree(3, Node([12,25,50], [Node([1,11]), Node([20]), Node([30]), Node([100])])) >>> b.isBalance() True + >>> Btree(3, Node([12,25,50,62], [Node([1,11]), Node([20]), Node([30]), Node([100])])).isBalance() + False + >>> Btree(3, Node([12,25,50], [Node([15]), Node([30]), Node([100])])).isBalance() + False + >>> Btree(3, Node([12,25,50])).isBalance() + True """ (ok, _, _, _) = self.root.is_ArbreB(self.k, True) return ok - - def equals(self, otherObject): - if not isinstance(otherObject, Btree): - return False - return (self.root.keys == otherObject.root.keys and self.k == otherObject.k) - + def __repr__(self) : + """ + representataion d'un btree + """ return f"Btree({self.root})" if __name__ == '__main__': diff --git a/src/Node.py b/src/Node.py index 2d5b863fe04c040a69d90df91949f6198373f74e..21bf61216ef850a36434550875eedb2e8b3d902c 100644 --- a/src/Node.py +++ b/src/Node.py @@ -43,6 +43,12 @@ class Node() : def is_ArbreB(self, k, is_root = False): """ + Verification de l'équilibrage de l'arbre + Params : + k => number of keys in node + Return : + (ok, height, mini, maxi) + Exemple(s) : >>> Node([5]).is_ArbreB(2) (True, 0, 5, 5) @@ -57,6 +63,8 @@ class Node() : (False, 1, 0, 5) >>> Node([5], [Node([0]), Node([7], [Node([6]), Node([8])])]).is_ArbreB(2) (False, 2, 0, 8) + >>> Node([12,25,50], [Node([1,11]), Node([20]), Node([30]), Node([100])]).is_ArbreB(3) + (True, 1, 1, 100) """ 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)) diff --git a/src/experimentation.py b/src/experimentation.py index d8ab56b8aed4857d5ba8070399afcade5a0f56ad..2566a08e624df928ce70f5fff9a28e1ba99cd04a 100644 --- a/src/experimentation.py +++ b/src/experimentation.py @@ -20,7 +20,7 @@ class experimentation: for n in [2, 4, 5] + list(range(6, 37, 2)) + [7, 9, 11, 13]: self.btree.insertion(n) - # TODO Visualization(self.btree).render() + #Visualization(self.btree).render() print(self.btree) diff --git a/src/test/BtreeTest.py b/src/test/BtreeTest.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/src/test/experimentation.py b/src/test/experimentation.py deleted file mode 100644 index 9100be1e698b56aa54d4b930ed59c345a4dc3887..0000000000000000000000000000000000000000 --- a/src/test/experimentation.py +++ /dev/null @@ -1,15 +0,0 @@ -import unittest -from Node import * - -class experimentation: - def setUp(self): - self.node = Node([12, 42], ) - - -if __name__ == "__main__": - import sys - sys.path.insert(1, './src') - sys.path.insert(2, '../src') - from Node import * - - unittest.main() \ No newline at end of file