forked from UNN/2026-rff_mp
[16] adding plt
This commit is contained in:
parent
17d62ab5ad
commit
d71c9d311e
|
|
@ -1,6 +1,7 @@
|
||||||
import random as rnd
|
import random as rnd
|
||||||
import time
|
import time
|
||||||
import csv
|
import csv
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
#############################################################################################
|
#############################################################################################
|
||||||
|
|
||||||
def sort_list(name_list):
|
def sort_list(name_list):
|
||||||
|
|
@ -24,6 +25,17 @@ def file_insert(results):
|
||||||
with open("results.csv", "w", encoding = "utf-8-sig", newline = "") as file:
|
with open("results.csv", "w", encoding = "utf-8-sig", newline = "") as file:
|
||||||
writer = csv.writer(file)
|
writer = csv.writer(file)
|
||||||
writer.writerows(results)
|
writer.writerows(results)
|
||||||
|
|
||||||
|
def drow(time, color_fun):
|
||||||
|
x = []
|
||||||
|
y = []
|
||||||
|
for key in time:
|
||||||
|
x.append(key)
|
||||||
|
y.append(time[key] * 1000)
|
||||||
|
plt.plot(x, y, marker = ".", color = color_fun, markersize = 2, alpha = 0.9)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
###########################################################################################################################
|
###########################################################################################################################
|
||||||
|
|
||||||
def ll_insert(head, name, phone):
|
def ll_insert(head, name, phone):
|
||||||
|
|
@ -122,7 +134,7 @@ def LinkedList(head, phone_book):
|
||||||
#########################################################################################################
|
#########################################################################################################
|
||||||
|
|
||||||
def ht_insert(buckest, name, phone):
|
def ht_insert(buckest, name, phone):
|
||||||
index = hash_key(name) % 10
|
index = hash_key(name) % len(buckest)
|
||||||
for i, (Name, Phone) in enumerate(buckest[index]):
|
for i, (Name, Phone) in enumerate(buckest[index]):
|
||||||
if Name == name:
|
if Name == name:
|
||||||
buckest[index][i] = (name, phone)
|
buckest[index][i] = (name, phone)
|
||||||
|
|
@ -131,7 +143,7 @@ def ht_insert(buckest, name, phone):
|
||||||
return buckest
|
return buckest
|
||||||
|
|
||||||
def ht_find(buckest, name):
|
def ht_find(buckest, name):
|
||||||
index = hash_key(name) % 10
|
index = hash_key(name) % len(buckest)
|
||||||
for (Name, Phone) in buckest[index]:
|
for (Name, Phone) in buckest[index]:
|
||||||
if Name == name:
|
if Name == name:
|
||||||
return Phone
|
return Phone
|
||||||
|
|
@ -151,7 +163,7 @@ def ht_list_all(buckest):
|
||||||
|
|
||||||
|
|
||||||
def ht_delete(buckest, name):
|
def ht_delete(buckest, name):
|
||||||
index = hash_key(name) % 10
|
index = hash_key(name) % len(buckest)
|
||||||
for i, (Name, Phone) in enumerate(buckest[index]):
|
for i, (Name, Phone) in enumerate(buckest[index]):
|
||||||
if Name == name:
|
if Name == name:
|
||||||
del buckest[index][i]
|
del buckest[index][i]
|
||||||
|
|
@ -331,7 +343,7 @@ def main():
|
||||||
|
|
||||||
phone_book_sorted = phone_book.copy()
|
phone_book_sorted = phone_book.copy()
|
||||||
phone_book_sorted = sort_list(phone_book_sorted)
|
phone_book_sorted = sort_list(phone_book_sorted)
|
||||||
replay = 5
|
replay = 10
|
||||||
|
|
||||||
|
|
||||||
Time_ll_not_sorted = []
|
Time_ll_not_sorted = []
|
||||||
|
|
@ -457,6 +469,26 @@ def main():
|
||||||
for i in range(1, len(results) - 1):
|
for i in range(1, len(results) - 1):
|
||||||
results[i][3] *= 1000
|
results[i][3] *= 1000
|
||||||
file_insert(results)
|
file_insert(results)
|
||||||
|
|
||||||
|
plt.figure(figsize = (16, 9))
|
||||||
|
plt.xlabel("Операция")
|
||||||
|
plt.ylabel("Время мс")
|
||||||
|
|
||||||
|
drow(Time_average_ll_not_sorted, "blue")
|
||||||
|
drow(Time_average_ll_sorted, "green")
|
||||||
|
drow(Time_average_ht_not_sorted, "#FF8800")
|
||||||
|
drow(Time_average_ht_sorted, "#FF0000")
|
||||||
|
drow(Time_average_bst_not_sorted, "#464219")
|
||||||
|
drow(Time_average_bst_sorted, "#FBFF00")
|
||||||
|
|
||||||
|
text = """
|
||||||
|
синий - LinkedList (not sorted) ораньжевый - HashTable (not sorted) коричневый - BST (not sorted)
|
||||||
|
зеленый - LinkedList (sorted) красный - HashTable (sorted) желтый - BST (sorted)
|
||||||
|
"""
|
||||||
|
# plt.subplots_adjust(bottom =0.3)
|
||||||
|
plt.figtext(0.1, 0.02, text, wrap = True, fontsize = 9, va = 'bottom')
|
||||||
|
plt.savefig("time_schedule.png")
|
||||||
|
plt.show()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user