broken fucking zad3 I don't care anymore

This commit is contained in:
jacekpoz 2024-04-11 05:28:53 +02:00
parent 14d2966b51
commit 118d4e911a
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
61 changed files with 847 additions and 0 deletions

1
lab2/zad3/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
target/

87
lab2/zad3/Cargo.lock generated Normal file
View file

@ -0,0 +1,87 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "getrandom"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "libc"
version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "libgen"
version = "0.1.0"
dependencies = [
"rand",
]
[[package]]
name = "libsort"
version = "0.1.0"
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "zad3"
version = "0.1.0"
dependencies = [
"libgen",
"libsort",
]

8
lab2/zad3/Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "zad3"
version = "0.1.0"
edition = "2021"
[dependencies]
libgen = { path = "../zad1/libgen" }
libsort = { path = "../zad1/libsort" }

View file

@ -0,0 +1,12 @@
set title "Average comparisons, k = 1, n ∈ {1000, 2000, ..., 50000}"
set style data lines
set xlabel "n"
set ylabel "Average comparisons"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k1/large" \
using 1:2 t "MergeSort", \
"" using 1:4 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average comparisons / n, k = 1, n ∈ {1000, 2000, ..., 50000}"
set style data lines
set xlabel "n"
set ylabel "Average comparisons / n"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k1/large" \
using 1:6 t "MergeSort", \
"" using 1:8 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average comparisons, k = 1, n ∈ {10, 20, ..., 50}"
set style data lines
set xlabel "n"
set ylabel "Average comparisons"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k1/small" \
using 1:2 t "MergeSort", \
"" using 1:4 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average comparisons / n, k = 1, n ∈ {10, 20, ..., 50}"
set style data lines
set xlabel "n"
set ylabel "Average comparisons / n"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k1/small" \
using 1:6 t "MergeSort", \
"" using 1:8 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average swaps, k = 1, n ∈ {1000, 2000, ..., 50000}"
set style data lines
set xlabel "n"
set ylabel "Average swaps"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k1/large" \
using 1:3 t "MergeSort", \
"" using 1:5 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average swaps / n, k = 1, n ∈ {1000, 2000, ..., 50000}"
set style data lines
set xlabel "n"
set ylabel "Average swaps / n"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k1/large" \
using 1:7 t "MergeSort", \
"" using 1:9 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average swaps, k = 1, n ∈ {10, 20, ..., 50}"
set style data lines
set xlabel "n"
set ylabel "Average swaps"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k1/small" \
using 1:3 t "MergeSort", \
"" using 1:5 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average swaps / n, k = 1, n ∈ {10, 20, ..., 50}"
set style data lines
set xlabel "n"
set ylabel "Average swaps / n"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k1/small" \
using 1:7 t "MergeSort", \
"" using 1:9 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average comparisons, k = 10, n ∈ {1000, 2000, ..., 50000}"
set style data lines
set xlabel "n"
set ylabel "Average comparisons"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k10/large" \
using 1:2 t "MergeSort", \
"" using 1:4 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average comparisons / n, k = 10, n ∈ {1000, 2000, ..., 50000}"
set style data lines
set xlabel "n"
set ylabel "Average comparisons / n"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k10/large" \
using 1:6 t "MergeSort", \
"" using 1:8 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average comparisons, k = 10, n ∈ {10, 20, ..., 50}"
set style data lines
set xlabel "n"
set ylabel "Average comparisons"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k10/small" \
using 1:2 t "MergeSort", \
"" using 1:4 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average comparisons / n, k = 10, n ∈ {10, 20, ..., 50}"
set style data lines
set xlabel "n"
set ylabel "Average comparisons / n"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k10/small" \
using 1:6 t "MergeSort", \
"" using 1:8 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average swaps, k = 10, n ∈ {1000, 2000, ..., 50000}"
set style data lines
set xlabel "n"
set ylabel "Average swaps"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k10/large" \
using 1:3 t "MergeSort", \
"" using 1:5 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average swaps / n, k = 10, n ∈ {1000, 2000, ..., 50000}"
set style data lines
set xlabel "n"
set ylabel "Average swaps / n"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k10/large" \
using 1:7 t "MergeSort", \
"" using 1:9 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average swaps, k = 10, n ∈ {10, 20, ..., 50}"
set style data lines
set xlabel "n"
set ylabel "Average swaps"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k10/small" \
using 1:3 t "MergeSort", \
"" using 1:5 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average swaps / n, k = 10, n ∈ {10, 20, ..., 50}"
set style data lines
set xlabel "n"
set ylabel "Average swaps / n"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k10/small" \
using 1:7 t "MergeSort", \
"" using 1:9 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average comparisons, k = 100, n ∈ {1000, 2000, ..., 50000}"
set style data lines
set xlabel "n"
set ylabel "Average comparisons"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k100/large" \
using 1:2 t "MergeSort", \
"" using 1:4 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average comparisons / n, k = 100, n ∈ {1000, 2000, ..., 50000}"
set style data lines
set xlabel "n"
set ylabel "Average comparisons / n"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k100/large" \
using 1:6 t "MergeSort", \
"" using 1:8 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average comparisons, k = 100, n ∈ {10, 20, ..., 50}"
set style data lines
set xlabel "n"
set ylabel "Average comparisons"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k100/small" \
using 1:2 t "MergeSort", \
"" using 1:4 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average comparisons / n, k = 100, n ∈ {10, 20, ..., 50}"
set style data lines
set xlabel "n"
set ylabel "Average comparisons / n"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k100/small" \
using 1:6 t "MergeSort", \
"" using 1:8 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average swaps, k = 100, n ∈ {1000, 2000, ..., 50000}"
set style data lines
set xlabel "n"
set ylabel "Average swaps"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k100/large" \
using 1:3 t "MergeSort", \
"" using 1:5 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average swaps / n, k = 100, n ∈ {1000, 2000, ..., 50000}"
set style data lines
set xlabel "n"
set ylabel "Average swaps / n"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k100/large" \
using 1:7 t "MergeSort", \
"" using 1:9 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average swaps, k = 100, n ∈ {10, 20, ..., 50}"
set style data lines
set xlabel "n"
set ylabel "Average swaps"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k100/small" \
using 1:3 t "MergeSort", \
"" using 1:5 t "MySort"
# vim: ft=gnuplot

View file

@ -0,0 +1,12 @@
set title "Average swaps / n, k = 100, n ∈ {10, 20, ..., 50}"
set style data lines
set xlabel "n"
set ylabel "Average swaps / n"
set term pdfcairo font "JetBrainsMono-NF,12"
plot "./results/k100/small" \
using 1:7 t "MergeSort", \
"" using 1:9 t "MySort"
# vim: ft=gnuplot

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,50 @@
1000 8673 9976 0 0 8.673 9.976 0 0
2000 19398 21952 0 0 9.699 10.976 0 0
3000 30887 34904 0 0 10.295666666666667 11.634666666666666 0 0
4000 42846 47904 0 0 10.7115 11.976 0 0
5000 55247 61808 0 0 11.0494 12.3616 0 0
6000 67803 75808 0 0 11.3005 12.634666666666666 0 0
7000 80722 89808 0 0 11.531714285714285 12.829714285714285 0 0
8000 93668 103808 0 0 11.7085 12.976 0 0
9000 106973 118616 0 0 11.88588888888889 13.179555555555556 0 0
10000 120515 133616 0 0 12.0515 13.3616 0 0
11000 134055 148616 0 0 12.186818181818182 13.510545454545454 0 0
12000 147651 163616 0 0 12.30425 13.634666666666666 0 0
13000 161484 178616 0 0 12.421846153846154 13.739692307692307 0 0
14000 175300 193616 0 0 12.521428571428572 13.829714285714285 0 0
15000 189292 208616 0 0 12.619466666666666 13.907733333333333 0 0
16000 203405 223616 0 0 12.7128125 13.976 0 0
17000 217647 239232 0 0 12.802764705882353 14.072470588235294 0 0
18000 232012 255232 0 0 12.889555555555555 14.179555555555556 0 0
19000 246375 271232 0 0 12.967105263157896 14.275368421052631 0 0
20000 260902 287232 0 0 13.0451 14.3616 0 0
21000 275522 303232 0 0 13.120095238095239 14.439619047619047 0 0
22000 290140 319232 0 0 13.188181818181818 14.510545454545454 0 0
23000 304633 335232 0 0 13.244913043478261 14.575304347826087 0 0
24000 319410 351232 0 0 13.30875 14.634666666666666 0 0
25000 333969 367232 0 0 13.35876 14.68928 0 0
26000 348975 383232 0 0 13.422115384615385 14.739692307692307 0 0
27000 363629 399232 0 0 13.46774074074074 14.78637037037037 0 0
28000 378857 415232 0 0 13.530607142857143 14.829714285714285 0 0
29000 393683 431232 0 0 13.575275862068965 14.870068965517241 0 0
30000 408503 447232 0 0 13.616766666666667 14.907733333333333 0 0
31000 423472 463232 0 0 13.660387096774194 14.942967741935483 0 0
32000 438513 479232 0 0 13.70353125 14.976 0 0
33000 453823 495464 0 0 13.752212121212121 15.014060606060607 0 0
34000 468989 512464 0 0 13.793794117647058 15.072470588235294 0 0
35000 484477 529464 0 0 13.8422 15.127542857142856 0 0
36000 499974 546464 0 0 13.888166666666667 15.179555555555556 0 0
37000 515463 563464 0 0 13.931432432432432 15.228756756756757 0 0
38000 530839 580464 0 0 13.969447368421053 15.275368421052631 0 0
39000 546316 597464 0 0 14.008102564102565 15.319589743589743 0 0
40000 561781 614464 0 0 14.044525 15.3616 0 0
41000 577116 631464 0 0 14.076 15.401560975609756 0 0
42000 592927 648464 0 0 14.117309523809524 15.439619047619047 0 0
43000 608475 665464 0 0 14.150581395348837 15.475906976744186 0 0
44000 624359 682464 0 0 14.189977272727273 15.510545454545454 0 0
45000 639519 699464 0 0 14.211533333333334 15.543644444444444 0 0
46000 655526 716464 0 0 14.250565217391305 15.575304347826087 0 0
47000 670997 733464 0 0 14.276531914893617 15.605617021276595 0 0
48000 686741 750464 0 0 14.307104166666667 15.634666666666666 0 0
49000 702202 767464 0 0 14.33065306122449 15.662530612244899 0 0
50000 718211 784464 0 0 14.36422 15.68928 0 0

View file

@ -0,0 +1,5 @@
10 25 34 0 0 2.5 3.4 0 0
20 64 88 0 0 3.2 4.4 0 0
30 106 148 0 0 3.533333333333333 4.933333333333334 0 0
40 164 216 0 0 4.1 5.4 0 0
50 216 286 0 0 4.32 5.72 0 0

View file

@ -0,0 +1,50 @@
1000 8711.5 9976 0 0 8.7115 9.976 0 0
2000 19422.2 21952 0 0 9.7111 10.976 0 0
3000 30942.7 34904 0 0 10.314233333333334 11.634666666666666 0 0
4000 42809.4 47904 0 0 10.702350000000001 11.976 0 0
5000 55228.3 61808 0 0 11.04566 12.3616 0 0
6000 67825.4 75808 0 0 11.304233333333332 12.634666666666666 0 0
7000 80679.6 89808 0 0 11.525657142857144 12.829714285714285 0 0
8000 93640.4 103808 0 0 11.70505 12.976 0 0
9000 107003.2 118616 0 0 11.889244444444444 13.179555555555556 0 0
10000 120464 133616 0 0 12.0464 13.3616 0 0
11000 134030.3 148616 0 0 12.184572727272727 13.510545454545454 0 0
12000 147662.7 163616 0 0 12.305225000000002 13.634666666666666 0 0
13000 161476.3 178616 0 0 12.421253846153846 13.739692307692307 0 0
14000 175392.4 193616 0 0 12.528028571428571 13.829714285714285 0 0
15000 189291.7 208616 0 0 12.619446666666667 13.907733333333333 0 0
16000 203298.2 223616 0 0 12.7061375 13.976 0 0
17000 217562.3 239232 0 0 12.797782352941176 14.072470588235294 0 0
18000 231914.1 255232 0 0 12.884116666666667 14.179555555555556 0 0
19000 246395 271232 0 0 12.968157894736843 14.275368421052631 0 0
20000 260881 287232 0 0 13.04405 14.3616 0 0
21000 275425 303232 0 0 13.11547619047619 14.439619047619047 0 0
22000 290012.2 319232 0 0 13.182372727272728 14.510545454545454 0 0
23000 304705.5 335232 0 0 13.248065217391304 14.575304347826087 0 0
24000 319352.9 351232 0 0 13.306370833333334 14.634666666666666 0 0
25000 334111 367232 0 0 13.36444 14.68928 0 0
26000 348940.9 383232 0 0 13.420803846153847 14.739692307692307 0 0
27000 363869.1 399232 0 0 13.476633333333332 14.78637037037037 0 0
28000 378703.5 415232 0 0 13.525125 14.829714285714285 0 0
29000 393650.7 431232 0 0 13.574162068965517 14.870068965517241 0 0
30000 408580.5 447232 0 0 13.61935 14.907733333333333 0 0
31000 423581.3 463232 0 0 13.663912903225807 14.942967741935483 0 0
32000 438566.1 479232 0 0 13.705190624999998 14.976 0 0
33000 453670 495464 0 0 13.747575757575758 15.014060606060607 0 0
34000 469045.5 512464 0 0 13.795455882352941 15.072470588235294 0 0
35000 484428.7 529464 0 0 13.84082 15.127542857142856 0 0
36000 499839.5 546464 0 0 13.884430555555555 15.179555555555556 0 0
37000 515296.9 563464 0 0 13.926943243243244 15.228756756756757 0 0
38000 530794.1 580464 0 0 13.968265789473683 15.275368421052631 0 0
39000 546310.5 597464 0 0 14.007961538461538 15.319589743589743 0 0
40000 561804.8 614464 0 0 14.04512 15.3616 0 0
41000 577293.2 631464 0 0 14.080321951219512 15.401560975609756 0 0
42000 592914.4 648464 0 0 14.117009523809525 15.439619047619047 0 0
43000 608527.6 665464 0 0 14.15180465116279 15.475906976744186 0 0
44000 624184.5 682464 0 0 14.186011363636364 15.510545454545454 0 0
45000 639718.5 699464 0 0 14.215966666666667 15.543644444444444 0 0
46000 655369 716464 0 0 14.247152173913044 15.575304347826087 0 0
47000 671011.8 733464 0 0 14.276846808510639 15.605617021276595 0 0
48000 686625.9 750464 0 0 14.30470625 15.634666666666666 0 0
49000 702414.1 767464 0 0 14.334981632653061 15.662530612244899 0 0
50000 718162.4 784464 0 0 14.363248 15.68928 0 0

View file

@ -0,0 +1,5 @@
10 23.1 34 0 0 2.31 3.4 0 0
20 62.7 88 0 0 3.1350000000000002 4.4 0 0
30 111.2 148 0 0 3.7066666666666666 4.933333333333334 0 0
40 164.5 216 0 0 4.1125 5.4 0 0
50 223.1 286 0 0 4.462 5.72 0 0

View file

@ -0,0 +1,50 @@
1000 8710.58 9976 0 0 8.71058 9.976 0 0
2000 19409.17 21952 0 0 9.704585 10.976 0 0
3000 30921.46 34904 0 0 10.307153333333334 11.634666666666666 0 0
4000 42817.8 47904 0 0 10.704450000000001 11.976 0 0
5000 55227.25 61808 0 0 11.04545 12.3616 0 0
6000 67838.23 75808 0 0 11.306371666666665 12.634666666666666 0 0
7000 80684.73 89808 0 0 11.52639 12.829714285714285 0 0
8000 93644.96 103808 0 0 11.705620000000001 12.976 0 0
9000 106969.59 118616 0 0 11.88551 13.179555555555556 0 0
10000 120439.66 133616 0 0 12.043966000000001 13.3616 0 0
11000 134037.86 148616 0 0 12.18526 13.510545454545454 0 0
12000 147676.12 163616 0 0 12.306343333333333 13.634666666666666 0 0
13000 161463.97 178616 0 0 12.420305384615384 13.739692307692307 0 0
14000 175356.22 193616 0 0 12.525444285714286 13.829714285714285 0 0
15000 189299.45 208616 0 0 12.619963333333335 13.907733333333333 0 0
16000 203295.97 223616 0 0 12.705998125 13.976 0 0
17000 217535.7 239232 0 0 12.796217647058825 14.072470588235294 0 0
18000 231946.55 255232 0 0 12.885919444444443 14.179555555555556 0 0
19000 246392.21 271232 0 0 12.968011052631578 14.275368421052631 0 0
20000 260890.62 287232 0 0 13.044531 14.3616 0 0
21000 275441.83 303232 0 0 13.11627761904762 14.439619047619047 0 0
22000 290057.1 319232 0 0 13.184413636363635 14.510545454545454 0 0
23000 304699.13 335232 0 0 13.247788260869566 14.575304347826087 0 0
24000 319341.56 351232 0 0 13.305898333333333 14.634666666666666 0 0
25000 334095.67 367232 0 0 13.3638268 14.68928 0 0
26000 348950.95 383232 0 0 13.421190384615386 14.739692307692307 0 0
27000 363828.23 399232 0 0 13.47511962962963 14.78637037037037 0 0
28000 378717.58 415232 0 0 13.525627857142858 14.829714285714285 0 0
29000 393633.61 431232 0 0 13.573572758620688 14.870068965517241 0 0
30000 408595.77 447232 0 0 13.619859 14.907733333333333 0 0
31000 423563.66 463232 0 0 13.663343870967742 14.942967741935483 0 0
32000 438575.72 479232 0 0 13.70549125 14.976 0 0
33000 453652.68 495464 0 0 13.747050909090909 15.014060606060607 0 0
34000 469084.18 512464 0 0 13.796593529411764 15.072470588235294 0 0
35000 484456.91 529464 0 0 13.841626 15.127542857142856 0 0
36000 499892.69 546464 0 0 13.885908055555555 15.179555555555556 0 0
37000 515351.91 563464 0 0 13.928429999999999 15.228756756756757 0 0
38000 530822.55 580464 0 0 13.969014473684211 15.275368421052631 0 0
39000 546301.31 597464 0 0 14.007725897435899 15.319589743589743 0 0
40000 561799.43 614464 0 0 14.044985750000002 15.3616 0 0
41000 577307.71 631464 0 0 14.080675853658535 15.401560975609756 0 0
42000 592886.26 648464 0 0 14.116339523809524 15.439619047619047 0 0
43000 608513.61 665464 0 0 14.151479302325582 15.475906976744186 0 0
44000 624144.43 682464 0 0 14.185100681818183 15.510545454545454 0 0
45000 639737 699464 0 0 14.216377777777778 15.543644444444444 0 0
46000 655359.63 716464 0 0 14.246948478260869 15.575304347826087 0 0
47000 671042.97 733464 0 0 14.27751 15.605617021276595 0 0
48000 686707.56 750464 0 0 14.3064075 15.634666666666666 0 0
49000 702373.58 767464 0 0 14.33415469387755 15.662530612244899 0 0
50000 718186.88 784464 0 0 14.3637376 15.68928 0 0

View file

@ -0,0 +1,5 @@
10 22.76 34 0 0 2.2760000000000002 3.4 0 0
20 63.65 88 0 0 3.1825 4.4 0 0
30 111.6 148 0 0 3.7199999999999998 4.933333333333334 0 0
40 165.9 216 0 0 4.1475 5.4 0 0
50 222.59 286 0 0 4.4518 5.72 0 0

178
lab2/zad3/src/main.rs Normal file
View file

@ -0,0 +1,178 @@
mod merge;
mod mergesort;
mod mysort;
use std::{collections::HashMap, env::args, fs::{self, OpenOptions}, io::{self, Write}};
use libgen::gen_rand;
use libsort::{is_sorted, print_list, SortResult};
use mergesort::mergesort;
use crate::mysort::mysort;
fn comp_avg(results_map: &HashMap<u64, Vec<SortResult>>) -> HashMap<u64, f64> {
results_map.iter()
.map(|(i, results)|
(*i, (results.iter()
.map(|res| res.comparisons)
.sum::<u64>() as f64 / results.len() as f64)))
.collect()
}
fn swap_avg(results_map: &HashMap<u64, Vec<SortResult>>) -> HashMap<u64, f64> {
results_map.iter()
.map(|(i, results)|
(*i, (results.iter()
.map(|res| res.swaps)
.sum::<u64>() as f64 / results.len() as f64)))
.collect()
}
fn sort_stdin() -> io::Result<()> {
let mut buffer = String::new();
let stdin = io::stdin();
stdin.read_line(&mut buffer)?;
let list_len = buffer.trim().parse::<u64>().expect("array length has to be u64");
buffer.clear();
let mut list: Vec<u64> = vec![];
for i in 0..list_len {
stdin.read_line(&mut buffer)?;
list.push(
buffer.trim().parse::<u64>()
.expect(format!("element {} has to be u64", i).as_str())
);
buffer.clear();
}
let input_list = list.clone();
let print = input_list.len() < 40;
if print {
print!("input: ");
print_list(&input_list);
println!();
}
let res = mysort(&mut list);
if print {
println!();
print!("input: ");
print_list(&input_list);
println!();
print!("output: ");
print_list(&list);
}
println!("swaps: {}", res.swaps);
println!("comparisons: {}", res.comparisons);
println!("is sorted: {}", is_sorted(&list));
Ok(())
}
fn main() -> io::Result<()> {
if args().len() == 1 {
return sort_stdin();
}
let k = args().nth(1)
.expect(format!("usage: {} <k>", args().nth(0).unwrap()).as_str())
.parse::<u64>()
.expect("k must be u64");
let mut merge_results_small: HashMap<u64, Vec<SortResult>> = HashMap::new();
let mut my_results_small: HashMap<u64, Vec<SortResult>> = HashMap::new();
for n in (10..=50).step_by(10) {
merge_results_small.insert(n, vec![]);
my_results_small.insert(n, vec![]);
for _ in 0..k {
let mut res = SortResult::default();
mergesort(&mut gen_rand(n), &mut res);
merge_results_small.get_mut(&n).unwrap().push(res);
my_results_small.get_mut(&n).unwrap().push(mysort(&mut gen_rand(n)));
}
}
let mut merge_results_large: HashMap<u64, Vec<SortResult>> = HashMap::new();
let mut my_results_large: HashMap<u64, Vec<SortResult>> = HashMap::new();
for n in (1000..=50000).step_by(1000) {
merge_results_large.insert(n, vec![]);
my_results_large.insert(n, vec![]);
for _ in 0..k {
let mut res = SortResult::default();
mergesort(&mut gen_rand(n), &mut res);
merge_results_large.get_mut(&n).unwrap().push(res);
my_results_large.get_mut(&n).unwrap().push(mysort(&mut gen_rand(n)));
}
}
let merge_comp_averages_small = comp_avg(&merge_results_small);
let merge_swap_averages_small = swap_avg(&merge_results_small);
let merge_comp_averages_large = comp_avg(&merge_results_large);
let merge_swap_averages_large = swap_avg(&merge_results_large);
let my_comp_averages_small = comp_avg(&my_results_small);
let my_swap_averages_small = swap_avg(&my_results_small);
let my_comp_averages_large = comp_avg(&my_results_large);
let my_swap_averages_large = swap_avg(&my_results_large);
_ = fs::create_dir_all(format!("./results/k{k}"));
_ = fs::remove_file(format!("./results/k{k}/small"));
let mut small = OpenOptions::new()
.create(true)
.append(true)
.open(format!("./results/k{k}/small"))?;
for n in (10..=50).step_by(10) {
writeln!(small, "{n} {} {} {} {} {} {} {} {}",
merge_comp_averages_small[&n],
merge_swap_averages_small[&n],
my_comp_averages_small[&n],
my_swap_averages_small[&n],
merge_comp_averages_small[&n] / n as f64,
merge_swap_averages_small[&n] / n as f64,
my_comp_averages_small[&n] / n as f64,
my_swap_averages_small[&n] / n as f64,
)?;
}
_ = fs::remove_file(format!("./results/k{k}/large"));
let mut large = OpenOptions::new()
.create(true)
.append(true)
.open(format!("./results/k{k}/large"))?;
for n in (1000..=50000).step_by(1000) {
writeln!(large, "{n} {} {} {} {} {} {} {} {}",
merge_comp_averages_large[&n],
merge_swap_averages_large[&n],
my_comp_averages_large[&n],
my_swap_averages_large[&n],
merge_comp_averages_large[&n] / n as f64,
merge_swap_averages_large[&n] / n as f64,
my_comp_averages_large[&n] / n as f64,
my_swap_averages_large[&n] / n as f64,
)?;
}
Ok(())
}

34
lab2/zad3/src/merge.rs Normal file
View file

@ -0,0 +1,34 @@
use libsort::{compare, CompareResult::*, SortResult};
pub fn merge(list1: &[u64], list2: &[u64], res: &mut SortResult) -> Vec<u64> {
let mut ret = vec![];
let mut i = 0;
let mut j = 0;
while i < list1.len() && j < list2.len() {
if compare(list1[i], list2[j], &mut res.comparisons) == LESS {
ret.push(list1[i]);
i = i + 1;
} else {
ret.push(list2[j]);
j = j + 1;
}
}
if i < list1.len() {
while i < list1.len() {
ret.push(list1[i]);
i = i + 1;
}
}
if j < list2.len() {
while j < list2.len() {
ret.push(list2[j]);
j = j + 1;
}
}
ret
}

View file

@ -0,0 +1,16 @@
use libsort::SortResult;
use crate::merge::merge;
pub fn mergesort(list: &[u64], res: &mut SortResult) -> Vec<u64> {
if list.len() > 1 {
let size = list.len() / 2;
let left = mergesort(&list[0..size], res);
let right = mergesort(&list[size..], res);
let merged = merge(&left, &right, res);
return merged;
}
list.to_vec()
}

70
lab2/zad3/src/mysort.rs Normal file
View file

@ -0,0 +1,70 @@
use libsort::{compare, CompareResult::*, SortResult};
use crate::merge::merge;
fn extend_run_left(list: &[u64], mut i: usize, res: &mut SortResult) -> usize {
while i > 0 && compare(list[i - 1], list[i], &mut res.comparisons) != GREATER {
i -= 1;
}
i
}
fn extend_run_right(list: &[u64], mut i: usize, res: &mut SortResult) -> usize {
while i < list.len() - 1 && compare(list[i], list[i + 1], &mut res.comparisons) != GREATER {
i += 1;
}
i
}
fn _mysort(list: &mut [u64], low: usize, high: usize, e: usize, s: usize) -> SortResult {
let mut res = SortResult::default();
if e == high || s == low {
return res;
}
let mid = low + (high - low) / 2;
if mid <= e {
let res1 = _mysort(list, e + 1, high, e + 1, s);
list.copy_from_slice(&merge(&list[low..=e], &list[(e + 1)..=high], &mut res));
res.comparisons += res1.comparisons;
res.swaps += res1.swaps;
} else if mid >= s {
let res1 = _mysort(list, low, s - 1, e, s - 1);
list.copy_from_slice(&merge(&list[low..=(s - 1)], &list[s..=high], &mut res));
res.comparisons += res1.comparisons;
res.swaps += res1.swaps;
} else {
let i = extend_run_left(list, low, &mut res);
let j = extend_run_right(list, high, &mut res);
if i == low && j == high {
return res;
}
if mid - i < j - mid {
let res1 = _mysort(list, low, i - 1, e, i - 1);
let res2 = _mysort(list, i, high, j, s);
list.copy_from_slice(&merge(&list[low..=(i - 1)], &list[i..=high], &mut res));
res.comparisons += res1.comparisons + res2.comparisons;
res.swaps += res1.swaps + res2.swaps;
} else {
let res1 = _mysort(list, low, j, e, i);
let res2 = _mysort(list, j + 1, high, j + 1, s);
list.copy_from_slice(&merge(&list[low..=j], &list[(j + 1)..=high], &mut res));
res.comparisons += res1.comparisons + res2.comparisons;
res.swaps += res1.swaps + res2.swaps;
}
}
res
}
pub fn mysort(list: &mut [u64]) -> SortResult {
_mysort(list, 0, list.len() - 1, 0, list.len() - 1)
}