diff --git a/src/ArbreB/Graph.gv b/src/ArbreB/Graph.gv new file mode 100644 index 0000000000000000000000000000000000000000..40c16205029aa9c865e2911afcf96e17b99f010a --- /dev/null +++ b/src/ArbreB/Graph.gv @@ -0,0 +1,12 @@ +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 new file mode 100644 index 0000000000000000000000000000000000000000..b9aafa075da3a40a4dc6c31134db139d96f77a38 --- /dev/null +++ b/src/ArbreB/Graph.gv.svg @@ -0,0 +1,52 @@ +<?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/BTree.py b/src/BTree.py index 5be9bdac617c08c1bdae443897f68478db7a1106..4a838d50bfd7e54380749db8a2b1a17760ea4777 100644 --- a/src/BTree.py +++ b/src/BTree.py @@ -1,5 +1,6 @@ #import Node as Bnode from Node import * +from Visualization import * class Btree() : @@ -42,25 +43,15 @@ class Btree() : self.root = new_root return True - def linearisation(self, node): + + def linearisation(self): """ Exemple(s): - >>> a = Btree(2) - >>> node = Node([6], [Node([1]), Node([7])]) - >>> a.linearisation(node) - () + >>> a =Btree(2, Node([12, 42], [Node([2, 3]), Node([25]), Node([50])])) + >>> a.linearisation() + [2, 3, 12, 25, 42, 50] """ - if (node): - if (node.isLeaf()): - for i in node.keys: - print(i) - else: - if (len(node.keys) == 1): - self.linearisation(node.childs[0]) - print(node.keys[0]) - self.linearisation(node.childs[1]) - else: - for + return self.root.linearisation() def __repr__(self) : diff --git a/src/Node.py b/src/Node.py index 683bab2c111842126c9ed729e21da4c996d11354..aa69412b7a4a7a56ff12dae8535444149476fb90 100644 --- a/src/Node.py +++ b/src/Node.py @@ -125,6 +125,8 @@ class Node() : def linearisation(self): """ Exemple(s): + >>> Node([12, 42], [Node([2, 3]), Node([13, 15]), Node([45])]).linearisation() + [2, 3, 12, 13, 15, 42, 45] >>> Node([12, 42], [Node([2, 3]), Node([25]), Node([50])]).linearisation() [2, 3, 12, 25, 42, 50] """ diff --git a/src/Visualization.py b/src/Visualization.py new file mode 100644 index 0000000000000000000000000000000000000000..7059052fb04b9b743065882e9b9e9191c8b86568 --- /dev/null +++ b/src/Visualization.py @@ -0,0 +1,25 @@ +import graphviz +from Node import * +from BTree import * + + +class Visualization() : + + def __init__(self, btree): + self.btree = btree + self.g = graphviz.Graph() + self.add_node_to_graph(self.btree.root) + + def add_node_to_graph(self, node): + nodeKeys = repr(node.keys) + self.g.node(nodeKeys) + for child in node.childs: + childKeys = repr(child.keys) + self.g.node(childKeys) + self.g.edge(nodeKeys, childKeys) + self.add_node_to_graph(childKeys) + + def render(self): + self.g.format = 'svg' + self.g.render(directory='ArbreB', view=True) + \ No newline at end of file