AVL implementation
This commit is contained in:
parent
1df8100e14
commit
2b2a97d1da
@ -1,3 +1,4 @@
|
||||
matplotlib
|
||||
numpy
|
||||
pygame
|
||||
graphviz
|
||||
|
58
vorlesung/L06_b_baeume/analyze_b_tree.py
Normal file
58
vorlesung/L06_b_baeume/analyze_b_tree.py
Normal file
@ -0,0 +1,58 @@
|
||||
from utils.memory_manager import MemoryManager
|
||||
from utils.memory_array import MemoryArray
|
||||
from utils.literal import Literal
|
||||
from b_tree import BTree
|
||||
from b_tree_node import BTreeNode
|
||||
|
||||
class MemoryManagerBTree(MemoryManager):
|
||||
"""
|
||||
Diese Klasse erweitert den MemoryManager, um spezifische Statistiken für B-Bäume zu speichern.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def count_loads():
|
||||
return sum([cell.loaded_count for cell in MemoryManager().cells if isinstance(cell, BTreeNode)])
|
||||
|
||||
@staticmethod
|
||||
def count_saves():
|
||||
return sum([cell.saved_count for cell in MemoryManager().cells if isinstance(cell, BTreeNode)])
|
||||
|
||||
@staticmethod
|
||||
def save_stats(count):
|
||||
data = { "cells": MemoryManager.count_cells(),
|
||||
"reads": MemoryManager.count_reads(),
|
||||
"writes": MemoryManager.count_writes(),
|
||||
"compares": MemoryManager.count_compares(),
|
||||
"adds": MemoryManager.count_adds(),
|
||||
"subs": MemoryManager.count_subs(),
|
||||
"muls": MemoryManager.count_muls(),
|
||||
"divs": MemoryManager.count_divs(),
|
||||
"bitops": MemoryManager.count_bitops(),
|
||||
"loads": MemoryManagerBTree.count_loads(),
|
||||
"saves": MemoryManagerBTree.count_saves() }
|
||||
MemoryManager.stats[count] = data
|
||||
|
||||
|
||||
|
||||
|
||||
def analyze_complexity(sizes):
|
||||
"""
|
||||
Analysiert die Komplexität
|
||||
|
||||
:param sizes: Eine Liste von Eingabegrößen für die Analyse.
|
||||
"""
|
||||
for size in sizes:
|
||||
MemoryManager.purge() # Speicher zurücksetzen
|
||||
tree = BTree(5)
|
||||
random_array = MemoryArray.create_random_array(size, -100, 100)
|
||||
for i in range(size-1):
|
||||
tree.insert(int(random_array[Literal(i)]))
|
||||
MemoryManager.reset()
|
||||
tree.insert(int(random_array[Literal(size-1)]))
|
||||
MemoryManagerBTree.save_stats(size)
|
||||
|
||||
MemoryManager.plot_stats(["cells", "compares", "loads", "saves"])
|
||||
|
||||
if __name__ == "__main__":
|
||||
sizes = range(1, 1001, 2)
|
||||
analyze_complexity(sizes)
|
Loading…
x
Reference in New Issue
Block a user