# -*- coding: utf-8 -*-
"""
Created on Fri May  1 11:42:31 2026

@author: ddima
"""

import matplotlib.pyplot as plt
import numpy as np

data = {
    ("LinkedList", "shuffled", "insert"): 3.46348492,
    ("HashTable", "shuffled", "insert"): 0.01967166,
    ("BST", "shuffled", "insert"): 0.01715242,

    ("LinkedList", "shuffled", "find"): 0.0301834,
    ("HashTable", "shuffled", "find"): 0.0002298400002,
    ("BST", "shuffled", "find"): 0.0002346200003,

    ("LinkedList", "shuffled", "delete"): 0.01254974,
    ("HashTable", "shuffled", "delete"): 0.0001220800004,
    ("BST", "shuffled", "delete"): 0.0001421199995,

    ("LinkedList", "sorted", "insert"): 3.2739972,
    ("HashTable", "sorted", "insert"): 0.01923022,
    ("BST", "sorted", "insert"): 4.01406982,

    ("LinkedList", "sorted", "find"): 0.0252881,
    ("HashTable", "sorted", "find"): 0.0002579799999,
    ("BST", "sorted", "find"): 0.0369953,

    ("LinkedList", "sorted", "delete"): 0.01326564,
    ("HashTable", "sorted", "delete"): 0.0001182399996,
    ("BST", "sorted", "delete"): 0.02074794,
}

structures = ["BST", "LinkedList", "HashTable"]
structure_labels = ["Бинарное дерево", "Связный список", "Хэш-таблица"]

operations = [("insert", "Вставка"), ("find", "Поиск"), ("delete", "Удаление"),]

for op_key, op_title in operations:
    shuffled_values = [data[(s, "shuffled", op_key)] for s in structures]
    sorted_values = [data[(s, "sorted", op_key)] for s in structures]

    x = np.arange(len(structures))
    width = 0.35

    plt.figure(figsize=(8, 5))

    plt.bar(x - width / 2, shuffled_values, width, label="Случайный")
    plt.bar(x + width / 2, sorted_values, width, label="Отсортированный")

    plt.title(op_title)
    plt.ylabel("Время (сек)")
    plt.xticks(x, structure_labels)
    plt.legend()
    plt.grid(axis="y", alpha=0.3)
    plt.tight_layout()

    plt.savefig(f"{op_key}_chart.svg", format="svg")
    plt.show()