From 057b52e3bd563dc1b3e90dca7d8ff71c18dc20ba Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Wed, 26 Oct 2022 21:19:38 +0300 Subject: [PATCH] Add labs --- LD1_2/.idea/.gitignore | 3 + LD1_2/.idea/misc.xml | 6 + LD1_2/.idea/modules.xml | 8 + LD1_2/.idea/uiDesigner.xml | 124 ++ LD1_2/LD1_2.iml | 11 + LD1_2/U24a.txt | 4 + LD1_2/U24b.txt | 9 + LD1_2/src/com/company/Main.java | 31 + LD1_2/src/models/Order.java | 44 + LD1_2/src/models/Product.java | 29 + LD1_2/src/utils/InOutUtils.java | 139 +++ LD1_2/src/utils/LinkedList.java | 89 ++ LD1_2/src/utils/List.java | 7 + LD1_2/src/utils/TaskUtils.java | 118 ++ LD1_intro/.idea/.gitignore | 3 + LD1_intro/.idea/.name | 1 + LD1_intro/.idea/description.html | 1 + LD1_intro/.idea/encodings.xml | 6 + LD1_intro/.idea/misc.xml | 9 + LD1_intro/.idea/modules.xml | 8 + LD1_intro/.idea/project-template.xml | 3 + LD1_intro/.idea/uiDesigner.xml | 124 ++ LD1_intro/LD1_intro.iml | 11 + LD1_intro/src/com/company/Main.java | 59 + LD1_intro/src/models/Student.java | 30 + LD1_intro/src/utils/Array.java | 44 + LD1_intro/src/utils/DataReader.java | 32 + LD1_intro/src/utils/LinkedList.java | 89 ++ LD1_intro/src/utils/List.java | 7 + LD1_intro/students_data.txt | 3 + Lab1b_BendriniaiSarasai/.idea/.gitignore | 3 + .../.idea/description.html | 1 + Lab1b_BendriniaiSarasai/.idea/encodings.xml | 6 + Lab1b_BendriniaiSarasai/.idea/misc.xml | 12 + Lab1b_BendriniaiSarasai/.idea/modules.xml | 8 + .../.idea/project-template.xml | 3 + Lab1b_BendriniaiSarasai/.idea/uiDesigner.xml | 124 ++ Lab1b_BendriniaiSarasai/Duomenys/ban.txt | 22 + .../Lab1b_BendriniaiSarasai.iml | 11 + Lab1b_BendriniaiSarasai/src/com/ktu/Car.java | 171 +++ .../src/com/ktu/CarList.java | 11 + .../src/com/ktu/CarMarket.java | 62 + .../src/com/ktu/ManualTest.java | 172 +++ .../src/com/ktu/Optional1.java | 38 + .../src/com/ktu/Optional2.java | 39 + .../src/com/ktu/SimpleBenchmark.java | 103 ++ .../src/util/ArrayQueue.java | 42 + .../src/util/ArrayStack.java | 35 + Lab1b_BendriniaiSarasai/src/util/Ks.java | 159 +++ .../src/util/LinkedList.java | 408 +++++++ .../src/util/LinkedListQueue.java | 29 + .../src/util/LinkedListStack.java | 29 + Lab1b_BendriniaiSarasai/src/util/List.java | 60 + .../src/util/Parsable.java | 10 + .../src/util/ParsableList.java | 103 ++ Lab1b_BendriniaiSarasai/src/util/Queue.java | 8 + Lab1b_BendriniaiSarasai/src/util/Stack.java | 8 + Lab2_AibesMedziai/.idea/.gitignore | 3 + Lab2_AibesMedziai/.idea/.name | 1 + Lab2_AibesMedziai/.idea/compiler.xml | 16 + Lab2_AibesMedziai/.idea/dbnavigator.xml | 463 +++++++ Lab2_AibesMedziai/.idea/encodings.xml | 7 + .../inspectionProfiles/Project_Default.xml | 36 + Lab2_AibesMedziai/.idea/jarRepositories.xml | 20 + Lab2_AibesMedziai/.idea/jpa-buddy.xml | 6 + .../libraries/Maven__junit_junit_4_13.xml | 13 + ...en__net_sf_jopt_simple_jopt_simple_4_6.xml | 13 + ...__org_apache_commons_commons_math3_3_2.xml | 13 + .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 + ...Maven__org_openjdk_jmh_jmh_core_1_25_2.xml | 13 + ...dk_jmh_jmh_generator_annprocess_1_25_2.xml | 13 + Lab2_AibesMedziai/.idea/misc.xml | 14 + Lab2_AibesMedziai/.idea/modules.xml | 8 + Lab2_AibesMedziai/.idea/uiDesigner.xml | 124 ++ Lab2_AibesMedziai/Lab2_AibesMedziai.iml | 24 + Lab2_AibesMedziai/data/ban.txt | 22 + Lab2_AibesMedziai/ktu.png | Bin 0 -> 10254 bytes Lab2_AibesMedziai/pom.xml | 181 +++ .../java/edu/ktu/ds/lab2/AddAllBenchmark.java | 88 ++ .../java/edu/ktu/ds/lab2/demo/Benchmark.java | 96 ++ .../main/java/edu/ktu/ds/lab2/demo/Car.java | 227 ++++ .../java/edu/ktu/ds/lab2/demo/CarMarket.java | 29 + .../edu/ktu/ds/lab2/demo/CarsGenerator.java | 80 ++ .../edu/ktu/ds/lab2/demo/DemoExecution.java | 13 + .../java/edu/ktu/ds/lab2/demo/ManualTest.java | 150 +++ .../main/java/edu/ktu/ds/lab2/gui/KsGui.java | 67 + .../java/edu/ktu/ds/lab2/gui/MainWindow.java | 445 +++++++ .../edu/ktu/ds/lab2/gui/MainWindowMenu.java | 56 + .../main/java/edu/ktu/ds/lab2/gui/Panels.java | 148 +++ .../ktu/ds/lab2/gui/ValidationException.java | 41 + .../java/edu/ktu/ds/lab2/optional1/Main.java | 41 + .../java/edu/ktu/ds/lab2/optional2/Main.java | 86 ++ .../java/edu/ktu/ds/lab2/utils/AvlSet.java | 236 ++++ .../java/edu/ktu/ds/lab2/utils/BstSet.java | 501 ++++++++ .../ktu/ds/lab2/utils/BstSetIterative.java | 118 ++ .../main/java/edu/ktu/ds/lab2/utils/Ks.java | 174 +++ .../java/edu/ktu/ds/lab2/utils/Parsable.java | 16 + .../edu/ktu/ds/lab2/utils/ParsableAvlSet.java | 77 ++ .../edu/ktu/ds/lab2/utils/ParsableBstSet.java | 78 ++ .../ktu/ds/lab2/utils/ParsableSortedSet.java | 10 + .../main/java/edu/ktu/ds/lab2/utils/Set.java | 42 + .../java/edu/ktu/ds/lab2/utils/SortedSet.java | 38 + .../edu/ktu/ds/lab2/gui/messages.properties | 59 + .../edu/ktu/ds/lab2/demo/AvlSetTests.java | 111 ++ .../ds/lab2/demo/BstSetIterativeTests.java | 13 + .../edu/ktu/ds/lab2/demo/BstSetTests.java | 23 + .../java/edu/ktu/ds/lab2/demo/SetTests.java | 164 +++ .../edu/ktu/ds/lab2/demo/SortedSetTests.java | 38 + .../target/classes/META-INF/BenchmarkList | 4 + .../target/classes/META-INF/CompilerHints | 12 + .../edu/ktu/ds/lab2/gui/messages.properties | 59 + .../Benchmark_FullSet_jmhType.java | 4 + .../Benchmark_FullSet_jmhType_B1.java | 20 + .../Benchmark_FullSet_jmhType_B2.java | 22 + .../Benchmark_FullSet_jmhType_B3.java | 20 + .../Benchmark_addAvlRecursive_jmhTest.java | 514 ++++++++ .../Benchmark_addBstIterative_jmhTest.java | 514 ++++++++ .../Benchmark_addBstRecursive_jmhTest.java | 514 ++++++++ .../demo/jmh_generated/Benchmark_jmhType.java | 4 + .../jmh_generated/Benchmark_jmhType_B1.java | 20 + .../jmh_generated/Benchmark_jmhType_B2.java | 22 + .../jmh_generated/Benchmark_jmhType_B3.java | 20 + .../Benchmark_removeBst_jmhTest.java | 1082 +++++++++++++++++ .../AddAllBenchmark_avlSetAddAll_jmhTest.java | 599 +++++++++ .../AddAllBenchmark_bstSetAddAll_jmhTest.java | 599 +++++++++ .../AddAllBenchmark_jmhType.java | 4 + .../AddAllBenchmark_jmhType_B1.java | 20 + .../AddAllBenchmark_jmhType_B2.java | 22 + .../AddAllBenchmark_jmhType_B3.java | 20 + .../test-classes/META-INF/BenchmarkList | 2 + .../test-classes/META-INF/CompilerHints | 9 + 131 files changed, 11103 insertions(+) create mode 100644 LD1_2/.idea/.gitignore create mode 100644 LD1_2/.idea/misc.xml create mode 100644 LD1_2/.idea/modules.xml create mode 100644 LD1_2/.idea/uiDesigner.xml create mode 100644 LD1_2/LD1_2.iml create mode 100644 LD1_2/U24a.txt create mode 100644 LD1_2/U24b.txt create mode 100644 LD1_2/src/com/company/Main.java create mode 100644 LD1_2/src/models/Order.java create mode 100644 LD1_2/src/models/Product.java create mode 100644 LD1_2/src/utils/InOutUtils.java create mode 100644 LD1_2/src/utils/LinkedList.java create mode 100644 LD1_2/src/utils/List.java create mode 100644 LD1_2/src/utils/TaskUtils.java create mode 100644 LD1_intro/.idea/.gitignore create mode 100644 LD1_intro/.idea/.name create mode 100644 LD1_intro/.idea/description.html create mode 100644 LD1_intro/.idea/encodings.xml create mode 100644 LD1_intro/.idea/misc.xml create mode 100644 LD1_intro/.idea/modules.xml create mode 100644 LD1_intro/.idea/project-template.xml create mode 100644 LD1_intro/.idea/uiDesigner.xml create mode 100644 LD1_intro/LD1_intro.iml create mode 100644 LD1_intro/src/com/company/Main.java create mode 100644 LD1_intro/src/models/Student.java create mode 100644 LD1_intro/src/utils/Array.java create mode 100644 LD1_intro/src/utils/DataReader.java create mode 100644 LD1_intro/src/utils/LinkedList.java create mode 100644 LD1_intro/src/utils/List.java create mode 100644 LD1_intro/students_data.txt create mode 100644 Lab1b_BendriniaiSarasai/.idea/.gitignore create mode 100644 Lab1b_BendriniaiSarasai/.idea/description.html create mode 100644 Lab1b_BendriniaiSarasai/.idea/encodings.xml create mode 100644 Lab1b_BendriniaiSarasai/.idea/misc.xml create mode 100644 Lab1b_BendriniaiSarasai/.idea/modules.xml create mode 100644 Lab1b_BendriniaiSarasai/.idea/project-template.xml create mode 100644 Lab1b_BendriniaiSarasai/.idea/uiDesigner.xml create mode 100644 Lab1b_BendriniaiSarasai/Duomenys/ban.txt create mode 100644 Lab1b_BendriniaiSarasai/Lab1b_BendriniaiSarasai.iml create mode 100644 Lab1b_BendriniaiSarasai/src/com/ktu/Car.java create mode 100644 Lab1b_BendriniaiSarasai/src/com/ktu/CarList.java create mode 100644 Lab1b_BendriniaiSarasai/src/com/ktu/CarMarket.java create mode 100644 Lab1b_BendriniaiSarasai/src/com/ktu/ManualTest.java create mode 100644 Lab1b_BendriniaiSarasai/src/com/ktu/Optional1.java create mode 100644 Lab1b_BendriniaiSarasai/src/com/ktu/Optional2.java create mode 100644 Lab1b_BendriniaiSarasai/src/com/ktu/SimpleBenchmark.java create mode 100644 Lab1b_BendriniaiSarasai/src/util/ArrayQueue.java create mode 100644 Lab1b_BendriniaiSarasai/src/util/ArrayStack.java create mode 100644 Lab1b_BendriniaiSarasai/src/util/Ks.java create mode 100644 Lab1b_BendriniaiSarasai/src/util/LinkedList.java create mode 100644 Lab1b_BendriniaiSarasai/src/util/LinkedListQueue.java create mode 100644 Lab1b_BendriniaiSarasai/src/util/LinkedListStack.java create mode 100644 Lab1b_BendriniaiSarasai/src/util/List.java create mode 100644 Lab1b_BendriniaiSarasai/src/util/Parsable.java create mode 100644 Lab1b_BendriniaiSarasai/src/util/ParsableList.java create mode 100644 Lab1b_BendriniaiSarasai/src/util/Queue.java create mode 100644 Lab1b_BendriniaiSarasai/src/util/Stack.java create mode 100644 Lab2_AibesMedziai/.idea/.gitignore create mode 100644 Lab2_AibesMedziai/.idea/.name create mode 100644 Lab2_AibesMedziai/.idea/compiler.xml create mode 100644 Lab2_AibesMedziai/.idea/dbnavigator.xml create mode 100644 Lab2_AibesMedziai/.idea/encodings.xml create mode 100644 Lab2_AibesMedziai/.idea/inspectionProfiles/Project_Default.xml create mode 100644 Lab2_AibesMedziai/.idea/jarRepositories.xml create mode 100644 Lab2_AibesMedziai/.idea/jpa-buddy.xml create mode 100644 Lab2_AibesMedziai/.idea/libraries/Maven__junit_junit_4_13.xml create mode 100644 Lab2_AibesMedziai/.idea/libraries/Maven__net_sf_jopt_simple_jopt_simple_4_6.xml create mode 100644 Lab2_AibesMedziai/.idea/libraries/Maven__org_apache_commons_commons_math3_3_2.xml create mode 100644 Lab2_AibesMedziai/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml create mode 100644 Lab2_AibesMedziai/.idea/libraries/Maven__org_openjdk_jmh_jmh_core_1_25_2.xml create mode 100644 Lab2_AibesMedziai/.idea/libraries/Maven__org_openjdk_jmh_jmh_generator_annprocess_1_25_2.xml create mode 100644 Lab2_AibesMedziai/.idea/misc.xml create mode 100644 Lab2_AibesMedziai/.idea/modules.xml create mode 100644 Lab2_AibesMedziai/.idea/uiDesigner.xml create mode 100644 Lab2_AibesMedziai/Lab2_AibesMedziai.iml create mode 100644 Lab2_AibesMedziai/data/ban.txt create mode 100644 Lab2_AibesMedziai/ktu.png create mode 100644 Lab2_AibesMedziai/pom.xml create mode 100644 Lab2_AibesMedziai/src/benchmark/java/edu/ktu/ds/lab2/AddAllBenchmark.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/Benchmark.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/Car.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/CarMarket.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/CarsGenerator.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/DemoExecution.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/ManualTest.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/KsGui.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/MainWindow.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/MainWindowMenu.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/Panels.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/ValidationException.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/optional1/Main.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/optional2/Main.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/AvlSet.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/BstSet.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/BstSetIterative.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/Ks.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/Parsable.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/ParsableAvlSet.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/ParsableBstSet.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/ParsableSortedSet.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/Set.java create mode 100644 Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/SortedSet.java create mode 100644 Lab2_AibesMedziai/src/main/resources/edu/ktu/ds/lab2/gui/messages.properties create mode 100644 Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/AvlSetTests.java create mode 100644 Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/BstSetIterativeTests.java create mode 100644 Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/BstSetTests.java create mode 100644 Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/SetTests.java create mode 100644 Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/SortedSetTests.java create mode 100644 Lab2_AibesMedziai/target/classes/META-INF/BenchmarkList create mode 100644 Lab2_AibesMedziai/target/classes/META-INF/CompilerHints create mode 100644 Lab2_AibesMedziai/target/classes/edu/ktu/ds/lab2/gui/messages.properties create mode 100644 Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_FullSet_jmhType.java create mode 100644 Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_FullSet_jmhType_B1.java create mode 100644 Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_FullSet_jmhType_B2.java create mode 100644 Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_FullSet_jmhType_B3.java create mode 100644 Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_addAvlRecursive_jmhTest.java create mode 100644 Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_addBstIterative_jmhTest.java create mode 100644 Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_addBstRecursive_jmhTest.java create mode 100644 Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_jmhType.java create mode 100644 Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_jmhType_B1.java create mode 100644 Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_jmhType_B2.java create mode 100644 Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_jmhType_B3.java create mode 100644 Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_removeBst_jmhTest.java create mode 100644 Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_avlSetAddAll_jmhTest.java create mode 100644 Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_bstSetAddAll_jmhTest.java create mode 100644 Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_jmhType.java create mode 100644 Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_jmhType_B1.java create mode 100644 Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_jmhType_B2.java create mode 100644 Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_jmhType_B3.java create mode 100644 Lab2_AibesMedziai/target/test-classes/META-INF/BenchmarkList create mode 100644 Lab2_AibesMedziai/target/test-classes/META-INF/CompilerHints diff --git a/LD1_2/.idea/.gitignore b/LD1_2/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/LD1_2/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/LD1_2/.idea/misc.xml b/LD1_2/.idea/misc.xml new file mode 100644 index 0000000..34c2ea5 --- /dev/null +++ b/LD1_2/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/LD1_2/.idea/modules.xml b/LD1_2/.idea/modules.xml new file mode 100644 index 0000000..aef2b3a --- /dev/null +++ b/LD1_2/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/LD1_2/.idea/uiDesigner.xml b/LD1_2/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/LD1_2/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LD1_2/LD1_2.iml b/LD1_2/LD1_2.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/LD1_2/LD1_2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/LD1_2/U24a.txt b/LD1_2/U24a.txt new file mode 100644 index 0000000..084097c --- /dev/null +++ b/LD1_2/U24a.txt @@ -0,0 +1,4 @@ +0, Atsuktuvas, 0.99 +1, Varztas, 0.05 +2, Laidas, 2.00 +3, Plaktukas, 2.99 \ No newline at end of file diff --git a/LD1_2/U24b.txt b/LD1_2/U24b.txt new file mode 100644 index 0000000..8defdf5 --- /dev/null +++ b/LD1_2/U24b.txt @@ -0,0 +1,9 @@ +Petraitis, Petras, 0, 10 +Jonaitis, Jonas, 1, 20 +Jonaitis, Jonas, 1, 20 +Jonaitis, Jonas, 1, 20 +Onaite, Ona, 2, 200 +Jonaitis, Brolis, 1, 100 +Jonaitis, Jonas, 1, 20 +Jonaitis, Jonas, 1, 20 +Onaite, Ona, 0, 20 \ No newline at end of file diff --git a/LD1_2/src/com/company/Main.java b/LD1_2/src/com/company/Main.java new file mode 100644 index 0000000..579262b --- /dev/null +++ b/LD1_2/src/com/company/Main.java @@ -0,0 +1,31 @@ +package com.company; + +import models.Order; +import models.Product; +import utils.InOutUtils; +import utils.LinkedList; +import utils.TaskUtils; + +public class Main { + public static void main(String[] args) { + LinkedList orders = new LinkedList(); + LinkedList products = new LinkedList(); + + InOutUtils.readProducts("U24a.txt", products); + InOutUtils.readOrders("U24b.txt", orders); + + int n = 1000; + float k = 10.0f; + + var mostPopularProductIds = TaskUtils.FindMostPopularProducts(orders); + var mostPopularProducts = TaskUtils.FindByID(products, mostPopularProductIds); + var filteredProducts = TaskUtils.FilterByQuantitySoldAndPrice(products, orders, n, k); + var customersWithSingleProduct = TaskUtils.FindCustomerWithSingleProduct(orders); + + InOutUtils.printProducts(products, "Įtaisai"); + InOutUtils.printOrders(orders, "Pirkėjai"); + InOutUtils.printMostPopularProducts(orders, mostPopularProducts, "Populiariausi įtaisai"); + InOutUtils.printOrdersWithPrices(customersWithSingleProduct, products, "Vienos rūšies pirkėjai"); + InOutUtils.printProducts(filteredProducts, String.format("Atrinkti įtaisai (n=%d, k=%.2f)", n, k)); + } +} diff --git a/LD1_2/src/models/Order.java b/LD1_2/src/models/Order.java new file mode 100644 index 0000000..e56d959 --- /dev/null +++ b/LD1_2/src/models/Order.java @@ -0,0 +1,44 @@ +package models; + +public class Order implements Comparable { + public String customerSurname; + public String customerName; + public String productID; + public int productAmount; + + public Order(String customerSurname, String customerName, String productID, int productAmount) { + this.customerSurname = customerSurname; + this.customerName = customerName; + this.productID = productID; + this.productAmount = productAmount; + } + + + @Override + public int compareTo(Order o) { + if (productAmount > o.productAmount) { + return 1; + } else if (productAmount == o.productAmount) { + int surnameCompare = customerSurname.compareTo(o.customerSurname); + if (surnameCompare < 0) { + return 1; + } else if (surnameCompare == 0 && customerName.compareTo(o.customerName) < 0) { + return 1; + } + } + + return equals(o) ? 0 : -1; + } + + @Override + public boolean equals(Object o) { + if (o == null || !(o instanceof Order)) + return false; + + Order order = (Order)o; + return customerName.equals(order.customerName) && + customerSurname.equals(order.customerSurname) && + productAmount == order.productAmount && + productID.equals(order.productID); + } +} diff --git a/LD1_2/src/models/Product.java b/LD1_2/src/models/Product.java new file mode 100644 index 0000000..c790e6c --- /dev/null +++ b/LD1_2/src/models/Product.java @@ -0,0 +1,29 @@ +package models; + +public class Product implements Comparable { + public String ID; + public String name; + public float price; + + public Product(String ID, String name, float price) { + this.ID = ID; + this.name = name; + this.price = price; + } + + @Override + public boolean equals(Object o) { + if (o == null || !(o instanceof Product)) + return false; + + Product product = (Product)o; + return ID.equals(product.ID) && + name.equals(product.name) && + price == product.price; + } + + @Override + public int compareTo(Product o) { + return ID.compareTo(o.ID); + } +} diff --git a/LD1_2/src/utils/InOutUtils.java b/LD1_2/src/utils/InOutUtils.java new file mode 100644 index 0000000..0e05b7b --- /dev/null +++ b/LD1_2/src/utils/InOutUtils.java @@ -0,0 +1,139 @@ +package utils; + +import models.Order; +import models.Product; + +import java.io.FileInputStream; +import java.nio.charset.StandardCharsets; +import java.util.Scanner; + +public class InOutUtils { + public static void readOrders(String filePath, List outputData) { + FileInputStream fileStream = null; + Scanner scanner = null; + + try { + fileStream = new FileInputStream(filePath); + scanner = new Scanner(fileStream, StandardCharsets.UTF_8); + while (scanner.hasNextLine()) { + String[] lines = scanner.nextLine().split(","); + String customerSurname = lines[0].trim(); + String customerName = lines[1].trim(); + String productID = lines[2].trim(); + int productAmount = Integer.parseInt(lines[3].trim()); + outputData.add(new Order(customerSurname, customerName, productID, productAmount)); + } + fileStream.close(); + } + catch (Exception e){ + e.printStackTrace(); + } + finally { + if (scanner != null) { + scanner.close(); + } + } + } + + public static void readProducts(String filePath, List outputData) { + FileInputStream fileStream = null; + Scanner scanner = null; + + try { + fileStream = new FileInputStream(filePath); + scanner = new Scanner(fileStream, StandardCharsets.UTF_8); + while (scanner.hasNextLine()) { + String[] lines = scanner.nextLine().split(","); + String ID = lines[0].trim(); + String name = lines[1].trim(); + float price = Float.parseFloat(lines[2].trim()); + outputData.add(new Product(ID, name, price)); + } + fileStream.close(); + } + catch (Exception e){ + e.printStackTrace(); + } + finally { + if (scanner != null) { + scanner.close(); + } + } + } + + public static void printOrders(LinkedList orders, String header) + { + if (orders.get(0) == null) { + System.out.println("Tuščia"); + return; + } + + System.out.println("-".repeat(49)); + System.out.printf("| %-45s |%n", header); + System.out.println("-".repeat(49)); + System.out.printf("| %-10s | %-6s | %7s | %13s |%n", "Pavardė", "Vardas", "Įtaisas", "Įtaiso kiekis"); + System.out.println("-".repeat(49)); + for (Order e : orders) { + System.out.printf("| %-10s | %-6s | %7s | %13d |%n", e.customerSurname, e.customerName, e.productID, e.productAmount); + } + System.out.println("-".repeat(49)); + } + + public static void printProducts(LinkedList products, String header) + { + if (products.get(0) == null) { + System.out.println("Tuščia"); + return; + } + + System.out.println("-".repeat(35)); + System.out.printf("| %-31s |%n", header); + System.out.println("-".repeat(35)); + System.out.printf("| %-2s | %-18s | %5s |%n", "ID", "Vardas", "Kaina"); + System.out.println("-".repeat(35)); + for (Product e : products) + { + System.out.printf("| %-2s | %-18s | %5.2f |%n", e.ID, e.name, e.price); + } + System.out.println("-".repeat(35)); + } + + public static void printOrdersWithPrices(LinkedList orders, LinkedList products, String header) + { + if (orders.get(0) == null) { + System.out.println("Tuščia"); + return; + } + + System.out.println("-".repeat(53)); + System.out.printf("| %-49s |%n", header); + System.out.println("-".repeat(53)); + System.out.printf("| %-10s | %-6s | %13s | %11s |%n", "Pavardė", "Vardas", "Įtaiso kiekis", "Kaina, eur."); + System.out.println("-".repeat(53)); + for (Order order : orders) { + Product product = TaskUtils.FindByID(products, order.productID); + System.out.printf("| %-10s | %-6s | %13s | %11.2f |%n", order.customerSurname, order.customerName, order.productAmount, order.productAmount * product.price); + } + System.out.println("-".repeat(53)); + } + + public static void printMostPopularProducts(LinkedList orders, LinkedList products, String header) + { + if (products.get(0) == null) { + System.out.println("Tuščia"); + return; + } + + System.out.println("-".repeat(62)); + System.out.printf("| %-58s |%n", header); + System.out.println("-".repeat(62)); + System.out.printf("| %-2s | %-10s | %19s | %18s |%n", "ID", "Vardas", "Įtaisų kiekis, vnt.", "Įtaisų kaina, eur."); + System.out.println("-".repeat(62)); + for (Product e : products) + { + int sales = TaskUtils.CountProductSales(orders, e.ID); + System.out.printf("| %-2s | %-10s | %19d | %18.2f |%n", e.ID, e.name, sales, sales * e.price); + } + System.out.println("-".repeat(62)); + } +} diff --git a/LD1_2/src/utils/LinkedList.java b/LD1_2/src/utils/LinkedList.java new file mode 100644 index 0000000..6902deb --- /dev/null +++ b/LD1_2/src/utils/LinkedList.java @@ -0,0 +1,89 @@ +package utils; + +import java.util.Iterator; + +/* +Realizuokite visus interfeiso metodus susietojo sarašo pagrindu. +Nesinaudokite java klase LinkedList, visa logika meginkite parasyti patys. +Jeigu reikia, galima kurti papildomus metodus ir kintamuosius. +*/ +public class LinkedList implements List { + + private class Node { + public T value; + public Node next; + + public Node(T value, Node next) { + this.value = value; + this.next = next; + } + + public Node(T value) { + this.value = value; + } + } + + Node head, tail; + + @Override + public void add(T item) { + if (head == null) { + this.head = new Node(item); + this.tail = this.head; + } else { + Node d = new Node(item); + this.tail.next = d; + this.tail = d; + } + } + + @Override + public T get(int index) { + Node current = this.head; + for (int i = 0; i < index && current != null; i++) { + current = current.next; + } + return current != null ? current.value : null; + } + + @Override + public boolean remove(T item) { + Node prev = null; + Node current = this.head; + while (current != null) { + if (current.value.equals(item)) { + if (current.next == null) { + this.tail = prev; + prev.next = null; + } else if (prev == null) { + this.head = current.next; + } else { + prev.next = current.next; + } + return true; + } + prev = current; + current = current.next; + } + return false; + } + + @Override + public Iterator iterator() { + return new Iterator() { + public Node current = head; + + @Override + public boolean hasNext() { + return current != null; + } + + @Override + public T next() { + T value = current.value; + current = current.next; + return value; + } + }; + } +} diff --git a/LD1_2/src/utils/List.java b/LD1_2/src/utils/List.java new file mode 100644 index 0000000..2ebd401 --- /dev/null +++ b/LD1_2/src/utils/List.java @@ -0,0 +1,7 @@ +package utils; + +public interface List extends Iterable{ + public void add(T item); // add item to the end + public T get(int index); // get element by its place in list + public boolean remove(T item); // remove item, if item removed return true, else return false +} diff --git a/LD1_2/src/utils/TaskUtils.java b/LD1_2/src/utils/TaskUtils.java new file mode 100644 index 0000000..d201d6c --- /dev/null +++ b/LD1_2/src/utils/TaskUtils.java @@ -0,0 +1,118 @@ +package utils; + +import models.Order; +import models.Product; +import java.util.HashMap; + +public class TaskUtils { + + public static LinkedList FindMostPopularProducts(Iterable orders) { + HashMap productSales = new HashMap(); + for (Order order : orders) { + if (!productSales.containsKey(order.productID)) { + productSales.put(order.productID, order.productAmount); + } else { + productSales.replace(order.productID, productSales.get(order.productID) + order.productAmount); + } + } + + LinkedList mostPopularProducts = new LinkedList(); + int mostPopularCount = 0; + for (String product : productSales.keySet()) { + int count = productSales.get(product); + if (count > mostPopularCount) { + mostPopularCount = count; + mostPopularProducts = new LinkedList(); + mostPopularProducts.add(product); + } else if (count == mostPopularCount) { + mostPopularProducts.add(product); + } + } + + return mostPopularProducts; + } + + public static int CountProductSales(Iterable orders, String product) { + int sales = 0; + for (Order order : orders) { + if (order.productID.equals(product)) { + sales += order.productAmount; + } + } + return sales; + } + + public static Product FindByID(Iterable products, String id) { + for (Product product : products) { + if (product.ID.equals(id)) { + return product; + } + } + return null; + } + + public static LinkedList FindByID(Iterable products, Iterable ids) { + LinkedList foundProducts = new LinkedList(); + for (String id : ids) { + foundProducts.add(FindByID(products, id)); + } + return foundProducts; + } + + public static LinkedList FilterByQuantitySoldAndPrice(Iterable products, Iterable orders, int minSold, float maxPrice) { + LinkedList filtered = new LinkedList(); + for (Product product : products) { + if (product.price < maxPrice) { + int sold = CountProductSales(orders, product.ID); + if (sold >= minSold) { + filtered.add(product); + } + } + } + return filtered; + } + + public static LinkedList MergeOrders(Iterable orders) + { + HashMap ordersByName = new HashMap<>(); + for (Order order : orders) + { + var key = order.customerSurname + order.customerName + order.productID; + if (ordersByName.containsKey(key)) + { + ordersByName.get(key).productAmount += order.productAmount; + } else + { + ordersByName.put(key, new Order(order.customerSurname, order.customerName, order.productID, order.productAmount)); + } + } + + LinkedList mergedOrders = new LinkedList(); + for (Order order : ordersByName.values()) + { + mergedOrders.add(order); + } + return mergedOrders; + } + + public static LinkedList FindCustomerWithSingleProduct(Iterable orders) { + HashMap> ordersByCustomer = new HashMap<>(); + for (Order order : MergeOrders(orders)) { + var key = order.customerName + order.customerSurname; + if (!ordersByCustomer.containsKey(key)) { + ordersByCustomer.put(key, new LinkedList<>()); + } + ordersByCustomer.get(key).add(order); + } + + LinkedList finalList = new LinkedList(); + for (LinkedList customerOrders : ordersByCustomer.values()) + { + if (customerOrders.get(1) == null) + { + finalList.add(customerOrders.get(0)); + } + } + return finalList; + } +} diff --git a/LD1_intro/.idea/.gitignore b/LD1_intro/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/LD1_intro/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/LD1_intro/.idea/.name b/LD1_intro/.idea/.name new file mode 100644 index 0000000..e5d7579 --- /dev/null +++ b/LD1_intro/.idea/.name @@ -0,0 +1 @@ +LD1_intro.iml \ No newline at end of file diff --git a/LD1_intro/.idea/description.html b/LD1_intro/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/LD1_intro/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/LD1_intro/.idea/encodings.xml b/LD1_intro/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/LD1_intro/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/LD1_intro/.idea/misc.xml b/LD1_intro/.idea/misc.xml new file mode 100644 index 0000000..c9971e0 --- /dev/null +++ b/LD1_intro/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/LD1_intro/.idea/modules.xml b/LD1_intro/.idea/modules.xml new file mode 100644 index 0000000..6c750f3 --- /dev/null +++ b/LD1_intro/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/LD1_intro/.idea/project-template.xml b/LD1_intro/.idea/project-template.xml new file mode 100644 index 0000000..1f08b88 --- /dev/null +++ b/LD1_intro/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/LD1_intro/.idea/uiDesigner.xml b/LD1_intro/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/LD1_intro/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LD1_intro/LD1_intro.iml b/LD1_intro/LD1_intro.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/LD1_intro/LD1_intro.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/LD1_intro/src/com/company/Main.java b/LD1_intro/src/com/company/Main.java new file mode 100644 index 0000000..1ceeda5 --- /dev/null +++ b/LD1_intro/src/com/company/Main.java @@ -0,0 +1,59 @@ +package com.company; +import models.Student; +import utils.*; + +public class Main { + + public static void main(String[] args) { + String filePath = "students_data.txt"; + + Array students_arr = new Array(); + + DataReader.readFromFile(filePath, students_arr); + + System.out.println("============Tests with array implementation============"); + performTests(students_arr); + + LinkedList students_llist = new LinkedList(); + +// Realizavus LinkedList klase ir atkomentavus turetume gauti tokius +// pacius rezultatus kaip ir klases Array atveju + DataReader.readFromFile(filePath, students_llist); + + System.out.println("============Tests with linked list implementation============"); + performTests(students_llist); + } + + private static void performTests(List students) { + System.out.println("Initial students list:"); + + for(Student student : students){ + System.out.println(student); + } + + System.out.println(students.remove(new Student("Tomas", "Tomaitis", 22, "IF-7/1"))); + System.out.println(students.remove(new Student("Jonas", "Jonaitis", 19, "IFF-9/3"))); + System.out.println(students.remove(new Student("Vardenis", "Pavardenis", 99, "XX-XX"))); + + System.out.println("\nAfter removal:"); + + for(Student student : students){ + System.out.println(student); + } + + students.add(new Student("Ona", "Onaite", 20,"IFF-8/1")); + + System.out.println("\nAfter addition at the end and insertion at the start:"); + + for(Student student : students){ + System.out.println(student); + } + + System.out.println("\nTesting get() method:"); + + for(int i = 0; i < 2; i++){ + System.out.println(students.get(i)); + } + + } +} diff --git a/LD1_intro/src/models/Student.java b/LD1_intro/src/models/Student.java new file mode 100644 index 0000000..c5035ac --- /dev/null +++ b/LD1_intro/src/models/Student.java @@ -0,0 +1,30 @@ +package models; + +public class Student { + String firstName; + String lastName; + int age; + String group; + + public Student(){} + + public Student(String firstName, String lastName, int age, String group){ + this.firstName = firstName; + this.lastName = lastName; + this.age = age; + this.group = group; + } + + @Override + public String toString(){ + return String.format("%s %s age: %d group: %s", firstName, lastName, age, group); + } + + @Override + public boolean equals(Object student) { + if (student == null) + return false; + + return ((Student) student).firstName.equals(this.firstName) && ((Student) student).lastName.equals(this.lastName); + } +} diff --git a/LD1_intro/src/utils/Array.java b/LD1_intro/src/utils/Array.java new file mode 100644 index 0000000..8bb3797 --- /dev/null +++ b/LD1_intro/src/utils/Array.java @@ -0,0 +1,44 @@ +package utils; +import java.util.ArrayList; +import java.util.Iterator; + +public class Array implements List { + + public ArrayList array; + + public Array(){ + array = new ArrayList(); + } + + @Override + public void add(T item) { + array.add(item); + } + + @Override + public T get(int index) { + return array.get(index); + } + + @Override + public boolean remove(T item) { + return array.remove(item); + } + + @Override + public Iterator iterator() { + return new Iterator() { + int currentIndex = 0; + + @Override + public boolean hasNext() { + return currentIndex < array.size() && array.get(currentIndex) != null; + } + + @Override + public T next() { + return array.get(currentIndex++); + } + }; + } +} diff --git a/LD1_intro/src/utils/DataReader.java b/LD1_intro/src/utils/DataReader.java new file mode 100644 index 0000000..c15ceeb --- /dev/null +++ b/LD1_intro/src/utils/DataReader.java @@ -0,0 +1,32 @@ +package utils; + +import models.Student; + +import java.io.FileInputStream; +import java.util.Scanner; + +public class DataReader { + + public static void readFromFile(String filePath, List outputData) { + FileInputStream fileStream = null; + Scanner scanner = null; + + try { + fileStream = new FileInputStream(filePath); + scanner = new Scanner(fileStream, "UTF-8"); + while (scanner.hasNextLine()) { + String[] lines = scanner.nextLine().split(";"); + outputData.add(new Student(lines[0], lines[1], Integer.parseInt(lines[2]), lines[3])); + } + fileStream.close(); + } + catch (Exception e){ + e.printStackTrace(); + } + finally { + if (scanner != null) { + scanner.close(); + } + } + } +} diff --git a/LD1_intro/src/utils/LinkedList.java b/LD1_intro/src/utils/LinkedList.java new file mode 100644 index 0000000..ec35d52 --- /dev/null +++ b/LD1_intro/src/utils/LinkedList.java @@ -0,0 +1,89 @@ +package utils; + +import java.util.Iterator; + +/* +Realizuokite visus interfeiso metodus susietojo sarašo pagrindu. +Nesinaudokite java klase LinkedList, visa logika meginkite parasyti patys. +Jeigu reikia, galima kurti papildomus metodus ir kintamuosius. +*/ +public class LinkedList implements List { + + private class Node { + public T value; + public Node next; + + public Node(T value, Node next) { + this.value = value; + this.next = next; + } + + public Node(T value) { + this.value = value; + } + } + + Node head, tail; + + @Override + public void add(T item) { + if (head == null) { + this.head = new Node(item); + this.tail = this.head; + } else { + Node d = new Node(item); + this.tail.next = d; + this.tail = d; + } + } + + @Override + public T get(int index) { + Node current = this.head; + for (int i = 0; i < index; i++) { + current = current.next; + } + return current.value; + } + + @Override + public boolean remove(T item) { + Node prev = null; + Node current = this.head; + while (current != null) { + if (current.value.equals(item)) { + if (current.next == null) { + this.tail = prev; + prev.next = null; + } else if (prev == null) { + this.head = current.next; + } else { + prev.next = current.next; + } + return true; + } + prev = current; + current = current.next; + } + return false; + } + + @Override + public Iterator iterator() { + return new Iterator() { + public Node current = head; + + @Override + public boolean hasNext() { + return current != null; + } + + @Override + public T next() { + T value = current.value; + current = current.next; + return value; + } + }; + } +} diff --git a/LD1_intro/src/utils/List.java b/LD1_intro/src/utils/List.java new file mode 100644 index 0000000..2ebd401 --- /dev/null +++ b/LD1_intro/src/utils/List.java @@ -0,0 +1,7 @@ +package utils; + +public interface List extends Iterable{ + public void add(T item); // add item to the end + public T get(int index); // get element by its place in list + public boolean remove(T item); // remove item, if item removed return true, else return false +} diff --git a/LD1_intro/students_data.txt b/LD1_intro/students_data.txt new file mode 100644 index 0000000..d4e02b5 --- /dev/null +++ b/LD1_intro/students_data.txt @@ -0,0 +1,3 @@ +Tomas;Tomaitis;19;IFF-9/1 +Giedrius;Giedraitis;18;IFF-9/1 +Jonas;Jonaitis;20;IFF-8/3 \ No newline at end of file diff --git a/Lab1b_BendriniaiSarasai/.idea/.gitignore b/Lab1b_BendriniaiSarasai/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Lab1b_BendriniaiSarasai/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Lab1b_BendriniaiSarasai/.idea/description.html b/Lab1b_BendriniaiSarasai/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/Lab1b_BendriniaiSarasai/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/Lab1b_BendriniaiSarasai/.idea/encodings.xml b/Lab1b_BendriniaiSarasai/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/Lab1b_BendriniaiSarasai/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Lab1b_BendriniaiSarasai/.idea/misc.xml b/Lab1b_BendriniaiSarasai/.idea/misc.xml new file mode 100644 index 0000000..2fc6c34 --- /dev/null +++ b/Lab1b_BendriniaiSarasai/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Lab1b_BendriniaiSarasai/.idea/modules.xml b/Lab1b_BendriniaiSarasai/.idea/modules.xml new file mode 100644 index 0000000..67313dc --- /dev/null +++ b/Lab1b_BendriniaiSarasai/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Lab1b_BendriniaiSarasai/.idea/project-template.xml b/Lab1b_BendriniaiSarasai/.idea/project-template.xml new file mode 100644 index 0000000..1f08b88 --- /dev/null +++ b/Lab1b_BendriniaiSarasai/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/Lab1b_BendriniaiSarasai/.idea/uiDesigner.xml b/Lab1b_BendriniaiSarasai/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/Lab1b_BendriniaiSarasai/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lab1b_BendriniaiSarasai/Duomenys/ban.txt b/Lab1b_BendriniaiSarasai/Duomenys/ban.txt new file mode 100644 index 0000000..f23258e --- /dev/null +++ b/Lab1b_BendriniaiSarasai/Duomenys/ban.txt @@ -0,0 +1,22 @@ +Renault Laguna 1997 50000 1700.0 +Renault Megane 2001 20000 3500.0 +Toyota Corolla 2001 20000 8500.8 +Renault Laguna 2001 115900 7500.0 +Renault Megane 1946 365100 9500.0 +Honda Civic 2007 36400 8500.3 +Ford Focus 2009 40000 36000.0 +Ford Focus 2008 50000 34000.0 +Ford Focus 2007 60000 32000.0 +Ford Focus 2006 70000 30000.0 +Ford Focus 2005 80000 28000.0 +Ford Focus 2004 90000 26000.0 +Ford Focus 2003 100000 24000.0 +Ford Focus 2002 110000 22000.0 +Ford Focus 2001 120000 20000.0 +Ford Focus 2000 130000 18000.0 +Ford Focus 1999 140000 16000.0 +Ford Focus 1998 150000 14000.0 +Ford Mondeo 2009 37000 36000.0 +Fiat Bravo 2008 27000 36000.0 +Ford Fiesta 2009 37000 16000.0 +Audi A6 2006 87000 36000.0 diff --git a/Lab1b_BendriniaiSarasai/Lab1b_BendriniaiSarasai.iml b/Lab1b_BendriniaiSarasai/Lab1b_BendriniaiSarasai.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Lab1b_BendriniaiSarasai/Lab1b_BendriniaiSarasai.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Lab1b_BendriniaiSarasai/src/com/ktu/Car.java b/Lab1b_BendriniaiSarasai/src/com/ktu/Car.java new file mode 100644 index 0000000..d1ae5e5 --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/com/ktu/Car.java @@ -0,0 +1,171 @@ +/** @author Eimutis Karčiauskas, KTU IF Programų inžinerijos katedra, 2014 09 23 + * + * Tai yra demonstracinė automobilio klasė (jos objektai dedami į LinkedList), + * kuri realizuoja interfeisą Parsable. + ****************************************************************************/ +package com.ktu; + +import util.Ks; +import java.time.LocalDate; +import java.util.Comparator; +import java.util.InputMismatchException; +import java.util.Locale; +import java.util.NoSuchElementException; +import java.util.Scanner; +import util.Parsable; + +public class Car implements Parsable { + + // bendri duomenys visiems automobiliams (visai klasei) + final static private int minYear = 1994; + + final static private double minPrice = 200.0; + final static private double maxPrice = 120_000.0; + + // kiekvieno automobilio individualūs duomenys + private String make; + private String model; + private int year; + private int mileage; + private double price; + + public Car() { + } + + public Car(String make, String model, + int year, int mileage, double price) { + this.make = make; + this.model = model; + this.year = year; + this.mileage = mileage; + this.price = price; + } + + public Car(String data) { + parse(data); + } + + @Override + public final void parse(String data) { + try { // ed - tai elementarūs duomenys, atskirti tarpais + Scanner ed = new Scanner(data); + make = ed.next(); + model = ed.next(); + year = ed.nextInt(); + mileage = ed.nextInt(); + setPrice(ed.nextDouble()); + } catch (InputMismatchException e) { + Ks.ern("Blogas duomenų formatas apie auto -> " + data); + } catch (NoSuchElementException e) { + Ks.ern("Trūksta duomenų apie auto -> " + data); + } + } + + public String validate() { + String error = ""; + int currentYear = LocalDate.now().getYear(); + if (year < minYear || year > currentYear) { + error = "Netinkami gamybos metai, turi būti [" + + minYear + ":" + currentYear + "]"; + } + if (price < minPrice || price > maxPrice) { + error += " Kaina už leistinų ribų [" + minPrice + + ":" + maxPrice + "]"; + } + return error; + } + + @Override + public String toString() { // surenkama visa reikalinga informacija + return String.format("%-8s %-8s %4d %7d %8.1f %s", + make, model, year, mileage, price, validate()); + } + + public String getMake() { + return make; + } + + public String getModel() { + return model; + } + + public int getYear() { + return year; + } + + public int getMileage() { + return mileage; + } + + public double getPrice() { + return price; + } + + // keisti bus galima tik kainą - kiti parametrai pastovūs + public void setPrice(double price) { + this.price = price; + } + + @Override + public int compareTo(Car otherCar) { + // lyginame pagal svarbiausią požymį - kainą + double otherPrice = otherCar.getPrice(); + if (price < otherPrice) { + return -1; + } + if (price > otherPrice) { + return +1; + } + return 0; + } + + // pradžioje pagal markes, o po to pagal modelius + public final static Comparator byMakeAndModel + = Comparator.comparing(Car::getMake).thenComparing(Car::getModel); + + public final static Comparator byPrice = (car1, car2) -> { + double price1 = car1.getPrice(); + double price2 = car2.getPrice(); + // didėjanti tvarka, pradedant nuo mažiausios + if (price1 < price2) { + return -1; + } + if (price1 > price2) { + return 1; + } + return 0; + }; + + public final static Comparator byYearAndPrice = (car1, car2) -> { + // metai mažėjančia tvarka, esant vienodiems lyginama price + if (car1.getYear() < car2.getYear()) { + return 1; + } + if (car1.getYear() > car2.getYear()) { + return -1; + } + if (car1.getPrice() < car2.getPrice()) { + return 1; + } + if (car1.getPrice() > car2.getPrice()) { + return -1; + } + return 0; + }; + + // metodas main = tiesiog paprastas pirminis automobilių išbandymas + public static void main(String... args) { + // suvienodiname skaičių formatus pagal LT lokalę (10-ainis kablelis) + Locale.setDefault(new Locale("LT")); + Car a1 = new Car("Renault", "Laguna", 1997, 50000, 599); + Car a2 = new Car("Renault", "Megane", 2015, 20000, 3500); + Car a3 = new Car(); + Car a4 = new Car(); + a3.parse("Toyota Corolla 2001 20000 8500,8"); + a4.parse("Toyota Avensis 1990 20000 500,8"); + Ks.oun(a1); + Ks.oun(a2); + Ks.oun(a3); + Ks.oun(a4); + } +} diff --git a/Lab1b_BendriniaiSarasai/src/com/ktu/CarList.java b/Lab1b_BendriniaiSarasai/src/com/ktu/CarList.java new file mode 100644 index 0000000..af2c7ed --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/com/ktu/CarList.java @@ -0,0 +1,11 @@ +package com.ktu; + +import util.ParsableList; + +public class CarList extends ParsableList { + + @Override + protected Car createElement(String data) { + return new Car(data); + } +} diff --git a/Lab1b_BendriniaiSarasai/src/com/ktu/CarMarket.java b/Lab1b_BendriniaiSarasai/src/com/ktu/CarMarket.java new file mode 100644 index 0000000..9510ec5 --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/com/ktu/CarMarket.java @@ -0,0 +1,62 @@ +/** + * Tai yra automobilių sąrašų kūrimo ir tolimesnių taikomųjų veiksmų klasė. + ****************************************************************************/ +package com.ktu; + +public class CarMarket { + + public CarList allCars = new CarList(); + + // suformuojamas sąrašas automobilių, kurie pagaminti vėliau nei riba + public CarList getNewerCars(int fromYear) { + CarList cars = new CarList(); + for (Car c : allCars) { + if (c.getYear() >= fromYear) { + cars.add(c); + } + } + return cars; + } + + // suformuojamas sąrašas automobilių, kurių kaina yra tarp ribų + public CarList getByPrice(int fromPrice, int toPrice) { + CarList cars = new CarList(); + for (Car c : allCars) { + if (c.getPrice() >= fromPrice && c.getPrice() <= toPrice) { + cars.add(c); + } + } + return cars; + } + + // suformuojamas sąrašas automobilių, turinčių didžiausią ridą + public CarList getHighestMileageCars() { + CarList cars = new CarList(); + // formuojamas sąrašas su maksimalia reikšme vienos peržiūros metu + double maxMileage = 0; + for (Car c : allCars) { + double mileage = c.getMileage(); + if (mileage >= maxMileage) { + if (mileage > maxMileage) { + cars.clear(); + maxMileage = mileage; + } + cars.add(c); + } + } + return cars; + } + + // suformuojams sąrašas automobilių, kurių modelio kodas atitinka nurodytą + public CarList getByMakeAndModel(String makeAndModel) { + CarList cars = new CarList(); + for (Car c : allCars) { + String carMakeAndModel = c.getMake() + " " + c.getModel(); + if (carMakeAndModel.startsWith(makeAndModel)) { + cars.add(c); + } + } + return cars; + } + // metodo main nėra -> demo bandymai klasėje ManualTest +} diff --git a/Lab1b_BendriniaiSarasai/src/com/ktu/ManualTest.java b/Lab1b_BendriniaiSarasai/src/com/ktu/ManualTest.java new file mode 100644 index 0000000..474dda9 --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/com/ktu/ManualTest.java @@ -0,0 +1,172 @@ +/** @author Eimutis Karčiauskas, KTU IF Programų inžinerijos katedra, 2014 09 23 + * + * Tai yra demonstracinė automobilių sąrašo bandymų klasė, kuri skirta tiesiog + * veiksmų su sąrašais išbandymui. + *************************************************************************** */ +package com.ktu; + +import util.Ks; +import java.util.Comparator; +import java.util.Locale; + +public class ManualTest { + + CarList cars = new CarList(); + + void execute() { + //createCars(); + createCarList(); +// countRenault(); +// appendCarList(); +// checkCarMarketFilters(); +// checkCarMarketSorting(); + } + + void createCars() { + Car c1 = new Car("Renault", "Laguna", 1997, 50000, 1700); + Car c2 = new Car("Renault", "Megane", 2001, 20000, 3500); + Car c3 = new Car("Toyota", "Corolla", 2001, 20000, 8500.8); + Car c4 = new Car(); + Car c5 = new Car(); + Car c6 = new Car(); + c4.parse("Renault Laguna 2001 115900 7500"); + c5.parse("Renault Megane 1946 365100 9500"); + c6.parse("Honda Civic 2007 36400 8500,3"); + + Ks.oun(c1); + Ks.oun(c2); + Ks.oun(c3); + Ks.oun("Pirmų 3 auto ridos vidurkis= " + + (c1.getMileage() + c2.getMileage() + c3.getMileage()) / 3); + Ks.oun(c4); + Ks.oun(c5); + Ks.oun(c6); + Ks.oun("Kitų 3 auto kainų suma= " + + (c4.getPrice() + c5.getPrice() + c6.getPrice())); + } + + void createCarList() { + Car c1 = new Car("Renault", "Laguna", 1997, 50000, 1700); + Car c2 = new Car("Renault", "Megane", 2001, 20000, 3500); + Car c3 = new Car("Toyota", "Corolla", 2001, 20000, 8500.8); + cars.add(c1); + cars.add(c2); + cars.add(c3); + cars.println("Pirmi 3 auto"); + cars.add("Renault Laguna 2001 115900 7500"); + cars.add("Renault Megane 1946 365100 9500"); + cars.add("Honda Civic 2007 36400 8500,3"); + + cars.println("Visi 6 auto"); + cars.forEach(System.out::println); + Ks.oun("Pirmų 3 auto ridos vidurkis= " + + (cars.get(0).getMileage() + cars.get(1).getMileage() + + cars.get(2).getMileage()) / 3); + + Ks.oun("Kitų 3 auto kainų suma= " + + (cars.get(3).getPrice() + cars.get(4).getPrice() + + cars.get(5).getPrice())); + // palaipsniui atidenkite sekančias eilutes ir išbandykite + cars.add(0, new Car("Mazda","6",2007,50000,27000)); + cars.add(6, new Car("Hyundai","Lantra",1998,9500,777)); + cars.set(4, c3); + cars.println("Po įterpimų"); + cars.remove(7); + cars.remove(0); + cars.println("Po išmetimų"); + cars.remove(0); cars.remove(0); cars.remove(0); + cars.remove(0); cars.remove(0); cars.remove(0); + cars.println("Po visų išmetimų"); + cars.remove(0); + cars.println("Po visų išmetimų"); + } + + void countRenault() { + int sk = 0; + for (Car c : cars) { + if (c.getMake().compareTo("Renault") == 0) { + sk++; + } + } + Ks.oun("Renault automobilių yra = " + sk); + } + + void appendCarList() { + for (int i = 0; i < 8; i++) { + cars.add(new Car("Ford", "Focus", + 2009 - i, 40000 + i * 10000, 36000 - i * 2000)); + } + cars.add("Ford Mondeo 2009 37000 36000.0"); + cars.add("Fiat Bravo 2008 27000 32500,0"); + cars.add("Ford Fiesta 2009 37000 16000,0"); + cars.add("Audi A6 2006 87000 36000,0"); + cars.println("Testuojamų automobilių sąrašas"); + cars.save("ban.txt"); + } + + void checkCarMarketFilters() { + CarMarket market = new CarMarket(); + + market.allCars.load("ban.txt"); + market.allCars.println("Bandomasis rinkinys"); + + cars = market.getNewerCars(2001); + cars.println("Pradedant nuo 2001"); + + cars = market.getByPrice(3000, 10000); + cars.println("Kaina tarp 3000 ir 10000"); + + cars = market.getHighestMileageCars(); + cars.println("Daugiausiai nuvažiavę"); + + cars = market.getByMakeAndModel("F"); + cars.println("Turi būti tik Fiatai ir Fordai"); + + cars = market.getByMakeAndModel("Ford M"); + + cars.println("Turi būti tik Ford Mondeo"); + int n = 0; + for (Car c : cars) { + n++; // testuojame ciklo veikimą + } + Ks.oun("Ford Mondeo kiekis = " + n); + } + + void checkCarMarketSorting() { + CarMarket market = new CarMarket(); + + market.allCars.load("ban.txt"); + Ks.oun("========" + market.allCars.get(0)); + market.allCars.println("Bandomasis rinkinys"); + market.allCars.sortBuble(Car.byMakeAndModel); + market.allCars.println("Rūšiavimas pagal Markę ir Modelį"); + market.allCars.sortBuble(Car.byPrice); + market.allCars.println("Rūšiavimas pagal kainą"); + market.allCars.sortBuble(Car.byYearAndPrice); + market.allCars.println("Rūšiavimas pagal Metus ir Kainą"); + market.allCars.sortBuble(byMileage); + market.allCars.sortBuble(Comparator.comparingInt(Car::getMileage)); + market.allCars.println("Rūšiavimas pagal Ridą"); + market.allCars.sortBuble(); + market.allCars.println("Rūšiavimas pagal compareTo - Kainą"); + } + + static Comparator byMileage = (car1, car2) -> { + int m1 = car1.getMileage(); + int m2 = car2.getMileage(); + // rida atvirkščia mažėjančia tvarka, pradedant nuo didžiausios + if (m1 < m2) { + return 1; + } + if (m1 > m2) { + return -1; + } + return 0; + }; + + public static void main(String... args) { + // suvienodiname skaičių formatus pagal LT lokalę (10-ainis kablelis) + Locale.setDefault(new Locale("LT")); + new ManualTest().execute(); + } +} diff --git a/Lab1b_BendriniaiSarasai/src/com/ktu/Optional1.java b/Lab1b_BendriniaiSarasai/src/com/ktu/Optional1.java new file mode 100644 index 0000000..d970236 --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/com/ktu/Optional1.java @@ -0,0 +1,38 @@ +package com.ktu; + +import util.ArrayStack; + +import java.io.BufferedReader; +import java.io.Console; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Optional1 { + public static void main(String... args) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + while (true) { + String line = reader.readLine(); + boolean result = check(line); + System.out.println(result); + } + } + + public static boolean check(String line) { + ArrayStack stack = new ArrayStack<>(); + + for (char c : line.toCharArray()) { + if (c == '(' || c == '[' || c == '{') { + stack.push(c); + } else if (c == ')' || c == ']' || c == '}') { + char opening_c = stack.pop(); + if (!((opening_c == '(' && c == ')') || + (opening_c == '[' && c == ']') || + (opening_c == '{' && c == '}'))) { + return false; + } + } + } + + return stack.isEmpty(); + } +} diff --git a/Lab1b_BendriniaiSarasai/src/com/ktu/Optional2.java b/Lab1b_BendriniaiSarasai/src/com/ktu/Optional2.java new file mode 100644 index 0000000..e4f595b --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/com/ktu/Optional2.java @@ -0,0 +1,39 @@ +package com.ktu; + +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Deque; +import java.util.stream.Collectors; + +public class Optional2 { + static int[] slidingMaximum(int[] nums, int m) + { + int[] ans = new int[nums.length - m + 1]; + Deque d = new ArrayDeque<>(); + + for (int i = 0; i < nums.length; i++) { + int num = nums[i]; + while (!d.isEmpty() && nums[d.getLast()] < num) { + d.removeLast(); + } + d.addLast(i); + if (d.getFirst() == i - m) { + d.removeFirst(); + } + if (i >= m-1) { + ans[i - m + 1] = nums[d.getFirst()]; + } + } + + return ans; + } + + public static void main(String args[]) + { + int m = 3; + int[] numbers = { 8, 7, 5, 4, 3, 1 }; + + int[] ans = slidingMaximum(numbers, m); + System.out.println(Arrays.stream(ans).mapToObj(String::valueOf).collect(Collectors.joining(", "))); + } +} diff --git a/Lab1b_BendriniaiSarasai/src/com/ktu/SimpleBenchmark.java b/Lab1b_BendriniaiSarasai/src/com/ktu/SimpleBenchmark.java new file mode 100644 index 0000000..9fe462c --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/com/ktu/SimpleBenchmark.java @@ -0,0 +1,103 @@ +/** @author Eimutis Karčiauskas, KTU IF Programų inžinerijos katedra, 2014 09 23 + * + * Tai yra darbo su sąrašais greitaveikos tyrimo klasė. + * Pavyzdyje pateiktas rikiavimo metodų tyrimas. + * Tyrimo metu pateiktais metodais naudojamasi kaip šablonais, + * išbandant įvairius rūšiavimo aspektus. + *************************************************************************** */ +package com.ktu; + +import util.Ks; +import util.LinkedList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Locale; +import java.util.Random; + +public class SimpleBenchmark { + + Car[] cars; + LinkedList carSeries = new LinkedList<>(); + Random rg = new Random(); // atsitiktinių generatorius + int[] counts = {2_000, 4_000, 8_000, 16_000}; +// pabandykite, ar Jūsų kompiuteris įveiks šiuos eksperimentus +// static int[] counts = {10_000, 20_000, 40_000, 80_000}; + + void generateCars(int count) { + String[][] makesAndModels = { // galimų automobilių markių ir jų modelių masyvas + {"Mazda", "121", "323", "626", "MX6"}, + {"Ford", "Fiesta", "Escort", "Focus", "Sierra", "Mondeo"}, + {"Saab", "92", "96"}, + {"Honda", "Accord", "Civic", "Jazz"}, + {"Renault", "Laguna", "Megane", "Twingo", "Scenic"}, + {"Peugeot", "206", "207", "307"} + }; + cars = new Car[count]; + rg.setSeed(2017); + for (int i = 0; i < count; i++) { + int makeIndex = rg.nextInt(makesAndModels.length); // markės indeksas 0.. + int modelIndex = rg.nextInt(makesAndModels[makeIndex].length - 1) + 1;// modelio indeksas 1.. + cars[i] = new Car(makesAndModels[makeIndex][0], makesAndModels[makeIndex][modelIndex], + 1994 + rg.nextInt(20), // metai tarp 1994 ir 2013 + 6000 + rg.nextInt(222_000), // rida tarp 6000 ir 228000 + 1000 + rg.nextDouble() * 350_000); // kaina tarp 1000 ir 351_000 + } + Collections.shuffle(Arrays.asList(cars)); + carSeries.clear(); + for (Car c : cars) { + carSeries.add(c); + } + } + + void generateAndExecute(int elementCount) { +// Paruošiamoji tyrimo dalis + long t0 = System.nanoTime(); + generateCars(elementCount); + LinkedList carSeries2 = carSeries.clone(); + LinkedList carSeries3 = carSeries.clone(); + LinkedList carSeries4 = carSeries.clone(); + long t1 = System.nanoTime(); + System.gc(); + System.gc(); + System.gc(); + long t2 = System.nanoTime(); +// Greitaveikos bandymai ir laiko matavimai + carSeries.sortSystem(); + long t3 = System.nanoTime(); + carSeries2.sortSystem(Car.byPrice); + long t4 = System.nanoTime(); + carSeries3.sortBuble(); + long t5 = System.nanoTime(); + carSeries4.sortBuble(Car.byPrice); + long t6 = System.nanoTime(); + Ks.ouf("%7d %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f \n", elementCount, + (t1 - t0) / 1e9, (t2 - t1) / 1e9, (t3 - t2) / 1e9, + (t4 - t3) / 1e9, (t5 - t4) / 1e9, (t6 - t5) / 1e9); + } + + void execute() { + long memTotal = Runtime.getRuntime().totalMemory(); + Ks.oun("memTotal= " + memTotal); + // Pasižiūrime kaip generuoja automobilius (20) vienetų) + generateCars(20); + for (Car c : carSeries) { + Ks.oun(c); + } + Ks.oun("1 - Pasiruošimas tyrimui - duomenų generavimas"); + Ks.oun("2 - Pasiruošimas tyrimui - šiukšlių surinkimas"); + Ks.oun("3 - Rūšiavimas sisteminiu greitu būdu be Comparator"); + Ks.oun("4 - Rūšiavimas sisteminiu greitu būdu su Comparator"); + Ks.oun("5 - Rūšiavimas List burbuliuku be Comparator"); + Ks.oun("6 - Rūšiavimas List burbuliuku su Comparator"); + Ks.ouf("%6d %7d %7d %7d %7d %7d %7d \n", 0, 1, 2, 3, 4, 5, 6); + for (int n : counts) { + generateAndExecute(n); + } + } + + public static void main(String[] args) { + // suvienodiname skaičių formatus pagal LT lokalę (10-ainis kablelis) + Locale.setDefault(new Locale("LT")); + new SimpleBenchmark().execute(); + } +} diff --git a/Lab1b_BendriniaiSarasai/src/util/ArrayQueue.java b/Lab1b_BendriniaiSarasai/src/util/ArrayQueue.java new file mode 100644 index 0000000..7470ab8 --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/util/ArrayQueue.java @@ -0,0 +1,42 @@ +package util; + +import java.util.ArrayList; + +public class ArrayQueue implements Queue { + private ArrayList data; + private int start = 0; + private int end = -1; + + public ArrayQueue() { + data = new ArrayList<>(); + } + + @Override + public void enqueue(E item) { + data.set(++end, item); + } + + @Override + public E dequeue() { + if (isEmpty()) return null; + + E value = data.get(start++); + if (isEmpty()) { + data = new ArrayList<>(); + start = 0; + end = -1; + } + return value; + } + + @Override + public E peak() { + if (isEmpty()) return null; + return data.get(start); + } + + @Override + public boolean isEmpty() { + return start > end; + } +} diff --git a/Lab1b_BendriniaiSarasai/src/util/ArrayStack.java b/Lab1b_BendriniaiSarasai/src/util/ArrayStack.java new file mode 100644 index 0000000..0788616 --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/util/ArrayStack.java @@ -0,0 +1,35 @@ +package util; + +import java.util.ArrayList; + +public class ArrayStack implements Stack { + private ArrayList data; + + public ArrayStack() { + data = new ArrayList<>(); + } + + @Override + public E pop() { + int size = data.size(); + if (size == 0) return null; + return data.remove(size-1); + } + + @Override + public void push(E item) { + data.add(item); + } + + @Override + public E peak() { + int size = data.size(); + if (size == 0) return null; + return data.get(size-1); + } + + @Override + public boolean isEmpty() { + return data.size() == 0; + } +} diff --git a/Lab1b_BendriniaiSarasai/src/util/Ks.java b/Lab1b_BendriniaiSarasai/src/util/Ks.java new file mode 100644 index 0000000..79d4ea6 --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/util/Ks.java @@ -0,0 +1,159 @@ +/** @author Eimutis Karčiauskas, KTU IF Programų inžinerijos katedra, 2014 09 23 + * + * Klasė yra skirta patogiam duomenų paėmimui iš klaviatūros bei + * efektyviam rezultatų pateikimui į sout ir serr srautus. + * Visi metodai yra statiniai ir skirti vienam duomenų tipui. + *************************************************************************** */ +package util; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.util.Arrays; + +public class Ks { // KTU system - imituojama Javos System klasė + + private static final BufferedReader keyboard + = new BufferedReader(new InputStreamReader(System.in)); + private static String dataFolderKTU = "Duomenys"; + + static public String giveString(String prompt) { + Ks.ou(prompt); + try { + return keyboard.readLine(); + } catch (IOException e) { + Ks.ern("Neveikia klaviatūros srautas, darbas baigtas"); + System.exit(0); + } + return ""; + } + + static public long giveLong(String prompt) { + while (true) { + String s = giveString(prompt); + try { + return Long.parseLong(s); + } catch (NumberFormatException e) { + Ks.ern("Neteisingas skaičiaus formatas, pakartokite"); + } + } + } + + static public long giveLong(String prompt, long bound1, long bound2) { + while (true) { + long a = giveLong(prompt + " tarp ribų [" + bound1 + ":" + bound2 + "]="); + if (a < bound1) { + Ks.ern("Skaičius mažesnis nei leistina, pakartokite"); + } else if (a > bound2) { + Ks.ern("Skaičius didesnis nei leistina, pakartokite"); + } else { + return a; + } + } + } + + static public int giveInt(String prompt) { + while (true) { + long a = giveLong(prompt); + if (a < Integer.MIN_VALUE) { + Ks.ern("Skaičius mažesnis nei Integer.MIN_VALUE" + + ", pakartokite"); + } else if (a > Integer.MAX_VALUE) { + Ks.ern("Skaičius didesnis nei Integer.MAX_VALUE" + + ", pakartokite"); + } else { + return (int) a; + } + } + } + + static public int giveInt(String prompt, int bound1, int bound2) { + return (int) giveLong(prompt, bound1, bound2); + } + + static public double giveDouble(String prompt) { + while (true) { + String s = giveString(prompt); + try { + return Double.parseDouble(s); + } catch (NumberFormatException e) { + if (s.contains(",")) { + Ks.ern("Vietoje kablelio naudokite tašką" + + ", pakartokite"); + } else { + Ks.ern("Neteisingas skaičiaus formatas" + + ", pakartokite"); + } + } + } + } + + static public double giveDouble(String prompt, double bound1, double bound2) { + while (true) { + double a = giveDouble(prompt + " tarp ribų [" + bound1 + ":" + bound2 + "]="); + if (a < bound1) { + Ks.ern("Skaičius mažesnis nei leistina, pakartokite"); + } else if (a > bound2) { + Ks.ern("Skaičius didesnis nei leistina, pakartokite"); + } else { + return a; + } + } + } + + static public String giveFileName() { + File dir = new File(dataFolderKTU); + dir.mkdir(); + oun("Jums prieinami failai " + Arrays.toString(dir.list())); + String fn = giveString("Nurodykite pasirinktą duomenų failo vardą: "); + return (fn); + } + + static public String getDataFolder() { + return dataFolderKTU; + } + + static public void setDataFolder(String folderName) { + dataFolderKTU = folderName; + } + + private static final PrintStream sout = System.out; + private static final PrintStream serr = System.out; + private static int lineNr; + private static int errorNr; + private static final boolean formatStartOfLine = true; + + static public void ou(Object obj) { + if (formatStartOfLine) { + sout.printf("%2d| %s", ++lineNr, obj); + } else { + sout.println(obj); + } + } + + static public void oun(Object obj) { + if (formatStartOfLine) { + sout.printf("%2d| %s\n", ++lineNr, obj); + } else { + sout.println(obj); + } + } + + static public void ouf(String format, Object... args) { + sout.printf(format, args); + } + + static public void er(Object obj) { + serr.printf("***Klaida %d: %s", ++errorNr, obj); + } + + static public void ern(Object obj) { + serr.printf("***Klaida %d: %s\n", ++errorNr, obj); + } + + static public void erf(String format, Object... args) { + serr.printf(format, args); + } +} diff --git a/Lab1b_BendriniaiSarasai/src/util/LinkedList.java b/Lab1b_BendriniaiSarasai/src/util/LinkedList.java new file mode 100644 index 0000000..8717b7f --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/util/LinkedList.java @@ -0,0 +1,408 @@ +/** + * @author Eimutis Karčiauskas, KTU IF Programų inžinerijos katedra, 2014 09 23 + * + * Tai pirmoji kompleksinės duomenų struktūros klasė, kuri leidžia apjungti + * atskirus objektus į vieną visumą - sąrašą. Objektai, kurie bus dedami į + * sąrašą, turi tenkinti interfeisą Comparable. + * + * Užduotis: Peržiūrėkite ir išsiaiškinkite pateiktus metodus. Metodų algoritmai + * yra aptarti paskaitos metu. Realizuokite nurodytus metodus. + * **************************************************************************** + */ +package util; + +import java.util.Arrays; +import java.util.Comparator; + +/** + * Koreguota 2015-09-18 + * + * @author Aleksis + * @param Sąrašo elementų tipas (klasė) + */ +public class LinkedList> + implements List, Iterable, Cloneable { + + private Node first; // rodyklė į pirmą mazgą + private Node last; // rodyklė į paskutinį mazgą + private Node current; // rodyklė į einamąjį mazgą, naudojama getNext + private int size; // sąrašo dydis, tuo pačiu elementų skaičius + + /** + * Constructs an empty list. + */ + public LinkedList() { + } + + /** + * metodas add įdeda elementą į sąrašo pabaigą + * + * @param e - tai įdedamas elementas (jis negali būti null) + * @return true, jei operacija atlikta sėkmingai + */ + @Override + public boolean add(E e) { + if (e == null) { + return false; // nuliniai objektai nepriimami + } + if (first == null) { + first = new Node<>(e, first); + last = first; + } else { + Node e1 = new Node(e, null); + last.next = e1; + last = e1; + } + size++; + return true; + } + + /** + * Įterpia elementą prieš k-ąją poziciją + * + * @param k pozicija + * @param e įterpiamasis elementas + * @return jei k yra blogas, grąžina null + */ + @Override + public boolean add(int k, E e) { + if (e == null) return false; + if (k < 0 || k >= size) return false; + + Node prev = null; + Node current = this.first; + for (int i = 0; i < k; i++) { + prev = current; + current = current.next; + } + + Node d = new Node<>(e, null); + if (prev == null && current.next == null) { + this.last = d; + this.first = d; + } else if (current.next == null) { + this.last.next = d; + this.last = d; + } else if (prev == null) { + d.next = this.first; + this.first = d; + } else { + prev.next = d; + d.next = current; + } + + size++; + + return true; + } + + /** + * + * @return sąrašo dydis (elementų kiekis) + */ + @Override + public int size() { + return size; + } + + /** + * patikrina ar sąrašas yra tuščias + * + * @return true, jei tuščias + */ + @Override + public boolean isEmpty() { + return first == null; + } + + /** + * Išvalo sąrašą + */ + @Override + public void clear() { + size = 0; + first = null; + last = null; + current = null; + } + + /** + * Grąžina elementą pagal jo indeksą (pradinis indeksas 0) + * + * @param k indeksas + * @return k-ojo elemento reikšmę; jei k yra blogas, gąžina null + */ + @Override + public E get(int k) { + if (k < 0 || k >= size) { + return null; + } + current = first.findNode(k); + return current.element; + } + + /** + * Pakeičia k-ojo elemento reikšmę + * + * @param k keičiamo elemento indeksas + * @param e nauja elemento reikšmė + * @return senoji reikšmė + */ + @Override + public E set(int k, E e) { + int i = 0; + Node current = this.first; + while (current != null && i < k) { + current = current.next; + i = i + 1; + } + if (i == k && current != null) { + E old = current.element; + current.element = e; + return old; + } else { + return null; + } + } + + /** + * pereina prie kitos reikšmės ir ją grąžina + * + * @return kita reikšmė + */ + @Override + public E getNext() { + if (current == null) { + return null; + } + current = current.next; + if (current == null) { + return null; + } + return current.element; + } + + /** + * Šalina elementą pagal indeksą + * + * @param k šalinamojo indeksas + * @return pašalintas elementas + */ + @Override + public E remove(int k) { + if (k < 0 || k >= size) return null; + + Node prev = null; + Node current = this.first; + for (int i = 0; i < k; i++) { + prev = current; + current = current.next; + } + + if (prev == null && current.next == null) { + this.last = null; + this.first = null; + } else if (current.next == null) { + this.last = prev; + } else if (prev == null) { + this.first = current.next; + } else { + prev.next = current.next; + } + + size--; + + return current.element; + } + + /** + * + * @return sąrašo kopiją + */ + @Override + public LinkedList clone() { + LinkedList cl = null; + try { + cl = (LinkedList) super.clone(); + } catch (CloneNotSupportedException e) { + Ks.ern("Blogai veikia ListKTU klasės protėvio metodas clone()"); + System.exit(1); + } + if (first == null) { + return cl; + } + cl.first = new Node<>(this.first.element, null); + Node e2 = cl.first; + for (Node e1 = first.next; e1 != null; e1 = e1.next) { + e2.next = new Node<>(e2.element, null); + e2 = e2.next; + e2.element = e1.element; + } + cl.last = e2.next; + cl.size = this.size; + return cl; + } + // ! + + /** + * Formuojamas Object masyvas (E tipo masyvo negalima sukurti) ir surašomi + * sąrašo elementai + * + * @return sąrašo elementų masyvas + */ + public Object[] toArray() { + Object[] a = new Object[size]; + int i = 0; + for (Node e1 = first; e1 != null; e1 = e1.next) { + a[i++] = e1.element; + } + return a; + } + + /** + * Masyvo rikiavimas Arrays klasės metodu sort + */ + public void sortSystem() { + Object[] a = this.toArray(); + Arrays.sort(a); + int i = 0; + for (Node e1 = first; e1 != null; e1 = e1.next) { + e1.element = (E) a[i++]; + } + } + + /** + * Rikiavimas Arrays klasės metodu sort pagal komparatorių + * + * @param c komparatorius + */ + public void sortSystem(Comparator c) { + Object[] a = this.toArray(); + Arrays.sort(a, (Comparator) c); + int i = 0; + for (Node e1 = first; e1 != null; e1 = e1.next) { + e1.element = (E) a[i++]; + } + } + + /** + * Sąrašo rikiavimas burbuliuko metodu + */ + public void sortBuble() { + if (first == null) { + return; + } + for (;;) { + boolean jauGerai = true; + Node e1 = first; + for (Node e2 = first.next; e2 != null; e2 = e2.next) { + if (e1.element.compareTo(e2.element) > 0) { + E t = e1.element; + e1.element = e2.element; + e2.element = t; + jauGerai = false; + } + e1 = e2; + } + if (jauGerai) { + return; + } + } + } + + /** + * Sąrašo rikiavimas burbuliuko metodu pagal komparatorių + * + * @param c komparatorius + */ + public void sortBuble(Comparator c) { + if (first == null) { + return; + } + for (;;) { + boolean jauGerai = true; + Node e1 = first; + for (Node e2 = first.next; e2 != null; e2 = e2.next) { + if (c.compare(e1.element, e2.element) > 0) { + E t = e1.element; + e1.element = e2.element; + e2.element = t; + jauGerai = false; + } + e1 = e2; + } + if (jauGerai) { + return; + } + } + } + + /** + * Sukuria iteratoriaus objektą sąrašo elementų peržiūrai + * + * @return iteratoriaus objektą + */ + @Override + public java.util.Iterator iterator() { + return new Iterator(); + } + + /** + * Iteratoriaus metodų klasė + */ + class Iterator implements java.util.Iterator { + + private Node iterPosition; + + Iterator() { + iterPosition = first; + } + + @Override + public boolean hasNext() { + return iterPosition != null; + } + + @Override + public E next() { + E d = iterPosition.element; + iterPosition = iterPosition.next; + return d; + } + + @Override + public void remove() { + throw new UnsupportedOperationException("Studentams reikia realizuoti remove()"); + } + } + + /** + * Vidinė mazgo klasė + * + * @param mazgo duomenų tipas + */ + private static class Node { + + private E element; // ji nematoma už klasės ListKTU ribų + private Node next; // next - kaip įprasta - nuoroda į kitą mazgą + + Node(E data, Node next) { //mazgo konstruktorius + this.element = data; + this.next = next; + } + + /** + * Suranda sąraše k-ąjį mazgą + * + * @param k ieškomo mazgo indeksas (prasideda nuo 0) + * @return surastas mazgas + */ + public Node findNode(int k) { + Node e = this; + for (int i = 0; i < k; i++) { + e = e.next; + } + return e; + } + } // klasės Node pabaiga +} diff --git a/Lab1b_BendriniaiSarasai/src/util/LinkedListQueue.java b/Lab1b_BendriniaiSarasai/src/util/LinkedListQueue.java new file mode 100644 index 0000000..b97683c --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/util/LinkedListQueue.java @@ -0,0 +1,29 @@ +package util; + +public class LinkedListQueue> implements Queue { + private LinkedList data; + + public LinkedListQueue() { + data = new LinkedList<>(); + } + + @Override + public void enqueue(E item) { + data.add(item); + } + + @Override + public E dequeue() { + return data.remove(0); + } + + @Override + public E peak() { + return data.get(0); + } + + @Override + public boolean isEmpty() { + return data.isEmpty(); + } +} diff --git a/Lab1b_BendriniaiSarasai/src/util/LinkedListStack.java b/Lab1b_BendriniaiSarasai/src/util/LinkedListStack.java new file mode 100644 index 0000000..257de34 --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/util/LinkedListStack.java @@ -0,0 +1,29 @@ +package util; + +public class LinkedListStack> implements Stack { + private LinkedList data; + + public LinkedListStack() { + data = new LinkedList(); + } + + @Override + public E pop() { + return data.remove(0); + } + + @Override + public void push(E item) { + data.add(0, item); + } + + @Override + public E peak() { + return data.get(0); + } + + @Override + public boolean isEmpty() { + return data.isEmpty(); + } +} diff --git a/Lab1b_BendriniaiSarasai/src/util/List.java b/Lab1b_BendriniaiSarasai/src/util/List.java new file mode 100644 index 0000000..c05b440 --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/util/List.java @@ -0,0 +1,60 @@ +/** @author Eimutis Karčiauskas, KTU IF Programų inžinerijos katedra, 2014 09 23 + * + * Tai pirmosios kolekcijų duomenų struktūros klasės interfeisas, + * apibrėžiantis operacijas, kurių pagalba atskiri objektai apjungiami + * į vieną visumą - sąrašą. + ***************************************************************************** */ +package util; + +public interface List { + + /** + * Appends the specified element to the end of this list. + * + * @param e element to be appended to this list + * @return true, if operation is Ok + */ + boolean add(E e); + + boolean add(int k, E e); + + /** + * Returns the number of elements in this list. + * + * @param k index of the element to be removed + * @return removed object e + */ + E remove(int k); + + int size(); + + boolean isEmpty(); + + /** + * Removes all of the elements from this list. + */ + void clear(); + + /** + * Positional Access Operations. Returns the element at the specified + * position in this list. + * + * @param k index of the element to return + * @return the element at the specified position in this list + * @throws IndexOutOfBoundsException {@inheritDoc} + */ + E get(int k); + + E getNext(); + + /** + * Replaces the element at the specified position in this list with the + * specified element. + * + * @param k index of the element to replace + * @param e element to be stored at the specified position + * @return the element previously at the specified position + * @throws IndexOutOfBoundsException {@inheritDoc} + */ + E set(int k, E e); +} diff --git a/Lab1b_BendriniaiSarasai/src/util/Parsable.java b/Lab1b_BendriniaiSarasai/src/util/Parsable.java new file mode 100644 index 0000000..7163e87 --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/util/Parsable.java @@ -0,0 +1,10 @@ +/** @author Eimutis Karčiauskas, KTU IF Programų inžinerijos katedra, 2014 09 23 + * + * Tai yra interfeisas, kurį turi tenkinti KTU studentų kuriamos duomenų klasės. + * Metodai užtikrina patogų duomenų suformavimą iš String eilučių. + ***************************************************************************** */ +package util; + +public interface Parsable extends Comparable { + void parse(String dataString); // suformuoja objektą iš eilutės +} diff --git a/Lab1b_BendriniaiSarasai/src/util/ParsableList.java b/Lab1b_BendriniaiSarasai/src/util/ParsableList.java new file mode 100644 index 0000000..3d89c77 --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/util/ParsableList.java @@ -0,0 +1,103 @@ +/** @author Eimutis Karčiauskas, KTU IF Programų inžinerijos katedra, 2014 09 23 + * + * Tai išvestinė kompleksinės duomenų struktūros klasė, kuri leidžia + * papildomai atlikti įvedimo - išvedimo veiksmus su sąrašo elementais. + * Objektai, kurie bus dedami į sąrašą, turi tenkinti interfeisą Parsable. + ***************************************************************************** + */ +package util; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.function.Function; + +public class ParsableList> extends LinkedList { + + private Function createFunction; + + public ParsableList() { + } + + public ParsableList(Function createFunction) { + this.createFunction = createFunction; + } + + public void add(String dataString) { // sukuria elementą iš String + add(createElement(dataString)); // ir įdeda jį į pabaigą + } + + public void load(String fName) {//suformuoja sąrašą iš fName failo + clear(); + if (fName.length() == 0) { + return; + } + try { + (new File(Ks.getDataFolder())).mkdir(); + String fN = Ks.getDataFolder() + File.separatorChar + fName; + BufferedReader fReader + = new BufferedReader(new FileReader(new File(fN))); + String dLine; + while ((dLine = fReader.readLine()) != null) { + add(dLine); + } + fReader.close(); + } catch (FileNotFoundException e) { + Ks.ern("Duomenų failas " + fName + " nerastas"); +// System.exit(0); + } catch (IOException e) { + Ks.ern("Failo " + fName + " skaitymo klaida"); + System.exit(0); + } + } + + public void save(String fName) { // išsaugoja sąrašą faile fName + PrintWriter fWriter = null; // tekstiniu formatu + try { // tinkamu vėlesniam skaitymui + // jei vardo nėra - failas neformuojamas + if (fName.equals("")) { + return; + } + + String fN = Ks.getDataFolder() + File.separatorChar + fName; + fWriter = new PrintWriter(new FileWriter(new File(fN))); + for (Parsable d1 = super.get(0); d1 != null; d1 = super.getNext()) { + fWriter.println(d1.toString()); + } + fWriter.close(); + } catch (IOException e) { + Ks.ern("!!! Klaida formuojant " + fName + " failą."); + System.exit(0); + } + } + + public void println() { // sąrašas spausdinamas į Ks.oun(""); + int eilNr = 0; + if (super.isEmpty()) { + Ks.oun("Sąrašas yra tuščias"); + } else { + for (Parsable d1 = super.get(0); d1 != null; d1 = super.getNext()) { + String printData = String.format("%3d: %s ", eilNr++, d1.toString()); + Ks.oun(printData); + } + } + Ks.oun("****** Bendras elementų kiekis yra " + super.size()); + } + + public void println(String title) { // spausdinant galima nurodyti antraštę + Ks.oun("========" + title + "======="); + println(); + Ks.oun("======== Sąrašo pabaiga ======="); + } + + protected E createElement(String data) { + if (createFunction == null) { + throw new IllegalStateException("Nenustatyta sąrašo elementų kūrimo funkcija"); + } + return createFunction.apply(data); + } +} diff --git a/Lab1b_BendriniaiSarasai/src/util/Queue.java b/Lab1b_BendriniaiSarasai/src/util/Queue.java new file mode 100644 index 0000000..4e92e30 --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/util/Queue.java @@ -0,0 +1,8 @@ +package util; + +public interface Queue { + void enqueue(E item); + E dequeue(); + E peak(); + boolean isEmpty(); +} diff --git a/Lab1b_BendriniaiSarasai/src/util/Stack.java b/Lab1b_BendriniaiSarasai/src/util/Stack.java new file mode 100644 index 0000000..21d68d9 --- /dev/null +++ b/Lab1b_BendriniaiSarasai/src/util/Stack.java @@ -0,0 +1,8 @@ +package util; + +public interface Stack { + E pop(); + void push(E item); + E peak(); + boolean isEmpty(); +} diff --git a/Lab2_AibesMedziai/.idea/.gitignore b/Lab2_AibesMedziai/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Lab2_AibesMedziai/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Lab2_AibesMedziai/.idea/.name b/Lab2_AibesMedziai/.idea/.name new file mode 100644 index 0000000..3015f06 --- /dev/null +++ b/Lab2_AibesMedziai/.idea/.name @@ -0,0 +1 @@ +Lab2_AibesMedziai \ No newline at end of file diff --git a/Lab2_AibesMedziai/.idea/compiler.xml b/Lab2_AibesMedziai/.idea/compiler.xml new file mode 100644 index 0000000..008bc58 --- /dev/null +++ b/Lab2_AibesMedziai/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lab2_AibesMedziai/.idea/dbnavigator.xml b/Lab2_AibesMedziai/.idea/dbnavigator.xml new file mode 100644 index 0000000..98bf579 --- /dev/null +++ b/Lab2_AibesMedziai/.idea/dbnavigator.xml @@ -0,0 +1,463 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lab2_AibesMedziai/.idea/encodings.xml b/Lab2_AibesMedziai/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/Lab2_AibesMedziai/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Lab2_AibesMedziai/.idea/inspectionProfiles/Project_Default.xml b/Lab2_AibesMedziai/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..512ec97 --- /dev/null +++ b/Lab2_AibesMedziai/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/Lab2_AibesMedziai/.idea/jarRepositories.xml b/Lab2_AibesMedziai/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/Lab2_AibesMedziai/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Lab2_AibesMedziai/.idea/jpa-buddy.xml b/Lab2_AibesMedziai/.idea/jpa-buddy.xml new file mode 100644 index 0000000..966d5f5 --- /dev/null +++ b/Lab2_AibesMedziai/.idea/jpa-buddy.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/Lab2_AibesMedziai/.idea/libraries/Maven__junit_junit_4_13.xml b/Lab2_AibesMedziai/.idea/libraries/Maven__junit_junit_4_13.xml new file mode 100644 index 0000000..59fc5c4 --- /dev/null +++ b/Lab2_AibesMedziai/.idea/libraries/Maven__junit_junit_4_13.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lab2_AibesMedziai/.idea/libraries/Maven__net_sf_jopt_simple_jopt_simple_4_6.xml b/Lab2_AibesMedziai/.idea/libraries/Maven__net_sf_jopt_simple_jopt_simple_4_6.xml new file mode 100644 index 0000000..18ea23b --- /dev/null +++ b/Lab2_AibesMedziai/.idea/libraries/Maven__net_sf_jopt_simple_jopt_simple_4_6.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lab2_AibesMedziai/.idea/libraries/Maven__org_apache_commons_commons_math3_3_2.xml b/Lab2_AibesMedziai/.idea/libraries/Maven__org_apache_commons_commons_math3_3_2.xml new file mode 100644 index 0000000..dde81ab --- /dev/null +++ b/Lab2_AibesMedziai/.idea/libraries/Maven__org_apache_commons_commons_math3_3_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lab2_AibesMedziai/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/Lab2_AibesMedziai/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/Lab2_AibesMedziai/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lab2_AibesMedziai/.idea/libraries/Maven__org_openjdk_jmh_jmh_core_1_25_2.xml b/Lab2_AibesMedziai/.idea/libraries/Maven__org_openjdk_jmh_jmh_core_1_25_2.xml new file mode 100644 index 0000000..4466f09 --- /dev/null +++ b/Lab2_AibesMedziai/.idea/libraries/Maven__org_openjdk_jmh_jmh_core_1_25_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lab2_AibesMedziai/.idea/libraries/Maven__org_openjdk_jmh_jmh_generator_annprocess_1_25_2.xml b/Lab2_AibesMedziai/.idea/libraries/Maven__org_openjdk_jmh_jmh_generator_annprocess_1_25_2.xml new file mode 100644 index 0000000..abc67f3 --- /dev/null +++ b/Lab2_AibesMedziai/.idea/libraries/Maven__org_openjdk_jmh_jmh_generator_annprocess_1_25_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lab2_AibesMedziai/.idea/misc.xml b/Lab2_AibesMedziai/.idea/misc.xml new file mode 100644 index 0000000..ecc7915 --- /dev/null +++ b/Lab2_AibesMedziai/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/Lab2_AibesMedziai/.idea/modules.xml b/Lab2_AibesMedziai/.idea/modules.xml new file mode 100644 index 0000000..a0c2fce --- /dev/null +++ b/Lab2_AibesMedziai/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Lab2_AibesMedziai/.idea/uiDesigner.xml b/Lab2_AibesMedziai/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/Lab2_AibesMedziai/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lab2_AibesMedziai/Lab2_AibesMedziai.iml b/Lab2_AibesMedziai/Lab2_AibesMedziai.iml new file mode 100644 index 0000000..3bdf9f4 --- /dev/null +++ b/Lab2_AibesMedziai/Lab2_AibesMedziai.iml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lab2_AibesMedziai/data/ban.txt b/Lab2_AibesMedziai/data/ban.txt new file mode 100644 index 0000000..089ce65 --- /dev/null +++ b/Lab2_AibesMedziai/data/ban.txt @@ -0,0 +1,22 @@ +Renault Laguna 2007 50000 1700.0 +Renault Megane 2011 20000 3500.0 +Toyota Corolla 2011 20000 8500.8 +Renault Laguna 2011 115900 7500.0 +Renault Megane 1946 365100 9500.0 +Honda Civic 2017 36400 8500.3 +Ford Focus 2019 40000 36000.0 +Ford Focus 2018 50000 34000.0 +Ford Focus 2017 60000 32000.0 +Ford Focus 2016 70000 30000.0 +Ford Focus 2015 80000 28000.0 +Ford Focus 2014 90000 26000.0 +Ford Focus 2013 100000 24000.0 +Ford Focus 2012 110000 22000.0 +Ford Focus 2011 120000 20000.0 +Ford Focus 2010 130000 18000.0 +Ford Focus 2009 140000 16000.0 +Ford Focus 2008 150000 14000.0 +Ford Mondeo 2019 37000 36000.0 +Fiat Bravo 2018 27000 36000.0 +Ford Fiesta 2019 37000 16000.0 +Audi A6 2016 87000 36000.0 diff --git a/Lab2_AibesMedziai/ktu.png b/Lab2_AibesMedziai/ktu.png new file mode 100644 index 0000000000000000000000000000000000000000..f54be2a75b7a85a079e3b7a975d39b571b095924 GIT binary patch literal 10254 zcmdUVcT`hNxA#G$NEH>4Dkz|IkR~OBB4DIR4jSU(wh{eNBOO>_ z3JR<++LQp^K3=cB6xz^<>fG|!brl6ru^ zV}P6#XjDsS6l4lLpZS^*{{=wSD?&a8kX0h^Pfg_11~N_qW}O!I zXMnqWfY~*_`2oN`bvMbI05FPWqb10Q0$9&mKD`B4O9AL!z2}MmToAZmrSe_^7~um1 zVft3Lf#M3FvF9xLJAjk|5Y&7c%mtkG2FyNQz3KrxNdhh?ZRkt?;3+)2zzupT>78^H zyM$tZ5h@@9nS?Z^Hb)@vi!}SN%S`YM5w=Pb^$;}6fJ1&=8;DaRbfw$ zSVTFMDc@29@yV6@_h*jhdQlFt05I+1+jq<>fMM{LBKEgCe#5bL+S-IX!xa~1^^RJ$ z49Hj<)8BN!`$qBg%c{}Qx!Ku~JMZO<%scdbjuFkKjrvEA_I#xeaob<&zp@A1Fb+^Y zz5AuPYfCkosWd6fh+G}_p9LC7iKiiIY!({4&S_yedU>aG}i}? z{*wn^r+5ztWu`=d;)gN>-cfvc#ukJ-D%Z}!T^hgQ0AQmA+4T83DWSi0&~&f+$vX5% zIfDc6w}M4G0)WXac7B}>4780D0B&Uja2LxlZZ%!vZ6s!DBEmM2ADW3hk!OG3EPqy> z?14X%lNlE}Q2u&IcQG@!nZRdRW|2ls>yQ`+D*k5ON-Bs0^}ac2TGRE~fHSA%K9Zg{ zXB&G;aQ`{{Y6K}=Qt&QY)9use!q{2cpI*?sq7o%~TS)7<4y*2M<_(C`DT&Z~O4U(P zAAuWzhat7fLa_nwG$EfU$`q>d#2KC_y&?bfz(puI@?u8HC#O;dNVwSRg-aj=} zg*L&)ZDcvarSf16mDFrdU*;~lBLssu3xF&UhC>2@7olS+YDD@+Q%N)z9W%{vP5^#MVLx zgzpIJW3)D7t)L_`iH^IkT-47jT+dC|^nE^gVV&zM7h{fyYL$@XJ=^^Fgm^gWHcAtv zyj&+%xSE@qQ>R#Ca1cNx*LLUHy=%&d$R4891?^GoiCnVWi)s+b?Lz*1+ib?yHMiUw z>~q%=)9Ow9(^QeUlb&@8`%FFpM>5m=;mVOx zl~Qf%?&^NiJ(MJx0udU%v5>NmGMqA1VP@!I$XlLQUTFz?H*1(QlXd)nSGs0oi0e~NlqsByjp|$eAtR#6hOdx&-RW8&y=6<h6t$SxaH2f(N($dj4C-=xyZnRz`3RZHtUZoFALak3yD2ZJvLOqcYVJNeIhZR zHxFy^rMMOx8mu1zjc|AhXXq135OwdvDmYKw+P@WlYcd5Pq#;qncSn?4CZGSI^q6?H zNHw&T-^!qC5S|K$JyKzk;O8zBvwu`Sb-212`Ze_{`HVMRqQFOE2hZ0%&0E2_7vJ)q z{GxodOS?;`x;T#+1-8mx2Je!%D5myBI#QL6&DBR;_QQx@Dt>zWI5>+ee z$^Jn&n|H42$+fpHYgH*#CsHKSE+)IN+TDOi)(HhgN4<2E&u3GMDMu_J=B?a1(U!sQ zjz8FkRS2-ek+j=lUZRN%_{hrTbH3>qULWQrd55snw`%Bq)*%s(O5^EX?ZR}7zZ8G9 zo_?}=uKC<_ba{4&iasARe7+9-P~x4mqvtr;3@s5)h#oOoy7GBBx80xyYE?g>(6^4$ zOU*XGq^TpYsf@sOnOv7_F4$)oJG^SF0T(csDl^{?NoACwefGTY!Z=+5t>4IXtj8Q< zD6*p=2^(Ab7WKaBL9bQ6)#CglUz!nBe15`w0+l`G=vXP`lwRrT_KxDXKtlKR@tUA= zg{sU3>B?Hm-1eSsDX31C&X&%;j@VlNM49>Uu6^Gcqj&9&$jacjQ7!IBroDb#mq1r- z&}z`~0Cs@EK?|SdFYd-4*clh7+c~bb5%v=vkzA!JAFld5$lMRn(TW`6SyrZMyIg;q zy6(oVQ1coMcCRV&qVZ==#>EoCIjkcOsHOYll_iU@y zyz0ult#FHsY2rN-TXmj4E}jexrb$31>NdTQxDUAPsf!c7PS=ilI%`JVudNl-YSfx; z$*#(cDolh9LXD2GBkNedhmGzTn|)Yi9C2_^?{U<2B((xjWKv{j2xZ7}+D#b=iLX$n zqs7Bqh296foN08&Z;m?)=`ITR?hY;w_w*(9y-wIjh-t8UoPD&^xJ+L(-rC&CQs3?& zEM&5!cd**zj&)~V&zz#xn0?IZcm2eAuVh>MQ|>_weN4>BX~M+KLknTPaj@QGwYaUN z1^`|h0N@`40DC8(Tm%4DK>%1X0|3cH0H8xgn|@FN0A>l;Ejb;Jv6YEcUB=-zZPN|w z8#v+Iz>l=I3LD>m;xsp@4xj_P1?~k@(ZUN^?+^{WWv!-lfOa{sKB0RtxfAb^R#v)l zGlSl)eK)rNBD`*oL=pl(+5Tk(a9J}V0B9on4+#X){%rpjd720K+5S_K>Hz@0{ii$& z7S{OopOO_$@UxAVvc;!>f0TFt_~(DhKLPy)_+J2lfd3Xic%c6X=y&_C0Qu9_iJuPh z#;r|MuwMmB@GTbyZ*M6ficX=H|8(I$jTrChe{|vR_Ma{!)%&YJ;U*aamzdd;E)fIp z6eLV3#N0j6{BQE*Um`=X0e?@V{!;tDQ|V8;@sao)q2KavqtKsR{$~OG=JtOF>`&_a z=Jx*+r~eArpC0;W0sR%H{|eZDn`D0l=&vdJYZv&_Q-53N{(oh^S$eJb>6K@i?&Iac z3e=!)E>aF@gNq-uMT2|zZ?k{P|65!}4lt-snOzuKZ0Us`aKj@<)N zP_t}72#lcxzo$JEy>S|ZoMAOobc$5ZKmP><0Z7X{2|dPN-Bfz`;bmx3B5+Av#-9jS z^$5U5AYR`}is`Qjx-mP^XmD5e=LR)2+Iu2Nzo;?ht~{D?jUJ7!Sai|rRP=rJ2|7M4 zB&B*|WJB!Q1m$U-Vtty8vM)Q=f&(ASzBPT=rA}lk&~VYK;Edi*GzYVi;$W_{s8+D&kSHjl8)#2Qz4CC#>i*CA#^X*X0y zT~RUUa(i0PPb(!kVS_oJb{4pt!P7fv-_<)sMtrWnz7tZ_7;#;5G~@s~zK5HSjSgzr z_p?|Nfl7BnIW30^)Cba<$?%<7(aU-Zjz4F84{V7wt&rRn0b>=AOQF5<7&SaWi62C* z7F|SC0e#_$!owrdhY<&tLn6Zn@dN3YuF=zBj~Cd5H3&iV9vy;~y%k<8bR>A9^jd4V zO)RmuC*=}=j*`xutsXS!KpUlcj1f%c;6ebm9)pe|qg1+)H96dJUX9O^FA+G4mYzd` zukt7}w&7+YI}TIOo$0~s^$c7(;}sseNp5`@VOI>+r6QEzKn1s)5mQ%0&O@6(F zG-AAaW6jY+AgK$$b8$?a!cv5 z4d|<8Msf86n#V8HEo|^EnyejzdNq8%K)?#0wzK7)YS3ItB_IYTvD+jNQ&8ZEnx}gn zL5b&R93zK>2nC*9R&Vpp4%NSY8deyhWaHU`1N(rFzFz9Gn5~4{^IRx9+9G zxFW795wqAGR$g%F@5C0{tYOS>*Hkx8S+1YJ<zibCp+>f5k`7(2U%>Z62aAuy1P$bN8G+s|R%5oE}dic(v{ z4@1kolbOR4=ud8bKlJgMQ>O23V9{!BNSnsmFYwi{lM7>OBc`69D*I~HD*B=<$ffy_ zf$#a#ERc9u(>Ex#q=exEfdv??E^S|%MjLRV?6Z-v1fk@M*qtIN5%nN;)4DCW;!_2% z=#*w5H?~R>QEa9-3?o0zVkvILo5HWh2u%ZHi;K|O!J=nYdKg-?W=b_kDAma9Yj(ty z)uNG(-25PYVrbk3YEG@RFRywx*->k+a}9>vrv;PlU1zMZ>Bs}|9)|Df zfiuFBF~eh7-*+^$r~3V);6zPiyg6G0@R`pItqyuOOOqiUsoi7^5_iT#-;}+dHlRZt ze8&cw5sBF+yXBN+jU^DrQVhw_6&#ppc^s&9^jcHJ9F{2ea)IwDaCh7R&|{fs7i(q& zuIJi*tN`tb!T`~XW5BA3>o^NB$bIBytSN)TtLg+|RdVDBcTGc@t6|g4$*S8@8U>0<2ewzO65IW z$L3!rtWuL!HtW?tP>QJ==xCki-0lJ*tH(uF!{@TvJYMt{zCQeXbj;tS{w~$EYm?uQ zn&v=E$@u}H$$NL#yWbSe7!AC2xA3BTQ_%O(frNeN` zBJC%T=cp#0-bKN2qaBB|33%_QG?|to8Mupl)EtWxQwbR{STbVy&f$7_8e+(XF5e@z zjQ2tq1VAh(c~**GW08$2`+SxN&vYkDTkl?Z+dkG*7_=HCd1uraBldP3O@R6ASnjX3 zTh$0RIj|)LBSE_vn@+@-T|aQsXLMkphO4;Sj`GuzN-a5;9;GT?89OoyRuJt za^!UhB@A@}F&=eCAA(FLw$X6a4TJ3 zYrX53YQOL1_hz9z^>{KBcxWg+PS3j8LAHL>!?4&jv10R;N=!-TR>T*vjXP z1;OBq9vv4PQ(Te}DqQvoaucsV54D)ex^j{>H96^3z}HT})3{{ixo@#2cPw)-CjGR~ z;8-T*FvzsJ3c!m7jczd`#EoX9&PjFeTU{oZs96dV1p)bp+EzD&t;y(DHJFRr zx6ww>gGN8MuD)%E^YI;TJerhHm-4P$I({KmjLf8c<2vHAp3y8s2sGUhT8=1JYgiZ&GP9jjNIMY%^LkggROjWx8CA{4%z@9Vy} zvwS5bsR=B(JCwq`ZVg@`HkcagRNUT6Jm4LN05*LFLq$f<2WxK1Z1u*>~;6 z8C-cnY_MXnCKo+LwlZ!TAl(BN&zF%xFTvt%Bg=eEL*(SUn7UNwuJX_cjZ2L0^3?@c zPt0T0jkTuLjDyX+WQD5UQ8Fu-I?L*K+gh&`q;0N@gU)BDT0NSHWAD3lEx&h!e#~|c zny|6+RrpXaVOsICHqV_7F=}t@u&JjH^P=F9dg4j{5v3Ql_X>e$oG;x)xNFz3;g@dN zfjSxkmxfnDz=$P3)0bv~;#dtx{f@IqL)KzxirT%;DoBcp#$*m@ZWp&jl?@)}xE6;T z?Z2Ack1I-YH%$;-p##uyX4w~8h#KsZcQRKMv0J1q34xxqjW~_|^$m=vUie~DpoQC{ zMXeR2-ffnH+}}*GSZ3AFdve{SsmRu3q^RlCl;3CP22P%c;VU$dW%@qY#)JwDn2skR z-+q)~(r`x$fu`bKY#z`Yh~Q$C-4t($DXO~bNcm_JQ9ti4zz5ctpD&}A1=VWAwp)aM z>{~uNcr;XODsF>tJ2_IVH4$)3KiP0PogoHpgj*5AHU7*wkk!u*o*gVYzZ|`S^V?)K zYn!O=P8ccbW5AsOwJ|zJf3N}s-qm&H4KWpUUP3xFtbHvjYGU-00S_oE@TYwDP0Xf} zA(y6Rc0zszSDfIgL&Wj*pjBc#| zC~MfNT~FusdIg?~7sXW`V}g$ua;D-?^Wa?+IHJ@Vpv3G3$f+$=&-+Y?Heh%gl*%=3 znd)BZ1B?2%>gj?thOCDnHbt}(Ivcx%(M&ssX`6iSmnybQtsK|p$Qs2YzCAa5tl=%# ze}&lCdLpZCWAL!)gfZJ#Oc4F8gzr3RfY+U65M;k)$18F=(8(VrT-Zdu(cBAFdGbX} z)MgkR5x+YbL%B9wJYFQ%yPndv!VM6?&&jIQuk=~ifb|dmdDOxvR!*(OzJXZf@%lon zL>xU>5#&229qm?nCeB9kR`5id`h1|OQkXH`y-MnLNs-v1{&i_oq{a5f&U1JwglD-HB)me} zq*LpMH%Bst54LbL;BKSAc^7MxrZ zIsl9IbJui_NucgXp7V9vQ7Cs-%(1lC<|h*nFE#CKT@qP+1O|!P-|!|iPtCc);k|?K zDM6gA;=<@5hw3mrD(2D71x;|ArI`1zK6ogpAfz=-9_ZaoNtN-3NvX@fKE3B&z5tt zuYPf|mGgqWPag7?X&V;`7@@I(znw6T?jxHz834&|@WnO+7QqufIFm-hhd(426K9qt z+^oAJg{nd;D%eNmt!zdeJXR?g+hR(81_y6KnwJRN20tu)ldFx0uPl;_G&^z*@L$7F zr%2lkDzq6q=4z}R7XS?@&cd)mH@2eIOb3uJtoo5kE*l*uCj|>WYULtUK0C{}N9$T; zVEjg<+H9a>zWjGmN->2&EG3dA-)$F)PFoGk)UP!=Ft$Rj9`|=r_#4mi5`6y3S=9R! zJQ(y5O}id@O6G8`w(T@zPqpEO$)A{CZrPF|eHe9=0{OAfuvHmpu+J=5{#01N2+TWV zJDMERqF-MKlREF6++Z5*`tk$9^s={|(w27bft2y)h-%uIAsJ1Xkw)J$dO&$|H1N=A za&tKadzqr_5!z&a`}_hmH*--y0tLv(a@+D-rS=xynPhDbXXj3V(Yev%bRu-Z*^Q~w z)*t`^;~>t()7Gg-b4KuhY#BL0H1~iI2RV-d%{5Q$^Ge(HdE}Qin+eBXuq?X_DbCMD zPfIS#Z!5T)c4FIVn;nz9ZGi83AZ1WD+rR1?CKnW^8dMa-VAETd7VO7cNDc&7oXS0vTa_b`M4a-g|e)Nj>N9thhS*?PYUiy#74AS$Q+l^4wq!T;yr zYlGj{*u|FXlyckk;AQC-KH>j~pM3CDCHR9~zGcY2@MpTS=>PS_9q-%;3Gnom!0SuU SA^iXR0GOistwMRTz<&eD*|zEc literal 0 HcmV?d00001 diff --git a/Lab2_AibesMedziai/pom.xml b/Lab2_AibesMedziai/pom.xml new file mode 100644 index 0000000..0d6f33d --- /dev/null +++ b/Lab2_AibesMedziai/pom.xml @@ -0,0 +1,181 @@ + + + + 4.0.0 + + edu.ktu.ds + lab2 + 1.0 + jar + + Lab2 + + + + + + org.openjdk.jmh + jmh-core + ${jmh.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + provided + + + junit + junit + 4.13 + test + + + + + + UTF-8 + UTF-8 + + 1.25.2 + + + 1.8 + + + benchmarks + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + ${javac.target} + ${javac.target} + ${javac.target} + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + package + + shade + + + ${uberjar.name} + + + org.openjdk.jmh.Main + + + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + + + + + maven-clean-plugin + 2.5 + + + maven-deploy-plugin + 2.8.1 + + + maven-install-plugin + 2.5.1 + + + maven-jar-plugin + 2.4 + + + maven-javadoc-plugin + 2.9.1 + + + maven-resources-plugin + 2.6 + + + maven-site-plugin + 3.3 + + + maven-source-plugin + 2.2.1 + + + maven-surefire-plugin + 2.17 + + + + + + diff --git a/Lab2_AibesMedziai/src/benchmark/java/edu/ktu/ds/lab2/AddAllBenchmark.java b/Lab2_AibesMedziai/src/benchmark/java/edu/ktu/ds/lab2/AddAllBenchmark.java new file mode 100644 index 0000000..f980a74 --- /dev/null +++ b/Lab2_AibesMedziai/src/benchmark/java/edu/ktu/ds/lab2/AddAllBenchmark.java @@ -0,0 +1,88 @@ +package edu.ktu.ds.lab2; + +import edu.ktu.ds.lab2.utils.AvlSet; +import edu.ktu.ds.lab2.utils.BstSet; +import edu.ktu.ds.lab2.utils.Set; +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.infra.Blackhole; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +// https://github.com/dastruktu/benchmark/blob/master/src/main/java/edu/ktu/ds/benchmark/JmhBenchmark.java +@BenchmarkMode(Mode.AverageTime) +@State(Scope.Benchmark) +@OutputTimeUnit(TimeUnit.MICROSECONDS) +@Warmup(time = 1, timeUnit = TimeUnit.SECONDS) +@Measurement(time = 1, timeUnit = TimeUnit.SECONDS) +public class AddAllBenchmark { + /* + Benchmark (listSize) Mode Cnt Score Error Units + AddAllBenchmark.avlSetAddAll 4000 avgt 5 12274.192 ± 1052.512 us/op + AddAllBenchmark.avlSetAddAll 8000 avgt 5 53572.221 ± 4584.040 us/op + AddAllBenchmark.avlSetAddAll 16000 avgt 5 199682.597 ± 19894.433 us/op + AddAllBenchmark.avlSetAddAll 32000 avgt 5 787332.020 ± 51936.079 us/op + AddAllBenchmark.avlSetAddAll 64000 avgt 5 2572856.880 ± 71156.461 us/op + AddAllBenchmark.avlSetAddAll 128000 avgt 5 7860938.300 ± 771355.219 us/op + AddAllBenchmark.bstSetAddAll 4000 avgt 5 499094.557 ± 444521.742 us/op + AddAllBenchmark.bstSetAddAll 8000 avgt 5 3312173.700 ± 200121.728 us/op + AddAllBenchmark.bstSetAddAll 16000 avgt 5 25703766.940 ± 551969.795 us/op + */ + + public int chunkSize = 200; + + @Param({"4000", "8000", "16000", "32000", "64000", "128000"}) + public int listSize; + + ArrayList> chunks; + BstSet bstSet; + AvlSet avlSet; + + @Setup(Level.Trial) + public void generateChunks() { + chunks = new ArrayList<>(); + chunks.ensureCapacity(listSize/chunkSize); + Random r = new Random(); + for (int i = 0; i < listSize/chunkSize; i++) { + Set chunk = new AvlSet<>(); + for (int j = 0; j < listSize; j++) { + chunk.add(r.nextInt(100_000)); + } + chunks.add(chunk); + } + } + + @Setup(Level.Iteration) + public void createSets() { + bstSet = new BstSet<>(); + avlSet = new AvlSet<>(); + } + + @Benchmark + public void bstSetAddAll(Blackhole bh) { + for (Set chunk : chunks) { + bstSet.addAll(chunk); + } + } + + @Benchmark + public void avlSetAddAll(Blackhole bh) { + for (Set chunk : chunks) { + avlSet.addAll(chunk); + } + } + + public static void main(String[] args) throws RunnerException { + Options opt = new OptionsBuilder() + .include(AddAllBenchmark.class.getSimpleName()) + .forks(1) + .build(); + new Runner(opt).run(); + } +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/Benchmark.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/Benchmark.java new file mode 100644 index 0000000..c127206 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/Benchmark.java @@ -0,0 +1,96 @@ +package edu.ktu.ds.lab2.demo; + +import edu.ktu.ds.lab2.utils.AvlSet; +import edu.ktu.ds.lab2.utils.BstSet; +import edu.ktu.ds.lab2.utils.BstSetIterative; +import edu.ktu.ds.lab2.utils.SortedSet; +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.infra.BenchmarkParams; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +import java.util.concurrent.TimeUnit; + +@BenchmarkMode(Mode.AverageTime) +@State(Scope.Benchmark) +@OutputTimeUnit(TimeUnit.MICROSECONDS) +@Warmup(time = 1, timeUnit = TimeUnit.SECONDS) +@Measurement(time = 1, timeUnit = TimeUnit.SECONDS) +public class Benchmark { + + @State(Scope.Benchmark) + public static class FullSet { + + Car[] cars; + BstSet carSet; + + @Setup(Level.Iteration) + public void generateElements(BenchmarkParams params) { + cars = Benchmark.generateElements(Integer.parseInt(params.getParam("elementCount"))); + } + + @Setup(Level.Invocation) + public void fillCarSet(BenchmarkParams params) { + carSet = new BstSet<>(); + addElements(cars, carSet); + } + } + + @Param({"10000", "20000", "40000", "80000"}) + public int elementCount; + + Car[] cars; + + @Setup(Level.Iteration) + public void generateElements() { + cars = generateElements(elementCount); + } + + static Car[] generateElements(int count) { + return new CarsGenerator().generateShuffle(count, 1.0); + } + + @org.openjdk.jmh.annotations.Benchmark + public BstSet addBstRecursive() { + BstSet carSet = new BstSet<>(Car.byPrice); + addElements(cars, carSet); + return carSet; + } + + @org.openjdk.jmh.annotations.Benchmark + public BstSetIterative addBstIterative() { + BstSetIterative carSet = new BstSetIterative<>(Car.byPrice); + addElements(cars, carSet); + return carSet; + } + + @org.openjdk.jmh.annotations.Benchmark + public AvlSet addAvlRecursive() { + AvlSet carSet = new AvlSet<>(Car.byPrice); + addElements(cars, carSet); + return carSet; + } + + @org.openjdk.jmh.annotations.Benchmark + public void removeBst(FullSet carSet) { + for (Car car : carSet.cars) { + carSet.carSet.remove(car); + } + } + + public static void addElements(Car[] carArray, SortedSet carSet) { + for (Car car : carArray) { + carSet.add(car); + } + } + + public static void main(String[] args) throws RunnerException { + Options opt = new OptionsBuilder() + .include(Benchmark.class.getSimpleName()) + .forks(1) + .build(); + new Runner(opt).run(); + } +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/Car.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/Car.java new file mode 100644 index 0000000..0d61829 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/Car.java @@ -0,0 +1,227 @@ +package edu.ktu.ds.lab2.demo; + +import edu.ktu.ds.lab2.utils.Ks; +import edu.ktu.ds.lab2.utils.Parsable; + +import java.time.LocalDate; +import java.util.*; + +/** + * @author EK + */ +public final class Car implements Parsable { + + // bendri duomenys visiems automobiliams (visai klasei) + private static final int minYear = 2000; + private static final int currentYear = LocalDate.now().getYear(); + private static final double minPrice = 100.0; + private static final double maxPrice = 333000.0; + private static final String idCode = "TA"; // ***** nauja + private static int serNr = 100; // ***** nauja + + private final String carRegNr; + + private String make = ""; + private String model = ""; + private int year = -1; + private int mileage = -1; + private double price = -1.0; + + public Car() { + carRegNr = idCode + (serNr++); // suteikiamas originalus carRegNr + } + + public Car(String make, String model, int year, int mileage, double price) { + carRegNr = idCode + (serNr++); // suteikiamas originalus carRegNr + this.make = make; + this.model = model; + this.year = year; + this.mileage = mileage; + this.price = price; + validate(); + } + + public Car(String dataString) { + carRegNr = idCode + (serNr++); // suteikiamas originalus carRegNr + this.parse(dataString); + validate(); + } + + public Car(Builder builder) { + carRegNr = idCode + (serNr++); // suteikiamas originalus carRegNr + this.make = builder.make; + this.model = builder.model; + this.year = builder.year; + this.mileage = builder.mileage; + this.price = builder.price; + validate(); + } + + public Car create(String dataString) { + return new Car(dataString); + } + + private void validate() { + String errorType = ""; + if (year < minYear || year > currentYear) { + errorType = "Netinkami gamybos metai, turi būti [" + + minYear + ":" + currentYear + "]"; + } + if (price < minPrice || price > maxPrice) { + errorType += " Kaina už leistinų ribų [" + minPrice + + ":" + maxPrice + "]"; + } + + if (!errorType.isEmpty()) { + Ks.ern("Automobilis yra blogai sugeneruotas: " + errorType + ". " + this); + } + } + + @Override + public void parse(String dataString) { + try { // duomenys, atskirti tarpais + Scanner scanner = new Scanner(dataString); + make = scanner.next(); + model = scanner.next(); + year = scanner.nextInt(); + setMileage(scanner.nextInt()); + setPrice(scanner.nextDouble()); + } catch (InputMismatchException e) { + Ks.ern("Blogas duomenų formatas -> " + dataString); + } catch (NoSuchElementException e) { + Ks.ern("Trūksta duomenų -> " + dataString); + } + } + + @Override + public String toString() { // papildyta su carRegNr + return getCarRegNr() + "=" + make + "_" + model + ":" + year + " " + getMileage() + " " + String.format("%4.1f", price); + } + + public String getMake() { + return make; + } + + public String getModel() { + return model; + } + + public int getYear() { + return year; + } + + public int getMileage() { + return mileage; + } + + public void setMileage(int mileage) { + this.mileage = mileage; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + public String getCarRegNr() { //** nauja. + return carRegNr; + } + + @Override + public int compareTo(Car car) { + return getCarRegNr().compareTo(car.getCarRegNr()); + } + + public static Comparator byMake = (Car c1, Car c2) -> c1.make.compareTo(c2.make); // pradžioje pagal markes, o po to pagal modelius + + public static Comparator byPrice = (Car c1, Car c2) -> { + // didėjanti tvarka, pradedant nuo mažiausios + if (c1.price < c2.price) { + return -1; + } + if (c1.price > c2.price) { + return +1; + } + return 0; + }; + + public static Comparator byYearPrice = (Car c1, Car c2) -> { + // metai mažėjančia tvarka, esant vienodiems lyginama kaina + if (c1.year > c2.year) { + return +1; + } + if (c1.year < c2.year) { + return -1; + } + if (c1.price > c2.price) { + return +1; + } + if (c1.price < c2.price) { + return -1; + } + return 0; + }; + + // Car klases objektų gamintojas (builder'is) + public static class Builder { + + private final static Random RANDOM = new Random(1949); // Atsitiktinių generatorius + private final static String[][] MODELS = { // galimų automobilių markių ir jų modelių masyvas + {"Mazda", "3", "6", "CX-3", "MX-5"}, + {"Ford", "Fiesta", "Kuga", "Focus", "Galaxy", "Mondeo"}, + {"VW", "Golf", "Jetta", "Passat", "Tiguan"}, + {"Honda", "HR-V", "CR-V", "Civic", "Jazz"}, + {"Renault", "Clio", "Megane", "Twingo", "Scenic"}, + {"Peugeot", "208", "308", "508", "Partner"}, + {"Audi", "A3", "A4", "A6", "A8", "Q3", "Q5"} + }; + + private String make = ""; + private String model = ""; + private int year = -1; + private int mileage = -1; + private double price = -1.0; + + public Car build() { + return new Car(this); + } + + public Car buildRandom() { + int ma = RANDOM.nextInt(MODELS.length); // markės indeksas 0.. + int mo = RANDOM.nextInt(MODELS[ma].length - 1) + 1;// modelio indeksas 1.. + return new Car(MODELS[ma][0], + MODELS[ma][mo], + 2000 + RANDOM.nextInt(22),// metai tarp 2000 ir 2021 + 6000 + RANDOM.nextInt(222000),// rida tarp 6000 ir 228000 + 800 + RANDOM.nextDouble() * 88000);// kaina tarp 800 ir 88800 + } + + public Builder year(int year) { + this.year = year; + return this; + } + + public Builder make(String make) { + this.make = make; + return this; + } + + public Builder model(String model) { + this.model = model; + return this; + } + + public Builder mileage(int mileage) { + this.mileage = mileage; + return this; + } + + public Builder price(double price) { + this.price = price; + return this; + } + } +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/CarMarket.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/CarMarket.java new file mode 100644 index 0000000..3d5c6c1 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/CarMarket.java @@ -0,0 +1,29 @@ +package edu.ktu.ds.lab2.demo; + +import edu.ktu.ds.lab2.utils.BstSet; +import edu.ktu.ds.lab2.utils.Set; + +public class CarMarket { + + public static Set duplicateCarMakes(Car[] cars) { + Set uni = new BstSet<>(Car.byMake); + Set duplicates = new BstSet<>(); + for (Car car : cars) { + int sizeBefore = uni.size(); + uni.add(car); + + if (sizeBefore == uni.size()) { + duplicates.add(car.getMake()); + } + } + return duplicates; + } + + public static Set uniqueCarModels(Car[] cars) { + Set uniqueModels = new BstSet<>(); + for (Car car : cars) { + uniqueModels.add(car.getModel()); + } + return uniqueModels; + } +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/CarsGenerator.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/CarsGenerator.java new file mode 100644 index 0000000..13eb33e --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/CarsGenerator.java @@ -0,0 +1,80 @@ +package edu.ktu.ds.lab2.demo; + +import edu.ktu.ds.lab2.gui.ValidationException; + +import java.util.Arrays; +import java.util.Collections; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +public class CarsGenerator { + + private int startIndex = 0, lastIndex = 0; + private boolean isStart = true; + + private Car[] cars; + + public Car[] generateShuffle(int setSize, double shuffleCoef) throws ValidationException { + return generateShuffle(setSize, setSize, shuffleCoef); + } + + /** + * @param setSize + * @param setTake + * @param shuffleCoef + * @return Gražinamas setSize ilgio Automobilių masyvas + * @throws ValidationException + */ + public Car[] generateShuffle(int setSize, + int setTake, + double shuffleCoef) throws ValidationException { + + Car[] cars = IntStream.range(0, setSize) + .mapToObj(i -> new Car.Builder().buildRandom()) + .toArray(Car[]::new); + return shuffle(cars, setTake, shuffleCoef); + } + + public Car takeCar() throws ValidationException { + if (lastIndex < startIndex) { + throw new ValidationException(String.valueOf(lastIndex - startIndex), 4); + } + // Vieną kartą Automobilis imamas iš masyvo pradžios, kitą kartą - iš galo. + isStart = !isStart; + return cars[isStart ? startIndex++ : lastIndex--]; + } + + private Car[] shuffle(Car[] cars, int amountToReturn, double shuffleCoef) throws ValidationException { + if (cars == null) { + throw new IllegalArgumentException("Automobilių nėra (null)"); + } + if (amountToReturn <= 0) { + throw new ValidationException(String.valueOf(amountToReturn), 1); + } + if (cars.length < amountToReturn) { + throw new ValidationException(cars.length + " >= " + amountToReturn, 2); + } + if ((shuffleCoef < 0) || (shuffleCoef > 1)) { + throw new ValidationException(String.valueOf(shuffleCoef), 3); + } + + int amountToLeave = cars.length - amountToReturn; + int startIndex = (int) (amountToLeave * shuffleCoef / 2); + + Car[] takeToReturn = Arrays.copyOfRange(cars, startIndex, startIndex + amountToReturn); + Car[] takeToLeave = Stream + .concat(Arrays.stream(Arrays.copyOfRange(cars, 0, startIndex)), + Arrays.stream(Arrays.copyOfRange(cars, startIndex + amountToReturn, cars.length))) + .toArray(Car[]::new); + + Collections.shuffle(Arrays.asList(takeToReturn) + .subList(0, (int) (takeToReturn.length * shuffleCoef))); + Collections.shuffle(Arrays.asList(takeToLeave) + .subList(0, (int) (takeToLeave.length * shuffleCoef))); + + this.startIndex = 0; + this.lastIndex = takeToLeave.length - 1; + this.cars = takeToLeave; + return takeToReturn; + } +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/DemoExecution.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/DemoExecution.java new file mode 100644 index 0000000..fec50fd --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/DemoExecution.java @@ -0,0 +1,13 @@ +package edu.ktu.ds.lab2.demo; + +import edu.ktu.ds.lab2.gui.MainWindow; + +/* + * Darbo atlikimo tvarka - čia yra pradinė Swing GUI klasė. + */ +public class DemoExecution { + + public static void main(String[] args) { + MainWindow.createAndShowGUI(); + } +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/ManualTest.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/ManualTest.java new file mode 100644 index 0000000..ac76233 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/demo/ManualTest.java @@ -0,0 +1,150 @@ +package edu.ktu.ds.lab2.demo; + +import edu.ktu.ds.lab2.utils.*; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.Locale; + +/* + * Aibės testavimas be Gui + * Dirbant su Intellij ir norint konsoleje matyti gražų pasuktą medį, + * reikia File -> Settings -> Editor -> File Encodings -> Global encoding pakeisti į UTF-8 + * + */ +public class ManualTest { + + static Car[] cars; + static ParsableSortedSet cSeries = new ParsableBstSet<>(Car::new, Car.byPrice); + + public static void main(String[] args) throws CloneNotSupportedException { + Locale.setDefault(Locale.US); // Suvienodiname skaičių formatus + executeTest(); + } + + public static void executeTest() throws CloneNotSupportedException { + Car c1 = new Car("Renault", "Laguna", 2007, 50000, 1700); + Car c2 = new Car.Builder() + .make("Renault") + .model("Megane") + .year(2011) + .mileage(20000) + .price(3500) + .build(); + Car c3 = new Car.Builder().buildRandom(); + Car c4 = new Car("Renault Laguna 2011 115900 700"); + Car c5 = new Car("Renault Megane 1946 365100 9500"); + Car c6 = new Car("Honda Civic 2011 36400 80.3"); + Car c7 = new Car("Renault Laguna 2011 115900 7500"); + Car c8 = new Car("Renault Megane 1946 365100 950"); + Car c9 = new Car("Honda Civic 2017 36400 850.3"); + + Car[] carsArray = {c9, c7, c8, c5, c1, c6}; + + Ks.oun("Auto Aibė:"); + ParsableSortedSet carsSet = new ParsableBstSet<>(Car::new); + + for (Car c : carsArray) { + carsSet.add(c); + Ks.oun("Aibė papildoma: " + c + ". Jos dydis: " + carsSet.size()); + } + Ks.oun(""); + Ks.oun(carsSet.toVisualizedString()); + + ParsableSortedSet carsSetCopy = (ParsableSortedSet) carsSet.clone(); + + carsSetCopy.add(c2); + carsSetCopy.add(c3); + carsSetCopy.add(c4); + Ks.oun("Papildyta autoaibės kopija:"); + Ks.oun(carsSetCopy.toVisualizedString()); + + c9.setMileage(10000); + + Ks.oun("Originalas:"); + Ks.ounn(carsSet.toVisualizedString()); + + Ks.oun("Ar elementai egzistuoja aibėje?"); + for (Car c : carsArray) { + Ks.oun(c + ": " + carsSet.contains(c)); + } + Ks.oun(c2 + ": " + carsSet.contains(c2)); + Ks.oun(c3 + ": " + carsSet.contains(c3)); + Ks.oun(c4 + ": " + carsSet.contains(c4)); + Ks.oun(""); + + Ks.oun("Ar elementai egzistuoja aibės kopijoje?"); + for (Car c : carsArray) { + Ks.oun(c + ": " + carsSetCopy.contains(c)); + } + Ks.oun(c2 + ": " + carsSetCopy.contains(c2)); + Ks.oun(c3 + ": " + carsSetCopy.contains(c3)); + Ks.oun(c4 + ": " + carsSetCopy.contains(c4)); + Ks.oun(""); + + Ks.oun("Automobilių aibė su iteratoriumi:"); + Ks.oun(""); + for (Car c : carsSet) { + Ks.oun(c); + } + Ks.oun(""); + Ks.oun("Automobilių aibė AVL-medyje:"); + ParsableSortedSet carsSetAvl = new ParsableAvlSet<>(Car::new); + for (Car c : carsArray) { + carsSetAvl.add(c); + } + Ks.ounn(carsSetAvl.toVisualizedString()); + + Ks.oun("Automobilių aibė su iteratoriumi:"); + Ks.oun(""); + for (Car c : carsSetAvl) { + Ks.oun(c); + } + + Ks.oun(""); + Ks.oun("Automobilių aibė su atvirkštiniu iteratoriumi:"); + Ks.oun(""); + Iterator iter = carsSetAvl.descendingIterator(); + while (iter.hasNext()) { + Ks.oun(iter.next()); + } + + Ks.oun(""); + Ks.oun("Automobilių aibės toString() metodas:"); + Ks.ounn(carsSetAvl); + + // Išvalome ir suformuojame aibes skaitydami iš failo + carsSet.clear(); + carsSetAvl.clear(); + + Ks.oun(""); + Ks.oun("Automobilių aibė DP-medyje:"); + carsSet.load("data\\ban.txt"); + Ks.ounn(carsSet.toVisualizedString()); + Ks.oun("Išsiaiškinkite, kodėl medis augo tik į vieną pusę."); + + Ks.oun(""); + Ks.oun("Automobilių aibė AVL-medyje:"); + carsSetAvl.load("data\\ban.txt"); + Ks.ounn(carsSetAvl.toVisualizedString()); + + Set carsSet4 = CarMarket.duplicateCarMakes(carsArray); + Ks.oun("Pasikartojančios automobilių markės:\n" + carsSet4); + + Set carsSet5 = CarMarket.uniqueCarModels(carsArray); + Ks.oun("Unikalūs automobilių modeliai:\n" + carsSet5); + } + + static ParsableSortedSet generateSet(int kiekis, int generN) { + cars = new Car[generN]; + for (int i = 0; i < generN; i++) { + cars[i] = new Car.Builder().buildRandom(); + } + Collections.shuffle(Arrays.asList(cars)); + + cSeries.clear(); + Arrays.stream(cars).limit(kiekis).forEach(cSeries::add); + return cSeries; + } +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/KsGui.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/KsGui.java new file mode 100644 index 0000000..6d4906f --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/KsGui.java @@ -0,0 +1,67 @@ +package edu.ktu.ds.lab2.gui; + +import javax.swing.*; +import java.awt.*; + +/** + * Klasė, skirta duomenų išvedimui į GUI + * + * @author darius + */ +public class KsGui { + + private static int lineNr; + private static boolean formatStartOfLine = true; + + public static void setFormatStartOfLine(boolean formatStartOfLine) { + KsGui.formatStartOfLine = formatStartOfLine; + } + + private static String getStartOfLine() { + return (formatStartOfLine) ? ++lineNr + "| " : ""; + } + + public static void oun(JTextArea ta, Object o) { + ou(ta, o); + ta.append(System.lineSeparator()); + } + + public static void ou(JTextArea ta, Object o) { + if (o instanceof Iterable) { + for (Object iterable : (Iterable) o) { + ta.append(iterable.toString() + System.lineSeparator()); + } + } else { + ta.append(o.toString()); + } + } + + public static void ou(JTextArea ta, Object o, String msg) { + ta.append(getStartOfLine() + msg + ": "); + oun(ta, o); + } + + public static void oun(JTextArea ta, Object o, String msg) { + ta.append(getStartOfLine() + msg + ": " + System.lineSeparator()); + oun(ta, o); + } + + public static void ounerr(JTextArea ta, Exception e) { + ta.setBackground(Color.pink); + ta.append(getStartOfLine() + e.toString() + System.lineSeparator()); + for (StackTraceElement ste : e.getStackTrace()) { + ta.append(ste.toString() + System.lineSeparator()); + } + ta.append(System.lineSeparator()); + } + + public static void ounerr(JTextArea ta, String msg) { + ta.setBackground(Color.pink); + ta.append(getStartOfLine() + msg + ". " + System.lineSeparator()); + } + + public static void ounerr(JTextArea ta, String msg, String parameter) { + ta.setBackground(Color.pink); + ta.append(getStartOfLine() + msg + ": " + parameter + System.lineSeparator()); + } +} \ No newline at end of file diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/MainWindow.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/MainWindow.java new file mode 100644 index 0000000..9a62d79 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/MainWindow.java @@ -0,0 +1,445 @@ +package edu.ktu.ds.lab2.gui; + +import edu.ktu.ds.lab2.demo.Car; +import edu.ktu.ds.lab2.demo.CarsGenerator; +import edu.ktu.ds.lab2.utils.Ks; +import edu.ktu.ds.lab2.utils.ParsableAvlSet; +import edu.ktu.ds.lab2.utils.ParsableBstSet; +import edu.ktu.ds.lab2.utils.ParsableSortedSet; + +import javax.swing.*; +import javax.swing.border.TitledBorder; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.AdjustmentEvent; +import java.io.File; +import java.util.Arrays; +import java.util.Collections; +import java.util.Random; +import java.util.ResourceBundle; +import java.util.stream.IntStream; + +/** + * Lab2 langas su Swing'u + *
+ *                  MainWindow (BorderLayout)
+ *  |-----------------------Center-------------------------|
+ *  |  |-----------------scrollOutput-------------------|  |
+ *  |  |  |------------------------------------------|  |  |
+ *  |  |  |                                          |  |  |
+ *  |  |  |                                          |  |  |
+ *  |  |  |                 taOutput                 |  |  |
+ *  |  |  |                                          |  |  |
+ *  |  |  |                                          |  |  |
+ *  |  |  |                                          |  |  |
+ *  |  |  |                                          |  |  |
+ *  |  |  |                                          |  |  |
+ *  |  |  |------------------------------------------|  |  |                                                              |  |
+ *  |  |------------------------------------------------|  |                                          |
+ *  |------------------------South-------------------------|
+ *  |  |~~~~~~~~~~~~~~~~~~~scrollSouth~~~~~~~~~~~~~~~~~~|  |
+ *  |  |                                                |  |
+ *  |  |    |------------||-----------||-----------|    |  |
+ *  |  |    | panButtons || panParam1 || panParam2 |    |  |
+ *  |  |    |            ||           ||           |    |  |
+ *  |  |    |------------||-----------||-----------|    |  |
+ *  |  |                                                |  |
+ *  |  |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|  |
+ *  |------------------------------------------------------|
+ * 
+ * + * @author darius.matulis@ktu.lt + */ +public class MainWindow extends JFrame implements ActionListener { + + private static final ResourceBundle MESSAGES = ResourceBundle.getBundle("edu.ktu.ds.lab2.gui.messages"); + private static final int TF_WIDTH = 8; + + private final JTextArea taOutput = new JTextArea(); + private final JScrollPane scrollOutput = new JScrollPane(taOutput); + private final JTextField tfInput = new JTextField(); + private final JComboBox cmbTreeType = new JComboBox<>(); + private final JPanel panSouth = new JPanel(); + private final JScrollPane scrollSouth = new JScrollPane(panSouth); + private final JPanel panParam2 = new JPanel(); + private MainWindowMenu mainWindowMenu; + private Panels panParam1, panButtons; + + private static ParsableSortedSet carsSet; + private final CarsGenerator carsGenerator = new CarsGenerator(); + + private int sizeOfInitialSubSet, sizeOfGenSet, sizeOfLeftSubSet; + private double shuffleCoef; + private final String[] errors; + + public MainWindow() { + errors = new String[]{ + MESSAGES.getString("badSetSize"), + MESSAGES.getString("badInitialData"), + MESSAGES.getString("badSetSizes"), + MESSAGES.getString("badShuffleCoef") + }; + initComponents(); + } + + private void initComponents() { + // Kad prijungiant tekstą prie JTextArea vaizdas visada nušoktų į apačią + scrollOutput.getVerticalScrollBar() + .addAdjustmentListener((AdjustmentEvent e) -> taOutput.select(taOutput.getCaretPosition() * taOutput.getFont().getSize(), 0)); + //====================================================================== + // Formuojamas mygtukų tinklelis (mėlynas). Naudojame klasę Panels. + //====================================================================== + // 4 eilutes, 2 stulpeliai + panButtons = new Panels( + new String[]{ + MESSAGES.getString("button1"), + MESSAGES.getString("button2"), + MESSAGES.getString("button3"), + MESSAGES.getString("button4"), + MESSAGES.getString("button5"), + MESSAGES.getString("button6")}, + 2, 3); + panButtons.getButtons().forEach((btn) -> btn.addActionListener(this)); + enableButtons(false); + //====================================================================== + // Formuojama pirmoji parametrų lentelė (žalia). Naudojame klasę Panels. + //====================================================================== + panParam1 = new Panels( + new String[]{ + MESSAGES.getString("lblParam11"), + MESSAGES.getString("lblParam12"), + MESSAGES.getString("lblParam13"), + MESSAGES.getString("lblParam14"), + MESSAGES.getString("lblParam15")}, + new String[]{ + MESSAGES.getString("tfParam11"), + MESSAGES.getString("tfParam12"), + MESSAGES.getString("tfParam13"), + MESSAGES.getString("tfParam14"), + MESSAGES.getString("tfParam15")}, + TF_WIDTH); + //====================================================================== + // Formuojama antroji parametrų lentelė (gelsva). + //====================================================================== + panParam2.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(3, 6, 3, 4); + // Išlygiavimas į kairę + c.anchor = GridBagConstraints.WEST; + // Komponentų išplėtimas iki maksimalaus celės dydžio + c.fill = GridBagConstraints.BOTH; + // Pirmas stulpelis + c.gridx = 0; + panParam2.add(new JLabel(MESSAGES.getString("lblParam21")), c); + panParam2.add(new JLabel(MESSAGES.getString("lblParam23")), c); + // Antras stulpelis + c.gridx = 1; + for (String s : new String[]{ + MESSAGES.getString("cmbTreeType1"), + MESSAGES.getString("cmbTreeType2"), + MESSAGES.getString("cmbTreeType3") + }) { + cmbTreeType.addItem(s); + } + cmbTreeType.addActionListener(this); + panParam2.add(cmbTreeType, c); + // Vėl pirmas stulpelis, tačiau plotis - 2 celės + c.gridx = 0; + c.gridwidth = 2; + tfInput.setEditable(false); + tfInput.setBackground(Color.lightGray); + panParam2.add(tfInput, c); + //====================================================================== + // Formuojamas bendras parametrų skydelis (tamsiai pilkas). + //====================================================================== + panSouth.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); + panSouth.add(panButtons); + panSouth.add(panParam1); + panSouth.add(panParam2); + + mainWindowMenu = new MainWindowMenu() { + @Override + public void actionPerformed(ActionEvent ae) { + try { + Object command = ae.getSource(); + if (command.equals(mainWindowMenu.getMenu(0).getItem(0))) { + fileChooseMenu(); + } else if (command.equals(mainWindowMenu.getMenu(0).getItem(1))) { + KsGui.ounerr(taOutput, MESSAGES.getString("notImplemented")); + } else if (command.equals(mainWindowMenu.getMenu(0).getItem(3))) { + System.exit(0); + } else if (command.equals(mainWindowMenu.getMenu(1).getItem(0))) { + JOptionPane.showOptionDialog(this, + MESSAGES.getString("author"), + MESSAGES.getString("menuItem21"), + JOptionPane.YES_NO_OPTION, + JOptionPane.INFORMATION_MESSAGE, + null, + new String[]{"OK"}, + null); + } + } catch (ValidationException e) { + KsGui.ounerr(taOutput, e.getMessage()); + } catch (Exception e) { + KsGui.ounerr(taOutput, MESSAGES.getString("systemError")); + e.printStackTrace(System.out); + } + } + }; + // Meniu juosta patalpinama lange + setJMenuBar(mainWindowMenu); + //====================================================================== + // Formuojamas Lab2 langas + //====================================================================== + JPanel mainWindow = new JPanel(); + mainWindow.setLayout(new BorderLayout()); + // ..centre ir pietuose talpiname objektus.. + mainWindow.add(scrollOutput, BorderLayout.CENTER); + mainWindow.add(scrollSouth, BorderLayout.SOUTH); + + // Šio freimo "turinyje" talpinamas Lab2 skydelis + getContentPane().add(mainWindow); + appearance(); + } + + private void appearance() { + // Grafinių objektų rėmeliai + TitledBorder outputBorder = new TitledBorder(MESSAGES.getString("border1")); + outputBorder.setTitleFont(new Font(Font.SANS_SERIF, Font.BOLD, 11)); + scrollOutput.setBorder(outputBorder); + TitledBorder southBorder = new TitledBorder(MESSAGES.getString("border2")); + southBorder.setTitleFont(new Font(Font.SANS_SERIF, Font.BOLD, 11)); + scrollSouth.setBorder(southBorder); + + panParam2.setBackground(new Color(255, 255, 153));// Gelsva + panParam1.setBackground(new Color(204, 255, 204));// Šviesiai žalia + panParam1.getTfOfTable().get(2).setEditable(false); + panParam1.getTfOfTable().get(2).setForeground(Color.red); + panParam1.getTfOfTable().get(4).setEditable(false); + panParam1.getTfOfTable().get(4).setBackground(Color.lightGray); + panButtons.setBackground(new Color(112, 162, 255)); // Blyškiai mėlyna + panSouth.setBackground(Color.GRAY); + taOutput.setFont(Font.decode("courier new-12")); + taOutput.setEditable(false); + } + + @Override + public void actionPerformed(ActionEvent ae) { + try { + System.gc(); + System.gc(); + System.gc(); + taOutput.setBackground(Color.white); + + Object source = ae.getSource(); + if (source instanceof JButton) { + handleButtons(source); + } else if (source instanceof JComboBox && source.equals(cmbTreeType)) { + enableButtons(false); + } + } catch (ValidationException e) { + if (e.getCode() >= 0 && e.getCode() <= 3) { + KsGui.ounerr(taOutput, errors[e.getCode()] + ": " + e.getMessage()); + if (e.getCode() == 2) { + panParam1.getTfOfTable().get(0).setBackground(Color.red); + panParam1.getTfOfTable().get(1).setBackground(Color.red); + } + } else if (e.getCode() == 4) { + KsGui.ounerr(taOutput, MESSAGES.getString("allSetIsPrinted")); + } else { + KsGui.ounerr(taOutput, e.getMessage()); + } + } catch (UnsupportedOperationException e) { + KsGui.ounerr(taOutput, e.getLocalizedMessage()); + } catch (Exception e) { + KsGui.ounerr(taOutput, MESSAGES.getString("systemError")); + e.printStackTrace(System.out); + } + } + + private void handleButtons(Object source) throws ValidationException { + if (source.equals(panButtons.getButtons().get(0))) { + treeGeneration(null); + } else if (source.equals(panButtons.getButtons().get(1))) { + treeIteration(); + } else if (source.equals(panButtons.getButtons().get(2))) { + treeAdd(); + } else if (source.equals(panButtons.getButtons().get(3))) { + treeRemove(); + } else if (source.equals(panButtons.getButtons().get(4)) + || source.equals(panButtons.getButtons().get(5))) { + KsGui.setFormatStartOfLine(true); + KsGui.ounerr(taOutput, MESSAGES.getString("notImplemented")); + KsGui.setFormatStartOfLine(false); + } + } + + public void treeGeneration(String filePath) throws ValidationException { + // Nuskaitomi uždavinio parametrai + readTreeParameters(); + // Sukuriamas aibės objektas, priklausomai nuo medžio pasirinkimo + // cmbTreeType objekte + createTree(); + + Car[] carsArray; + // Jei failas nenurodytas - generuojama + if (filePath == null) { + carsArray = carsGenerator.generateShuffle(sizeOfGenSet, sizeOfInitialSubSet, shuffleCoef); + panParam1.getTfOfTable().get(2).setText(String.valueOf(sizeOfLeftSubSet)); + } else { // Skaitoma is failo + carsSet.load(filePath); + carsArray = new Car[carsSet.size()]; + int i = 0; + for (Object o : carsSet.toArray()) { + carsArray[i++] = (Car) o; + } + // Skaitant iš failo išmaišoma standartiniu Collections.shuffle metodu. + Collections.shuffle(Arrays.asList(carsArray), new Random()); + } + + // Išmaišyto masyvo elementai surašomi i aibę + carsSet.clear(); + Arrays.stream(carsArray).forEach(a -> carsSet.add(a)); + + // Išvedami rezultatai + // Nustatoma, kad eilutės pradžioje neskaičiuotų išvedamų eilučių skaičiaus + KsGui.setFormatStartOfLine(true); + KsGui.oun(taOutput, carsSet.toVisualizedString(), + MESSAGES.getString("setInTree")); + // Nustatoma, kad eilutės pradžioje skaičiuotų išvedamų eilučių skaičių + KsGui.setFormatStartOfLine(false); + enableButtons(true); + } + + private void treeAdd() throws ValidationException { + KsGui.setFormatStartOfLine(true); + Car car = carsGenerator.takeCar(); + carsSet.add(car); + panParam1.getTfOfTable().get(2).setText(String.valueOf(--sizeOfLeftSubSet)); + KsGui.setFormatStartOfLine(true); + KsGui.oun(taOutput, car, MESSAGES.getString("setAdd")); + KsGui.oun(taOutput, carsSet.toVisualizedString()); + KsGui.setFormatStartOfLine(false); + } + + private void treeRemove() { + KsGui.setFormatStartOfLine(true); + if (carsSet.isEmpty()) { + KsGui.ounerr(taOutput, MESSAGES.getString("setIsEmpty")); + } else { + int nr = new Random().nextInt(carsSet.size()); + Car auto = (Car) carsSet.toArray()[nr]; + carsSet.remove(auto); + KsGui.oun(taOutput, auto, MESSAGES.getString("setRemoval")); + panParam1.getTfOfTable().get(2).setText(String.valueOf(++sizeOfLeftSubSet)); + } + KsGui.oun(taOutput, carsSet.toVisualizedString()); + KsGui.setFormatStartOfLine(false); + } + + private void treeIteration() { + KsGui.setFormatStartOfLine(true); + if (carsSet.isEmpty()) { + KsGui.ounerr(taOutput, MESSAGES.getString("setIsEmpty")); + } else { + KsGui.oun(taOutput, carsSet, MESSAGES.getString("setIterator")); + } + KsGui.setFormatStartOfLine(false); + } + + private void readTreeParameters() throws ValidationException { + // Truputėlis kosmetikos.. + for (int i = 0; i < 2; i++) { + panParam1.getTfOfTable().get(i).setBackground(Color.WHITE); + } + // Nuskaitomos parametrų reiksmės. Jei konvertuojant is String + // įvyksta klaida, sugeneruojama NumberFormatException situacija. Tam, kad + // atskirti kuriame JTextfield'e ivyko klaida, panaudojama nuosava + // situacija MyException + int i = 0; + try { + // Pakeitimas (replace) tam, kad sukelti situaciją esant + // neigiamam skaičiui + sizeOfGenSet = Integer.parseInt(panParam1.getParametersOfTable().get(i).replace("-", "x")); + sizeOfInitialSubSet = Integer.parseInt(panParam1.getParametersOfTable().get(++i).replace("-", "x")); + sizeOfLeftSubSet = sizeOfGenSet - sizeOfInitialSubSet; + ++i; + shuffleCoef = Double.parseDouble(panParam1.getParametersOfTable().get(++i).replace("-", "x")); + } catch (NumberFormatException e) { + // Galima ir taip: pagauti exception'ą ir vėl mesti + throw new ValidationException(panParam1.getParametersOfTable().get(i), e, i); + } + } + + private void createTree() throws ValidationException { + switch (cmbTreeType.getSelectedIndex()) { + case 0: + carsSet = new ParsableBstSet<>(Car::new); + break; + case 1: + carsSet = new ParsableAvlSet<>(Car::new); + break; + default: + enableButtons(false); + throw new ValidationException(MESSAGES.getString("notImplemented")); + } + } + + private void enableButtons(boolean enable) { + IntStream.rangeClosed(1, 5) + .filter(i -> i < panButtons.getButtons().size() && panButtons.getButtons().get(i) != null) + .forEachOrdered(i -> panButtons.getButtons().get(i).setEnabled(enable)); + } + + private void fileChooseMenu() throws ValidationException { + JFileChooser fc = new JFileChooser("."); + + // Nuimamas "all Files" filtras + // fc.setAcceptAllFileFilterUsed(false); + // Papildoma mūsų sukurtais filtrais + fc.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() { + @Override + public boolean accept(File file) { + String filename = file.getName(); + // Rodomos tik direktorijos ir txt failai + return file.isDirectory() || filename.endsWith(".txt"); + } + + @Override + public String getDescription() { + return "*.txt"; + } + }); + int returnVal = fc.showOpenDialog(this); + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = fc.getSelectedFile(); + treeGeneration(file.getAbsolutePath()); + } + } + + public static void createAndShowGUI() { + try { + UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName() + // Arba sitaip, tada swing komponentu isvaizda priklausys + // nuo naudojamos OS: + // UIManager.getSystemLookAndFeelClassName() + // Arba taip: + // "com.sun.java.swing.plaf.motif.MotifLookAndFeel" + // Linux'e dar taip: + // "com.sun.java.swing.plaf.gtk.GTKLookAndFeel" + ); + UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { + Ks.ou(ex.getMessage()); + } + MainWindow window = new MainWindow(); + window.setLocation(50, 50); + window.setIconImage(new ImageIcon(MESSAGES.getString("icon")).getImage()); + window.setTitle(MESSAGES.getString("title")); + window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + window.setPreferredSize(new Dimension(1100, 650)); + window.pack(); + window.setVisible(true); + } +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/MainWindowMenu.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/MainWindowMenu.java new file mode 100644 index 0000000..85e5c02 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/MainWindowMenu.java @@ -0,0 +1,56 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package edu.ktu.ds.lab2.gui; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.util.ResourceBundle; + +/** + * @author darius + */ +public abstract class MainWindowMenu extends JMenuBar implements ActionListener { + + private static final ResourceBundle MESSAGES = ResourceBundle.getBundle("edu.ktu.ds.lab2.gui.messages"); + + public MainWindowMenu() { + initComponents(); + } + + private void initComponents() { + // Sukuriama meniu juosta + JMenu jMenu1 = new JMenu(MESSAGES.getString("menu1")); + super.add(jMenu1); + JMenuItem jMenuItem11 = new JMenuItem(MESSAGES.getString("menuItem11")); + jMenuItem11.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK)); + JMenuItem jMenuItem12 = new JMenuItem(MESSAGES.getString("menuItem12")); + jMenuItem12.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK)); + JMenuItem jMenuItem13 = new JMenuItem(MESSAGES.getString("menuItem13")); + jMenuItem13.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_DOWN_MASK)); + + jMenu1.add(jMenuItem11); + jMenu1.add(jMenuItem12); + jMenu1.addSeparator(); + jMenu1.add(jMenuItem13); + + JMenu jMenu2 = new JMenu(MESSAGES.getString("menu2")); + super.add(jMenu2); + JMenuItem jMenuItem21 = new JMenuItem(MESSAGES.getString("menuItem21")); + jMenuItem21.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, InputEvent.SHIFT_DOWN_MASK)); + jMenu2.add(jMenuItem21); + + jMenuItem11.addActionListener(this); + jMenuItem12.addActionListener(this); + jMenuItem13.addActionListener(this); + jMenuItem21.addActionListener(this); + } + + @Override + public abstract void actionPerformed(ActionEvent e); +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/Panels.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/Panels.java new file mode 100644 index 0000000..c162f23 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/Panels.java @@ -0,0 +1,148 @@ +package edu.ktu.ds.lab2.gui; + +import javax.swing.*; +import javax.swing.text.JTextComponent; +import java.awt.*; +import java.util.List; +import java.util.Queue; +import java.util.*; +import java.util.stream.Collectors; + +/** + * Klasės objektu galima sukurti du panelius: parametrų lentelę ir mygtukų + * tinklelį. Panelyje talpinamų objektų kiekis nustatomas parametrais. + * + * @author darius.matulis@ktu.lt + */ +public class Panels extends JPanel { + + private final static int SPACING = 4; + private final List tfs = new ArrayList<>(); + private final List btns = new ArrayList<>(); + + /** + * Sukuriama parametrų lentelė (GridBag išdėstymo dėsnis) + *
+     * |-------------------------------|
+     * |                |------------| |
+     * |   lblTexts[0]  | tfTexts[0] | |
+     * |                |------------| |
+     * |                               |
+     * |                |------------| |
+     * |   lblTexts[1]  | tfTexts[1] | |
+     * |                |------------| |
+     * |      ...             ...      |
+     * |-------------------------------|
+     * 
+ * + * @param lblTexts + * @param tfTexts + * @param columnWidth + */ + public Panels(String[] lblTexts, String[] tfTexts, int columnWidth) { + super(); + if (lblTexts == null || tfTexts == null) { + throw new IllegalArgumentException("Arguments for table of parameters are incorrect"); + } + + if (lblTexts.length > tfTexts.length) { + tfTexts = Arrays.copyOf(tfTexts, lblTexts.length); + Arrays.fill(tfTexts, ""); + } + + initTableOfParameters(columnWidth, lblTexts, tfTexts); + } + + /** + * Sukuriamas mygtukų tinklelis (GridLayout išdėstymo dėsnis) + *
+     * |-------------------------------------|
+     * | |-------------| |-------------|     |
+     * | | btnNames[0] | | btnNames[1] | ... |
+     * | |-------------| |-------------|     |
+     * |                                     |
+     * | |-------------| |-------------|     |
+     * | | btnNames[2] | | btnNames[3] | ... |
+     * | |-------------| |-------------|     |
+     * |       ...              ...          |
+     * |-------------------------------------|
+     * 
+ * + * @param btnNames + * @param gridX + * @param gridY + */ + public Panels(String[] btnNames, int gridX, int gridY) { + super(); + if (btnNames == null || gridX < 1 || gridY < 1) { + throw new IllegalArgumentException("Arguments for buttons grid are incorrect"); + } + initGridOfButtons(gridX, gridY, btnNames); + } + + private void initTableOfParameters(int columnWidth, String[] lblTexts, String[] tfTexts) { + setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + // Spacing'as tarp komponentų + c.insets = new Insets(SPACING, SPACING, SPACING, SPACING); + // Lygiavimas į kairę + c.anchor = GridBagConstraints.WEST; + // Pasirenkamas pirmas stulpelis.. + c.gridx = 0; + // ..ir į jį sudedami labeliai + Arrays.stream(lblTexts).forEach((lblText) -> add(new JLabel(lblText), c)); + // Pasirenkamas antras stulpelis.. + c.gridx = 1; + // ..ir į jį sudedami textfieldai + + for (String tfText : tfTexts) { + JTextField tf = new JTextField(tfText, columnWidth); + tf.setHorizontalAlignment(JTextField.CENTER); + tf.setBackground(Color.WHITE); + tfs.add(tf); + add(tf, c); + } + } + + private void initGridOfButtons(int gridX, int gridY, String[] btnNames) { + setLayout(new GridLayout(gridY, gridX, SPACING, SPACING)); + Queue btnNamesQueue = new LinkedList<>(Arrays.asList(btnNames)); + for (int i = 0; i < gridX; i++) { + for (int j = 0; j < gridY; j++) { + if (btnNamesQueue.isEmpty()) { + break; + } + JButton button = new JButton(btnNamesQueue.poll()); + btns.add(button); + add(button); + } + } + } + + /** + * Gražinamas parametrų lentelės parametrų sąrašas + * + * @return Gražinamas parametrų lentelės parametrų sąrašas + */ + public List getParametersOfTable() { + return tfs.stream().map(JTextComponent::getText).collect(Collectors.toList()); + } + + /** + * Gražinamas parametrų lentelės JTextField objektų sąrašas + * + * @return Gražinamas parametrų lentelės JTextField objektų sąrašas + */ + public List getTfOfTable() { + return tfs; + } + + /** + * Gražinamas mygtukų tinklelio JButton objektų sąrašas + * + * @return Gražinamas mygtukų tinklelio JButton objektų sąrašas + */ + public List getButtons() { + return btns; + } +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/ValidationException.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/ValidationException.java new file mode 100644 index 0000000..6bcb700 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/gui/ValidationException.java @@ -0,0 +1,41 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package edu.ktu.ds.lab2.gui; + +/** + * Nuosava situacija, panaudota dialogo struktūrose įvedamų parametrų + * tikrinimui. + */ +public class ValidationException extends RuntimeException { + + // Situacijos kodas. Pagal ji programuojama programos reakcija į situaciją + private final int code; + + public ValidationException(String text) { + // (-1) - susitariama, kad tai neutralus kodas. + this(text, -1); + } + + public ValidationException(String message, int code) { + super(message); + if (code < -1) { + throw new IllegalArgumentException("Illegal code in Validation Exception: " + code); + } + this.code = code; + } + + public ValidationException(String message, Throwable throwable, int code) { + super(message, throwable); + if (code < -1) { + throw new IllegalArgumentException("Illegal code in MyException: " + code); + } + this.code = code; + } + + public int getCode() { + return code; + } +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/optional1/Main.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/optional1/Main.java new file mode 100644 index 0000000..e832059 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/optional1/Main.java @@ -0,0 +1,41 @@ +package edu.ktu.ds.lab2.optional1; + + +import edu.ktu.ds.lab2.utils.BstSet; + +public class Main { + public static void main(String[] args) { + int k = 2; + BstSet set = new BstSet<>(); + BstSet.BstNode a = set.getRoot(); + set.add(15); + set.add(23); + set.add(7); + set.add(4); + set.add(1); + set.add(9); + System.out.println(set.toVisualizedString()); + + System.out.println(IsBalanced(set.getRoot(), k) != -1); + } + + public static int IsBalanced(BstSet.BstNode node, int maxBalance) { + if (node.left == null && node.right == null) return 0; + + int leftHeight = -1; + int rightHeight = -1; + if (node.left != null) { + leftHeight = IsBalanced(node.left, maxBalance); + if (leftHeight == -1) return -1; + } + if (node.right != null) { + rightHeight = IsBalanced(node.right, maxBalance); + if (rightHeight == -1) return -1; + } + + if (Math.abs(leftHeight - rightHeight) >= maxBalance) return -1; + + return Math.max(leftHeight, rightHeight) + 1; + } + +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/optional2/Main.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/optional2/Main.java new file mode 100644 index 0000000..d590b5f --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/optional2/Main.java @@ -0,0 +1,86 @@ +package edu.ktu.ds.lab2.optional2; + +import edu.ktu.ds.lab2.utils.BstSet; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Stack; + +public class Main { + public static void main(String[] args) { + BstSet set = new BstSet<>(); + set.add(15); + set.add(23); + set.add(7); + set.add(4); + set.add(12); + set.add(19); + set.add(26); + set.add(1); + set.add(5); + set.add(9); + set.add(14); + set.add(16); + set.add(21); + set.add(25); + set.add(30); + System.out.println(set.toVisualizedString()); + System.out.println(getInnerValues(set)); + } + + public static > ArrayList getInnerValues(BstSet set) { + HashSet excludedValues = new HashSet<>(); + excludedValues.addAll(getLeftEdge(set)); + excludedValues.addAll(getRightEdge(set)); + excludedValues.addAll(getBottomEdge(set)); + + ArrayList innerValues = new ArrayList<>(); + for (E value : set) { + if (!excludedValues.contains(value)) { + innerValues.add(value); + } + } + return innerValues; + } + + public static > ArrayList getLeftEdge(BstSet set) { + ArrayList leftEdge = new ArrayList<>(); + BstSet.BstNode node = set.getRoot(); + while (node != null) { + leftEdge.add(node.element); + node = node.left; + } + return leftEdge; + } + + public static > ArrayList getRightEdge(BstSet set) { + ArrayList rightEdge = new ArrayList<>(); + BstSet.BstNode node = set.getRoot(); + while (node != null) { + rightEdge.add(node.element); + node = node.right; + } + return rightEdge; + } + + public static > ArrayList getBottomEdge(BstSet set) { + ArrayList bottomEdge = new ArrayList<>(); + Stack> stack = new Stack<>(); + stack.add(set.getRoot()); + while (!stack.isEmpty()) { + BstSet.BstNode node = stack.pop(); + if (node.left == null && node.right == null) { + bottomEdge.add(node.element); + } else { + if (node.left != null) { + stack.push(node.left); + } + if (node.right != null) { + stack.push(node.right); + } + } + } + return bottomEdge; + } + +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/AvlSet.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/AvlSet.java new file mode 100644 index 0000000..24aebf7 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/AvlSet.java @@ -0,0 +1,236 @@ +package edu.ktu.ds.lab2.utils; + +import java.util.Comparator; + +/** + * Rikiuojamos objektų kolekcijos - aibės realizacija AVL-medžiu. + * + * @param Aibės elemento tipas. Turi tenkinti interfeisą Comparable, arba + * per klasės konstruktorių turi būti paduodamas Comparator + * interfeisą tenkinantis objektas. + * @author darius.matulis@ktu.lt + * @užduotis Peržiūrėkite ir išsiaiškinkite pateiktus metodus. + */ +public class AvlSet> extends BstSet implements SortedSet { + + public AvlSet() { + } + + public AvlSet(Comparator c) { + super(c); + } + + /** + * Aibė papildoma nauju elementu. + * + * @param element + */ + @Override + public void add(E element) { + if (element == null) { + throw new IllegalArgumentException("Element is null in add(E element)"); + } + root = addRecursive(element, (AVLNode) root); + } + + /** + * Privatus rekursinis metodas naudojamas add metode; + * + * @param element + * @param node + * @return + */ + private AVLNode addRecursive(E element, AVLNode node) { + if (node == null) { + size++; + return new AVLNode<>(element); + } + int cmp = c.compare(element, node.element); + + if (cmp < 0) { + node.left = addRecursive(element, (AVLNode) node.left); + } else if (cmp > 0) { + node.right = addRecursive(element, (AVLNode) node.right); + } + + if (cmp != 0) { + int balance = getBalance(node); + if (balance >= 2) { + int cmp2 = c.compare(element, node.left.element); + node = (cmp2 < 0) ? rightRotation(node) : doubleRightRotation(node); + } else if (balance <= -2) { + int cmp2 = c.compare(node.right.element, element); + node = (cmp2 < 0) ? leftRotation(node) : doubleLeftRotation(node); + } + } + + node.updateHeight(); + return node; + } + + /** + * Pašalinamas elementas iš aibės. + * + * @param element + */ + @Override + public void remove(E element) { + if (element == null) { + throw new IllegalArgumentException("Element is null in remove(E element)"); + } + root = removeRecursive(element, (AVLNode) root); + } + + private int getBalance(AVLNode node) { + if (node == null) return 0; + return height((AVLNode) node.left) - height((AVLNode) node.right); + } + + private AVLNode removeRecursive(E element, AVLNode node) { + if (node == null) return null; + + int cmp = c.compare(element, node.element); + + if (cmp < 0) { + node.left = removeRecursive(element, (AVLNode) node.left); + } else if (cmp > 0) { + node.right = removeRecursive(element, (AVLNode) node.right); + } else { + size--; + if (node.left == null && node.right == null) { + node = null; + } else if (node.left != null && node.right != null) { + if (node.right.left != null) { + BstNode minimumParent = node; + BstNode minimumNode = node.right; + + while (minimumNode.left != null) { + minimumParent = minimumNode; + minimumNode = minimumNode.left; + } + + minimumParent.left = minimumNode.right; + node.element = minimumNode.element; + } else { + node.element = node.right.element; + node.right = node.right.right; + } + } else if (node.left != null) { + node = (AVLNode) node.left; + } else { // if (node.right != null) + node = (AVLNode) node.right; + } + } + + if (node != null) { + node.updateHeight(); + if (cmp != 0) { + int balance = getBalance(node); + if (balance >= 2) { + int hl = node.left.left != null ? ((AVLNode) node.left.left).height : -1; + int hr = node.left.right != null ? ((AVLNode) node.left.right).height : -1; + node = (hl >= hr) ? rightRotation(node) : doubleRightRotation(node); + } else if (balance <= -2) { + int hl = node.right.left != null ? ((AVLNode) node.right.left).height : -1; + int hr = node.right.right != null ? ((AVLNode) node.right.right).height : -1; + node = (hr >= hl) ? leftRotation(node) : doubleLeftRotation(node); + } + } + } + + return node; + } + + // Papildomi privatūs metodai, naudojami operacijų su aibe realizacijai + // AVL-medžiu; + + // n2 + // / n1 + // n1 ==> / \ + // / n3 n2 + // n3 + + private AVLNode rightRotation(AVLNode n2) { + AVLNode n1 = (AVLNode) n2.left; + n2.left = n1.right; + n1.right = n2; + n2.updateHeight(); + n1.updateHeight(); + return n1; + } + + private AVLNode leftRotation(AVLNode n1) { + AVLNode n2 = (AVLNode) n1.right; + n1.right = n2.left; + n2.left = n1; + n1.updateHeight(); + n2.updateHeight(); + return n2; + } + + // n3 n3 + // / / n2 + // n1 ==> n2 ==> / \ + // \ / n1 n3 + // n2 n1 + // + private AVLNode doubleRightRotation(AVLNode n3) { + n3.left = leftRotation((AVLNode) n3.left); + return rightRotation(n3); + } + + private AVLNode doubleLeftRotation(AVLNode n1) { + n1.right = rightRotation((AVLNode) n1.right); + return leftRotation(n1); + } + + public String serialize() { + return serialize((AVLNode) root); + } + + private String serialize(AVLNode node) { + StringBuilder builder = new StringBuilder(); + if (node.left == null && node.right == null) { + builder.append(node.element); + } else { + builder.append("("); + if (node.left != null) { + builder.append(serialize((AVLNode) node.left)); + } else { + builder.append("null"); + } + builder.append(","); + builder.append(node.element); + builder.append(","); + if (node.right != null) { + builder.append(serialize((AVLNode) node.right)); + } else { + builder.append("null"); + } + builder.append(")"); + } + return builder.toString(); + } + + private int height(AVLNode n) { + return (n == null) ? -1 : n.height; + } + + /** + * Vidinė kolekcijos mazgo klasė + * + * @param mazgo elemento duomenų tipas + */ + protected class AVLNode extends BstNode { + protected int height; + + protected AVLNode(N element) { + super(element); + this.height = 0; + } + + public void updateHeight() { + height = Math.max(height((AVLNode) this.left), height((AVLNode) this.right)) + 1; + } + } +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/BstSet.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/BstSet.java new file mode 100644 index 0000000..8ff8485 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/BstSet.java @@ -0,0 +1,501 @@ +package edu.ktu.ds.lab2.utils; + +import java.util.Comparator; +import java.util.Iterator; +import java.util.Stack; + +/** + * Rikiuojamos objektų kolekcijos - aibės realizacija dvejetainiu paieškos + * medžiu. + * + * @param Aibės elemento tipas. Turi tenkinti interfeisą Comparable, arba + * per klasės konstruktorių turi būti paduodamas Comparator interfeisą + * tenkinantis objektas. + * @author darius.matulis@ktu.lt + * @užduotis Peržiūrėkite ir išsiaiškinkite pateiktus metodus. + */ +public class BstSet> implements SortedSet, Cloneable { + + // Medžio šaknies mazgas + protected BstNode root = null; + // Medžio dydis + protected int size = 0; + // Rodyklė į komparatorių + protected Comparator c; + + /** + * Sukuriamas aibės objektas DP-medžio raktams naudojant Comparable + */ + public BstSet() { + this.c = Comparator.naturalOrder(); + } + + /** + * Sukuriamas aibės objektas DP-medžio raktams naudojant Comparator + * + * @param c Komparatorius + */ + public BstSet(Comparator c) { + this.c = c; + } + + /** + * Patikrinama ar aibė tuščia. + * + * @return Grąžinama true, jei aibė tuščia. + */ + @Override + public boolean isEmpty() { + return root == null; + } + + /** + * @return Grąžinamas aibėje esančių elementų kiekis. + */ + @Override + public int size() { + return size; + } + + /** + * Išvaloma aibė. + */ + @Override + public void clear() { + root = null; + size = 0; + } + + /** + * Patikrinama ar aibėje egzistuoja elementas. + * + * @param element - Aibės elementas. + * @return Grąžinama true, jei aibėje egzistuoja elementas. + */ + @Override + public boolean contains(E element) { + if (element == null) { + throw new IllegalArgumentException("Element is null in contains(E element)"); + } + + return get(element) != null; + } + + /** + * Patikrinama ar visi abės set elementai egzistuoja aibėje + * + * @param set aibė + * @return + */ + @Override + public boolean containsAll(Set set) { + for (E e : set) { + if (!contains(e)) { + return false; + } + } + return true; + } + + /** + * Aibė papildoma nauju elementu. + * + * @param element - Aibės elementas. + */ + @Override + public void add(E element) { + if (element == null) { + throw new IllegalArgumentException("Element is null in add(E element)"); + } + + root = addRecursive(element, root); + } + + /** + * Abės set elementai pridedami į esamą aibę, jeigu abi aibės turi tą patį elementą, jis nėra dedamas. + * + * @param set pridedamoji aibė + */ + @Override + public void addAll(Set set) { + for (E element : set) { + add(element); + } + } + + private BstNode addRecursive(E element, BstNode node) { + if (node == null) { + size++; + return new BstNode<>(element); + } + + int cmp = c.compare(element, node.element); + + if (cmp < 0) { + node.left = addRecursive(element, node.left); + } else if (cmp > 0) { + node.right = addRecursive(element, node.right); + } + + return node; + } + + /** + * Pašalinamas elementas iš aibės. + * + * @param element - Aibės elementas. + */ + @Override + public void remove(E element) { + if (element == null) { + throw new IllegalArgumentException("Element is null in remove(E element)"); + } + + root = removeRecursive(element, root); + } + + /** + * Aibėje lieka tik tie elementai, kurie yra aibėje set. + * + * @param set aibė + */ + @Override + public void retainAll(Set set) { + for (E e : this) { + if (!set.contains(e)) { + remove(e); + } + } + } + + private BstNode removeRecursive(E element, BstNode node) { + if (node == null) return null; + + int cmp = c.compare(element, node.element); + + if (cmp < 0) { + node.left = removeRecursive(element, node.left); + } else if (cmp > 0) { + node.right = removeRecursive(element, node.right); + } else { + size--; + if (node.left == null && node.right == null) { + return null; + } else if (node.left != null && node.right != null) { + if (node.right.left != null) { + BstNode minimumParent = node; + BstNode minimumNode = node.right; + + while (minimumNode.left != null) { + minimumParent = minimumNode; + minimumNode = minimumNode.left; + } + + minimumParent.left = minimumNode.right; + node.element = minimumNode.element; + } else { + node.element = node.right.element; + node.right = node.right.right; + } + } else if (node.left != null) { + return node.left; + } else { // if (node.right != null) + return node.right; + } + } + + return node; + } + + private E get(E element) { + if (element == null) { + throw new IllegalArgumentException("Element is null in get(E element)"); + } + + BstNode node = root; + while (node != null) { + int cmp = c.compare(element, node.element); + + if (cmp < 0) { + node = node.left; + } else if (cmp > 0) { + node = node.right; + } else { + return node.element; + } + } + + return null; + } + + /** + * Grąžinamas aibės elementų masyvas. + * + * @return Grąžinamas aibės elementų masyvas. + */ + @Override + public Object[] toArray() { + int i = 0; + Object[] array = new Object[size]; + for (Object o : this) { + array[i++] = o; + } + return array; + } + + /** + * Aibės elementų išvedimas į String eilutę Inorder (Vidine) tvarka. Aibės + * elementai išvedami surikiuoti didėjimo tvarka pagal raktą. + * + * @return elementų eilutė + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("["); + boolean isFirst = true; + for (E element : this) { + if (!isFirst) { + sb.append(", "); + } + sb.append(element.toString()); + isFirst = false; + } + sb.append("]"); + return sb.toString(); + } + + /** + * Medžio vaizdavimas simboliais, žiūr.: unicode.org/charts/PDF/U2500.pdf + * Tai 4 galimi terminaliniai simboliai medžio šakos gale + */ + private static final String[] term = {"\u2500", "\u2534", "\u252C", "\u253C"}; + private static final String rightEdge = "\u250C"; + private static final String leftEdge = "\u2514"; + private static final String endEdge = "\u25CF"; + private static final String vertical = "\u2502 "; + private String horizontal; + + /* Papildomas metodas, išvedantis aibės elementus į vieną String eilutę. + * String eilutė formuojama atliekant elementų postūmį nuo krašto, + * priklausomai nuo elemento lygio medyje. Galima panaudoti spausdinimui į + * ekraną ar failą tyrinėjant medžio algoritmų veikimą. + * + * @author E. Karčiauskas + */ + @Override + public String toVisualizedString() { + horizontal = term[0] + term[0]; + return root == null ? ">" + horizontal : toTreeDraw(root, ">", ""); + } + + private String toTreeDraw(BstNode node, String edge, String indent) { + if (node == null) { return ""; } + String step = (edge.equals(leftEdge)) ? vertical : " "; + StringBuilder sb = new StringBuilder(); + sb.append(toTreeDraw(node.right, rightEdge, indent + step)); + + int t = (node.right != null ? 1 : 0) + (node.left != null ? 2 : 0); + sb.append(indent).append(edge).append(horizontal); + sb.append(term[t]).append(endEdge).append(node.element.toString()); + sb.append(System.lineSeparator()); + step = (edge.equals(rightEdge)) ? vertical : " "; + sb.append(toTreeDraw(node.left, leftEdge, indent + step)); + return sb.toString(); + } + + /** + * Sukuria ir grąžina aibės kopiją. + * + * @return Aibės kopija. + * @throws java.lang.CloneNotSupportedException + */ + @Override + public Object clone() throws CloneNotSupportedException { + BstSet cl = (BstSet) super.clone(); + if (root == null) { + return cl; + } + cl.root = cloneRecursive(root); + cl.size = this.size; + return cl; + } + + private BstNode cloneRecursive(BstNode node) { + if (node == null) { + return null; + } + + BstNode clone = new BstNode<>(node.element); + clone.left = cloneRecursive(node.left); + clone.right = cloneRecursive(node.right); + return clone; + } + + /** + * Grąžinamas aibės poaibis iki elemento. + * + * @param element - Aibės elementas. + * @return Grąžinamas aibės poaibis iki elemento. + */ + @Override + public Set headSet(E element) { + Set headSet = new BstSet<>(); + for (E e : this) { + headSet.add(e); + if (c.compare(e, element) == 0) break; + } + return headSet; + } + + /** + * Grąžinamas aibės poaibis nuo elemento element1 iki element2. + * + * @param element1 - pradinis aibės poaibio elementas. + * @param element2 - galinis aibės poaibio elementas. + * @return Grąžinamas aibės poaibis nuo elemento element1 iki element2. + */ + @Override + public Set subSet(E element1, E element2) { + Set subSet = new BstSet<>(); + boolean seen1 = false; + boolean seen2 = false; + for (E e : this) { + if (!seen1 && c.compare(e, element1) == 0) seen1 = true; + + if (seen1 && !seen2) { + subSet.add(e); + } + + if (!seen2 && c.compare(e, element2) == 0) seen2 = true; + } + return subSet; + } + + /** + * Grąžinamas aibės poaibis nuo elemento. + * + * @param element - Aibės elementas. + * @return Grąžinamas aibės poaibis nuo elemento. + */ + @Override + public Set tailSet(E element) { + Set tailSet = new BstSet<>(); + boolean seen = false; + for (E e : this) { + if (!seen && c.compare(e, element) == 0) seen = true; + + if (seen) { + tailSet.add(e); + } + } + return tailSet; + } + + public BstNode getRoot() { + return root; + } + + /** + * Grąžinamas tiesioginis iteratorius. + * + * @return Grąžinamas tiesioginis iteratorius. + */ + @Override + public Iterator iterator() { + return new IteratorBst(true); + } + + /** + * Grąžinamas atvirkštinis iteratorius. + * + * @return Grąžinamas atvirkštinis iteratorius. + */ + @Override + public Iterator descendingIterator() { + return new IteratorBst(false); + } + + /** + * Vidinė objektų kolekcijos iteratoriaus klasė. Iteratoriai: didėjantis ir + * mažėjantis. Kolekcija iteruojama kiekvieną elementą aplankant vieną kartą + * vidine (angl. inorder) tvarka. Visi aplankyti elementai saugomi steke. + * Stekas panaudotas iš java.util paketo, bet galima susikurti nuosavą. + */ + private class IteratorBst implements Iterator { + + private final Stack> stack = new Stack<>(); + // Nurodo iteravimo kolekcija kryptį, true - didėjimo tvarka, false - mažėjimo + private final boolean ascending; + // Reikalinga remove() metodui. + private BstNode lastInStack; + private BstNode last; + + IteratorBst(boolean ascendingOrder) { + this.ascending = ascendingOrder; + this.toStack(root); + } + + @Override + public boolean hasNext() { + return !stack.empty(); + } + + @Override + public E next() {// Jei stekas tuščias + if (stack.empty()) { + lastInStack = root; + last = null; + return null; + } else { + // Grąžinamas paskutinis į steką patalpintas elementas + BstNode n = stack.pop(); + // Atsimenamas paskutinis grąžintas elementas, o taip pat paskutinis steke esantis elementas. + // Reikia remove() metodui + lastInStack = stack.isEmpty() ? root : stack.peek(); + last = n; + BstNode node = (ascending) ? n.right : n.left; + // Dešiniajame n pomedyje ieškoma minimalaus elemento, + // o visi paieškos kelyje esantys elementai talpinami į steką + toStack(node); + return n.element; + } + } + + @Override + public void remove() { + root = removeRecursive(lastInStack.element, root); + } + + private void toStack(BstNode n) { + while (n != null) { + stack.push(n); + n = (ascending) ? n.left : n.right; + } + } + } + + /** + * Vidinė kolekcijos mazgo klasė + * + * @param mazgo elemento duomenų tipas + */ + public static class BstNode { + + // Elementas + public N element; + // Rodyklė į kairįjį pomedį + public BstNode left; + // Rodyklė į dešinįjį pomedį + public BstNode right; + + protected BstNode() { + } + + protected BstNode(N element) { + this.element = element; + this.left = null; + this.right = null; + } + } +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/BstSetIterative.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/BstSetIterative.java new file mode 100644 index 0000000..c30c7d6 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/BstSetIterative.java @@ -0,0 +1,118 @@ +package edu.ktu.ds.lab2.utils; + +import java.util.Comparator; + +/** + * Klasė paveldi klasę BstSet ir perdengia add metodą iteracine realizacija + * + * @param + * @author darius + */ +public class BstSetIterative> extends BstSet implements SortedSet { + + public BstSetIterative() { + super(); + } + + public BstSetIterative(Comparator c) { + super(c); + } + + /** + * Aibė papildoma nauju elementu. Papildymas atliekamas iteracijos į gylį + * + * @param element + */ + @Override + public void add(E element) { + if (element == null) { + throw new IllegalArgumentException("Element is null in add(E element)"); + } + + if (root == null) { + root = new BstNode(element); + } else { + BstNode current = root; + BstNode parent = null; + while (current != null) { + parent = current; + int cmp = c.compare(element, current.element); + if (cmp < 0) { + current = current.left; + } else if (cmp > 0) { + current = current.right; + } else { + return; + } + } + + int cmp = c.compare(element, parent.element); + if (cmp < 0) { + parent.left = new BstNode(element); + } else if (cmp > 0) { + parent.right = new BstNode(element); + } + } + size++; + } + + /** + * Pašalinamas elementas iš aibės. + * + * @param element - Aibės elementas. + */ + @Override + public void remove(E element) { + if (element == null) { + throw new IllegalArgumentException("Element is null in remove(E element)"); + } + if (root == null) return; + + BstNode current = root; + BstNode parent = null; + + while (current != null) { + int cmp = c.compare(element, current.element); + if (cmp == 0) break; + + parent = current; + if (cmp < 0) { + current = current.left; + } else { //if (cmp > 0) { + current = current.right; + } + } + + if (current == null) { + return; + } else if (current.right != null && current.left != null) { + BstNode rightMinimumParent = null; + BstNode rightMinimum = current.right; + + while (rightMinimum.left != null) { + rightMinimumParent = rightMinimum; + rightMinimum = rightMinimum.left; + } + + if (rightMinimumParent != null) { + rightMinimumParent.left = rightMinimum.right; + } else { + current.right = rightMinimum.right; + } + + current.element = rightMinimum.element; + } else { + BstNode newCurrent = current.left == null ? current.right : current.left; + + if (parent == null) { + root = newCurrent; + } else if (parent.left == current) { + parent.left = newCurrent; + } else { + parent.right = newCurrent; + } + } + + size--; + } +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/Ks.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/Ks.java new file mode 100644 index 0000000..4bbb0a2 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/Ks.java @@ -0,0 +1,174 @@ +package edu.ktu.ds.lab2.utils; + +import java.io.*; +import java.time.LocalDate; +import java.util.Arrays; + +/* + * Klasė yra skirta patogiam duomenų paėmimui iš klaviatūros bei + * efektyviam rezultatų pateikimui į sout ir serr srautus. + * Visi metodai yra statiniai ir skirti vienam duomenų tipui. + * studentai savarankiškai paruošia metodus dėl short ir byte skaičių tipų. + * + * @author eimutis + */ +public class Ks { // KTU system - imituojama Javos System klasė + + private static final BufferedReader keyboard + = new BufferedReader(new InputStreamReader(System.in)); + private static String dataFolder = "data"; + + static public String giveString(String prompt) { + Ks.ou(prompt); + try { + return keyboard.readLine(); + } catch (IOException e) { + Ks.ern("Neveikia klaviatūros srautas, darbas baigtas"); + System.exit(0); + } + return ""; + } + + static public long giveLong(String prompt) { + while (true) { + String s = giveString(prompt); + try { + return Long.parseLong(s); + } catch (NumberFormatException e) { + Ks.ern("Neteisingas skaičiaus formatas, pakartokite"); + } + } + } + + static public long giveLong(String prompt, long bound1, long bound2) { + while (true) { + long a = giveLong(prompt + " tarp ribų [" + bound1 + ":" + bound2 + "]="); + if (a < bound1) { + Ks.ern("Skaičius mažesnis nei leistina, pakartokite"); + } else if (a > bound2) { + Ks.ern("Skaičius didesnis nei leistina, pakartokite"); + } else { + return a; + } + } + } + + static public int giveInt(String prompt) { + while (true) { + long a = giveLong(prompt); + if (a < Integer.MIN_VALUE) { + Ks.ern("Skaičius mažesnis nei Integer.MIN_VALUE" + + ", pakartokite"); + } else if (a > Integer.MAX_VALUE) { + Ks.ern("Skaičius didesnis nei Integer.MAX_VALUE" + + ", pakartokite"); + } else { + return (int) a; + } + } + } + + static public int giveInt(String prompt, int bound1, int bound2) { + return (int) giveLong(prompt, bound1, bound2); + } + + static public double giveDouble(String prompt) { + while (true) { + String s = giveString(prompt); + try { + return Double.parseDouble(s); + } catch (NumberFormatException e) { + if (s.contains(",")) { + Ks.ern("Vietoje kablelio naudokite tašką" + + ", pakartokite"); + } else { + Ks.ern("Neteisingas skaičiaus formatas" + + ", pakartokite"); + } + } + } + } + + static public double giveDouble(String prompt, double bound1, double bound2) { + while (true) { + double a = giveDouble(prompt + " tarp ribų [" + bound1 + ":" + bound2 + "]="); + if (a < bound1) { + Ks.ern("Skaičius mažesnis nei leistina, pakartokite"); + } else if (a > bound2) { + Ks.ern("Skaičius didesnis nei leistina, pakartokite"); + } else { + return a; + } + } + } + + static public String giveFileName() { + File dir = new File(dataFolder); + dir.mkdir(); + oun("Jums prieinami failai " + Arrays.toString(dir.list())); + return giveString("Nurodykite pasirinktą duomenų failo vardą: "); + } + + static public String getDataFolder() { + return dataFolder; + } + + static public void setDataFolder(String folderName) { + dataFolder = folderName; + } + + private static final PrintStream sout = System.out; + private static final PrintStream serr = System.out; + private static int lineNr; + private static int errorNr; + private static final boolean formatStartOfLine = true; + + static public void ou(Object obj) { + if (formatStartOfLine) { + sout.printf("%2d| %s", ++lineNr, obj); + } else { + sout.println(obj); + } + } + + static public void oun(Object obj) { + if (formatStartOfLine) { + sout.printf("%2d| %s\n", ++lineNr, obj); + } else { + sout.println(obj); + } + } + + static public void ounn(Object obj) { // *****nauja + if (formatStartOfLine) { + sout.printf("%2d|\n", ++lineNr); + sout.printf("%s\n", obj); + } else { + sout.println(obj); + } + } + + static public void out(Object obj) { + sout.print(obj); + } + + static public void ouf(String format, Object... args) { + sout.printf(format, args); + } + + static public void er(Object obj) { + serr.printf("***Klaida %d: %s", ++errorNr, obj); + } + + static public void ern(Object obj) { + serr.printf("***Klaida %d: %s\n", ++errorNr, obj); + } + + static public void erf(String format, Object... args) { + serr.printf(format, args); + } + + static public LocalDate getDate() { + return LocalDate.now(); + } +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/Parsable.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/Parsable.java new file mode 100644 index 0000000..a076b22 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/Parsable.java @@ -0,0 +1,16 @@ +package edu.ktu.ds.lab2.utils; + +/** @author Eimutis Karčiauskas, KTU IF Programų inžinerijos katedra + * + * Tai yra interfeisas, kurį turi tenkinti KTU studentų kuriamos duomenų klasės + * Metodai užtikrina patogų duomenų suformavimą iš String eilučių + ******************************************************************************/ +public interface Parsable extends Comparable { + + /** + * Suformuoja objektą iš eilutės + * + * @param dataString + */ + void parse(String dataString); +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/ParsableAvlSet.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/ParsableAvlSet.java new file mode 100644 index 0000000..3bc75c1 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/ParsableAvlSet.java @@ -0,0 +1,77 @@ +package edu.ktu.ds.lab2.utils; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Comparator; +import java.util.Optional; +import java.util.function.Function; + +public class ParsableAvlSet> extends AvlSet implements ParsableSortedSet { + + private final Function createFunction; // funkcija bazinio objekto kūrimui + + /** + * Konstruktorius su funkcija bazinio objekto kūrimui + * + * @param createFunction + */ + public ParsableAvlSet(Function createFunction) { + super(); + this.createFunction = createFunction; + } + + /** + * Konstruktorius su funkcija bazinio objekto kūrimui ir komparatoriumi + * + * @param createFunction + * @param c + */ + public ParsableAvlSet(Function createFunction, Comparator c) { + super(c); + this.createFunction = createFunction; + } + + /** + * Sukuria elementą iš String eilutės ir įdeda jį į pabaigą + * + * @param dataString + */ + @Override + public void add(String dataString) { + add(createElement(dataString)); + } + + /** + * Suformuoja sąrašą iš filePath failo + * + * @param filePath + */ + @Override + public void load(String filePath) { + if (filePath == null || filePath.length() == 0) { + return; + } + + clear(); + try (BufferedReader fReader = Files.newBufferedReader(Paths.get(filePath), Charset.defaultCharset())) { + fReader.lines() + .map(String::trim) + .filter(line -> !line.isEmpty()) + .forEach(this::add); + } catch (FileNotFoundException e) { + Ks.ern("Duomenų failas " + filePath + " nerastas"); + } catch (IOException e) { + Ks.ern("Failo " + filePath + " skaitymo klaida"); + } + } + + protected E createElement(String data) { + return Optional.ofNullable(createFunction) + .map(f -> f.apply(data)) + .orElseThrow(() -> new IllegalStateException("Nenustatyta aibės elementų kūrimo funkcija")); + } +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/ParsableBstSet.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/ParsableBstSet.java new file mode 100644 index 0000000..c233e14 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/ParsableBstSet.java @@ -0,0 +1,78 @@ +package edu.ktu.ds.lab2.utils; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Comparator; +import java.util.Optional; +import java.util.function.Function; + +public class ParsableBstSet> extends BstSet + implements ParsableSortedSet { + + private final Function createFunction; // funkcija bazinio objekto kūrimui + + /** + * Konstruktorius su funkcija bazinio objekto kūrimui + * + * @param createFunction + */ + public ParsableBstSet(Function createFunction) { + super(); + this.createFunction = createFunction; + } + + /** + * Konstruktorius su funkcija bazinio objekto kūrimui ir komparatoriumi + * + * @param createFunction + * @param c + */ + public ParsableBstSet(Function createFunction, Comparator c) { + super(c); + this.createFunction = createFunction; + } + + /** + * Sukuria elementą iš String ir įdeda jį į pabaigą + * + * @param dataString + */ + @Override + public void add(String dataString) { + super.add(createElement(dataString)); + } + + /** + * Suformuoja sąrašą iš filePath failo + * + * @param filePath + */ + @Override + public void load(String filePath) { + if (filePath == null || filePath.length() == 0) { + return; + } + + clear(); + try (BufferedReader fReader = Files.newBufferedReader(Paths.get(filePath), Charset.defaultCharset())) { + fReader.lines() + .map(String::trim) + .filter(line -> !line.isEmpty()) + .forEach(this::add); + } catch (FileNotFoundException e) { + Ks.ern("Tinkamas duomenų failas " + filePath + " nerastas"); + } catch (IOException e) { + Ks.ern("Failo " + filePath + " skaitymo klaida"); + } + } + + protected E createElement(String data) { + return Optional.ofNullable(createFunction) + .map(f -> f.apply(data)) + .orElseThrow(() -> new IllegalStateException("Nenustatyta aibės elementų kūrimo funkcija")); + } +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/ParsableSortedSet.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/ParsableSortedSet.java new file mode 100644 index 0000000..a0d925c --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/ParsableSortedSet.java @@ -0,0 +1,10 @@ +package edu.ktu.ds.lab2.utils; + +public interface ParsableSortedSet extends SortedSet { + + void add(String dataString); + + void load(String fName); + + Object clone() throws CloneNotSupportedException; +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/Set.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/Set.java new file mode 100644 index 0000000..a1ddb13 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/Set.java @@ -0,0 +1,42 @@ +package edu.ktu.ds.lab2.utils; + +/** + * Interfeisu aprašomas Aibės ADT. + * + * @param Aibės elemento duomenų tipas + */ +public interface Set extends Iterable { + + //Patikrinama ar aibė tuščia. + boolean isEmpty(); + + // Grąžinamas aibėje esančių elementų kiekis. + int size(); + + // Išvaloma aibė. + void clear(); + + // Aibė papildoma nauju elementu. + void add(E element); + + // Abės set elementai pridedami į esamą aibę, jeigu abi aibės turi tą patį elementą, jis nėra dedamas. + void addAll(Set set); + + // Pašalinamas elementas iš aibės. + void remove(E element); + + // Aibėje lieka tie elementai, kurie yra esamoje abėje ir aibėje set. + void retainAll(Set set); + + // Patikrinama ar elementas egzistuoja aibėje. + boolean contains(E element); + + // Patikrinama ar visi abės set elementai egzistuoja aibėje. + boolean containsAll(Set set); + + // Grąžinamas aibės elementų masyvas. + Object[] toArray(); + + // Gražinamas vizualiai išdėstytas aibės elementų turinys + String toVisualizedString(); +} diff --git a/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/SortedSet.java b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/SortedSet.java new file mode 100644 index 0000000..7d87cd7 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/java/edu/ktu/ds/lab2/utils/SortedSet.java @@ -0,0 +1,38 @@ +package edu.ktu.ds.lab2.utils; + +import java.util.Iterator; + +public interface SortedSet extends Set { + + /** + * Grąžinamas aibės poaibis iki elemento data. + * + * @param element - Aibės elementas. + * @return Grąžinamas aibės poaibis iki elemento data. + */ + Set headSet(E element); + + /** + * Grąžinamas aibės poaibis nuo elemento data1 iki data2. + * + * @param element1 - pradinis aibės poaibio elementas. + * @param element2 - galinis aibės poaibio elementas. + * @return Grąžinamas aibės poaibis nuo elemento data1 iki data2. + */ + Set subSet(E element1, E element2); + + /** + * Grąžinamas aibės poaibis iki elemento data. + * + * @param element - Aibės elementas. + * @return Grąžinamas aibės poaibis nuo elemento data. + */ + Set tailSet(E element); + + /** + * Grąžinamas atvirkštinis iteratorius. + * + * @return Grąžinamas atvirkštinis iteratorius. + */ + Iterator descendingIterator(); +} diff --git a/Lab2_AibesMedziai/src/main/resources/edu/ktu/ds/lab2/gui/messages.properties b/Lab2_AibesMedziai/src/main/resources/edu/ktu/ds/lab2/gui/messages.properties new file mode 100644 index 0000000..b4b0c67 --- /dev/null +++ b/Lab2_AibesMedziai/src/main/resources/edu/ktu/ds/lab2/gui/messages.properties @@ -0,0 +1,59 @@ +title=KTU IF LD2. Med\u017Eio tipo duomen\u0173 strukt\u016Br\u0173 tiriamasis darbas +author=Autorius: Vardenis Pavardenis, IF-x/x\nemail: vardenis.pavardenis@ktu.edu\n\u012Era\u0161ykite savo rekvizitus. +icon=ktu.png + +# Meniu pavadinimai +menu1=Failas +menu2=Pagalba + +menuItem11=Atidaryti.. +menuItem12=I\u0161saugoti.. +menuItem13=I\u0161eiti +menuItem21=Apie.. + +# R\u0117meli\u0173 pavadinimai +border1=Rezultatai: +border2=Parametrai: + +# Mygtuk\u0173 pavadinimai +button1=Generuoti automobili\u0173 aib\u0119 +button2=Per\u017Ei\u016Bra su iteratoriumi +button3=Papildyti aib\u0119 automobiliu +button4=Pa\u0161alinti automobil\u012F i\u0161 aib\u0117s +button5=J\u016Bs\u0173 sukurta funkcija +button6=J\u016Bs\u0173 sukurta funkcija + +# Pirmos lentel\u0117s parametrai +lblParam11=Generuojamos automobili\u0173 aib\u0117s dydis +lblParam12=Pradin\u0117 automobili\u0173 aib\u0117s imtis +lblParam13=Lik\u0119s automobili\u0173 aib\u0117s dydis +lblParam14=I\u0161barstymo koeficientas [0,1] +lblParam15=J\u016Bs\u0173 parametras +tfParam11=100 +tfParam12=10 +tfParam13= +tfParam14=0.8 +tfParam15= + +# Antros lentel\u0117s parametrai +lblParam21=Paie\u0161kos med\u017Eio tipas +lblParam22=Elemento teksto kirtiklis +lblParam23=Duomen\u0173 \u012Fvedimas + +cmbTreeType1=DP-medis +cmbTreeType2=AVL-Medis +cmbTreeType3=Kiti med\u017Eiai + +notImplemented=Dar ne\u012Fdiegta +allSetIsPrinted=Visa sugeneruota aib\u0117 jau i\u0161spausdinta +setIsEmpty=Aib\u0117 tu\u0161\u010Dia +setInTree=Duomen\u0173 aib\u0117 medyje +setRemoval=Elemento pa\u0161alinimas i\u0161 aib\u0117s +setAdd=Aib\u0117s papildymas elementu +setIterator=Aib\u0117s per\u017Ei\u016Bra su iteratoriumi + +badSetSize=Netinkamas generuojamos aib\u0117s dydis +badInitialData=Netinkama pradin\u0117 aib\u0117s imtis arba netinkamai nuskaityti duomenys +badSetSizes=Generuojama aib\u0117 turi b\u016Bti didesn\u0117 negu pradin\u0117 aib\u0117s imtis +badShuffleCoef=Netinkamas i\u0161barstymo koeficientas +systemError=Sistemin\u0117 klaida. \u017Di\u016Br\u0117ti konsol\u0117je \ No newline at end of file diff --git a/Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/AvlSetTests.java b/Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/AvlSetTests.java new file mode 100644 index 0000000..84592be --- /dev/null +++ b/Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/AvlSetTests.java @@ -0,0 +1,111 @@ +package edu.ktu.ds.lab2.demo; + +import edu.ktu.ds.lab2.utils.AvlSet; +import edu.ktu.ds.lab2.utils.Set; +import org.junit.Assert; +import org.junit.Test; + +import java.io.Console; +import java.util.List; +import java.util.Random; + +public class AvlSetTests extends BstSetTests { + public Set newSet() { + return new AvlSet<>(); + } + + @Test + public void checkAddRightTurn() { + AvlSet avl = (AvlSet) set; + avl.add(3); + avl.add(2); + avl.add(1); + Assert.assertEquals(avl.serialize(), "(1,2,3)"); + } + + @Test + public void checkAddDoubleRightTurn() { + AvlSet avl = (AvlSet) set; + avl.add(3); + avl.add(1); + avl.add(2); + Assert.assertEquals(avl.serialize(), "(1,2,3)"); + } + + @Test + public void checkAddLeftTurn() { + AvlSet avl = (AvlSet) set; + avl.add(1); + avl.add(2); + avl.add(3); + Assert.assertEquals(avl.serialize(), "(1,2,3)"); + } + + @Test + public void checkAddDoubleLeftTurn() { + AvlSet avl = (AvlSet) set; + avl.add(2); + avl.add(1); + avl.add(3); + Assert.assertEquals(avl.serialize(), "(1,2,3)"); + } + + @Test + public void checkRemoveRightTurn() { + AvlSet avl = (AvlSet) set; + avl.add(1); + avl.add(2); + avl.add(3); + avl.add(0); + avl.remove(3); + Assert.assertEquals(avl.serialize(), "(0,1,2)"); + } + + @Test + public void checkRemoveDoubleRightTurn() { + AvlSet avl = (AvlSet) set; + avl.add(1); + avl.add(3); + avl.add(4); + avl.add(2); + avl.remove(4); + Assert.assertEquals(avl.serialize(), "(1,2,3)"); + } + + @Test + public void checkRemoveLeftTurn() { + AvlSet avl = (AvlSet) set; + avl.add(2); + avl.add(1); + avl.add(3); + avl.add(4); + avl.remove(1); + Assert.assertEquals(avl.serialize(), "(2,3,4)"); + } + + @Test + public void checkRemoveDoubleLeftTurn() { + AvlSet avl = (AvlSet) set; + avl.add(1); + avl.add(2); + avl.add(4); + avl.add(3); + avl.remove(1); + Assert.assertEquals(avl.serialize(), "(2,3,4)"); + } + + @Test + public void checkMassRemoving() { + Random r = new Random(); + for (int i = 0; i < 50; i++) { + add(r.nextInt(1000)); + } + assertSetsMatch(set, javaSet); + while (set.size() > 0) { + int index = r.nextInt(set.size()); + remove((Integer) set.toArray()[index]); + assertSetsMatch(set, javaSet); + } + + } +} diff --git a/Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/BstSetIterativeTests.java b/Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/BstSetIterativeTests.java new file mode 100644 index 0000000..a5771c9 --- /dev/null +++ b/Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/BstSetIterativeTests.java @@ -0,0 +1,13 @@ +package edu.ktu.ds.lab2.demo; + +import edu.ktu.ds.lab2.utils.BstSetIterative; +import edu.ktu.ds.lab2.utils.Set; + +import java.util.Random; + +public class BstSetIterativeTests extends BstSetTests { + @Override + public Set newSet() { + return new BstSetIterative<>(); + } +} diff --git a/Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/BstSetTests.java b/Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/BstSetTests.java new file mode 100644 index 0000000..7857776 --- /dev/null +++ b/Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/BstSetTests.java @@ -0,0 +1,23 @@ +package edu.ktu.ds.lab2.demo; + +import edu.ktu.ds.lab2.utils.BstSet; +import edu.ktu.ds.lab2.utils.Set; +import org.junit.Test; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.Random; + +public class BstSetTests extends SortedSetTests { + + @Override + public Set newSet() { + return new BstSet<>(); + } + + @Override + public Integer newElement() { + return new Random().nextInt(1000); + } +} diff --git a/Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/SetTests.java b/Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/SetTests.java new file mode 100644 index 0000000..c58db91 --- /dev/null +++ b/Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/SetTests.java @@ -0,0 +1,164 @@ +package edu.ktu.ds.lab2.demo; + +import edu.ktu.ds.lab2.utils.Set; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.*; + +public abstract class SetTests> { + protected Set set; + protected java.util.Set javaSet; + + @Before + public void setup() { + javaSet = new TreeSet<>(); + set = newSet(); + } + + public abstract Set newSet(); + + public abstract E newElement(); + + public List newTestList(int count) { + List list = new ArrayList<>(); + for (int i = 0; i < count; i++) { + list.add(newElement()); + } + return list; + } + + public void add(E element) { + set.add(element); + javaSet.add(element); + } + + private Set collectionToSet(Collection elements) { + Set set = newSet(); + for (E e : elements) { + set.add(e); + } + return set; + } + + public void addAll(Collection elements) { + set.addAll(collectionToSet(elements)); + javaSet.addAll(elements); + } + + public void remove(E element) { + set.remove(element); + javaSet.remove(element); + } + + public void fill(Iterable elements) { + for (E e : elements) { + add(e); + } + } + + public void retainAll(Collection elements) { + set.retainAll(collectionToSet(elements)); + javaSet.retainAll(elements); + } + + public ArrayList iterableToArray(Iterable iterable) { + ArrayList array = new ArrayList<>(); + for (E e : iterable) array.add(e); + return array; + } + + public void assertSetsMatch(Iterable actual, Iterable expected) { + Assert.assertEquals(iterableToArray(actual), iterableToArray(expected)); + } + + public void assertContainsAllMatches(Collection elements) { + Assert.assertEquals(set.containsAll(collectionToSet(elements)), javaSet.containsAll(elements)); + } + + @Test + public void checkAddition() { + add(newElement()); + add(newElement()); + add(newElement()); + assertSetsMatch(set, javaSet); + } + + @Test + public void checkAdditionWithDuplicates() { + E element = newElement(); + add(newElement()); + add(newElement()); + add(newElement()); + add(element); + add(element); + assertSetsMatch(set, javaSet); + } + + @Test + public void checkSize() { + E e1 = newElement(); + E e2 = newElement(); + E e3 = newElement(); + Assert.assertEquals(set.size(), 0); + set.add(e1); + set.add(e2); + set.add(e3); + Assert.assertEquals(set.size(), 3); + set.remove(e2); + Assert.assertEquals(set.size(), 2); + set.remove(e1); + set.remove(e3); + Assert.assertEquals(set.size(), 0); + } + + @Test + public void checkRemoving() { + List values = newTestList(5); + fill(values); + assertSetsMatch(set, javaSet); + + remove(values.get(2)); + assertSetsMatch(set, javaSet); + + remove(values.get(0)); + remove(values.get(4)); + assertSetsMatch(set, javaSet); + + remove(values.get(1)); + remove(values.get(3)); + assertSetsMatch(set, javaSet); + } + + @Test + public void checkAddingAll() { + List values = newTestList(5); + add(values.get(0)); + add(values.get(1)); + assertSetsMatch(set, javaSet); + + addAll(values); + assertSetsMatch(set, javaSet); + } + + @Test + public void checkContainsAll() { + List values = newTestList(5); + add(values.get(0)); + add(values.get(1)); + assertContainsAllMatches(values); + + fill(values); + assertContainsAllMatches(values); + } + + @Test + public void checkRetainsAll() { + List values = newTestList(5); + List retained = Arrays.asList(values.get(0), values.get(4), values.get(2)); + fill(values); + retainAll(retained); + assertSetsMatch(set, javaSet); + } +} diff --git a/Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/SortedSetTests.java b/Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/SortedSetTests.java new file mode 100644 index 0000000..da982ba --- /dev/null +++ b/Lab2_AibesMedziai/src/test/java/edu/ktu/ds/lab2/demo/SortedSetTests.java @@ -0,0 +1,38 @@ +package edu.ktu.ds.lab2.demo; + +import edu.ktu.ds.lab2.utils.BstSet; +import edu.ktu.ds.lab2.utils.Set; +import edu.ktu.ds.lab2.utils.SortedSet; +import org.junit.Test; + +import java.util.Comparator; +import java.util.List; + +public abstract class SortedSetTests> extends SetTests { + @Test + public void checkHeadSet() { + List values = newTestList(5); + fill(values); + values.sort(Comparator.naturalOrder()); + Set headSet = ((SortedSet)set).headSet(values.get(3)); + assertSetsMatch(headSet, values.subList(0, 4)); + } + + @Test + public void checkTailSet() { + List values = newTestList(5); + fill(values); + values.sort(Comparator.naturalOrder()); + Set headSet = ((SortedSet)set).tailSet(values.get(2)); + assertSetsMatch(headSet, values.subList(2, 5)); + } + + @Test + public void checkSubSet() { + List values = newTestList(5); + fill(values); + values.sort(Comparator.naturalOrder()); + Set headSet = ((SortedSet)set).subSet(values.get(1), values.get(3)); + assertSetsMatch(headSet, values.subList(1, 4)); + } +} diff --git a/Lab2_AibesMedziai/target/classes/META-INF/BenchmarkList b/Lab2_AibesMedziai/target/classes/META-INF/BenchmarkList new file mode 100644 index 0000000..fe29f4c --- /dev/null +++ b/Lab2_AibesMedziai/target/classes/META-INF/BenchmarkList @@ -0,0 +1,4 @@ +JMH S 30 edu.ktu.ds.lab2.demo.Benchmark S 68 edu.ktu.ds.lab2.demo.jmh_generated.Benchmark_addBstIterative_jmhTest S 15 addBstIterative S 11 AverageTime E A 1 1 1 E E T 3 1 s E E T 3 1 s E E E E E E E M 1 12 elementCount 4 16 xAAMAADAwAAMAA== 16 yAAMAADAwAAMAA== 16 0AAMAADAwAAMAA== 16 4AAMAADAwAAMAA== U 12 MICROSECONDS E E +JMH S 30 edu.ktu.ds.lab2.demo.Benchmark S 68 edu.ktu.ds.lab2.demo.jmh_generated.Benchmark_addAvlRecursive_jmhTest S 15 addAvlRecursive S 11 AverageTime E A 1 1 1 E E T 3 1 s E E T 3 1 s E E E E E E E M 1 12 elementCount 4 16 xAAMAADAwAAMAA== 16 yAAMAADAwAAMAA== 16 0AAMAADAwAAMAA== 16 4AAMAADAwAAMAA== U 12 MICROSECONDS E E +JMH S 30 edu.ktu.ds.lab2.demo.Benchmark S 68 edu.ktu.ds.lab2.demo.jmh_generated.Benchmark_addBstRecursive_jmhTest S 15 addBstRecursive S 11 AverageTime E A 1 1 1 E E T 3 1 s E E T 3 1 s E E E E E E E M 1 12 elementCount 4 16 xAAMAADAwAAMAA== 16 yAAMAADAwAAMAA== 16 0AAMAADAwAAMAA== 16 4AAMAADAwAAMAA== U 12 MICROSECONDS E E +JMH S 30 edu.ktu.ds.lab2.demo.Benchmark S 62 edu.ktu.ds.lab2.demo.jmh_generated.Benchmark_removeBst_jmhTest S 9 removeBst S 11 AverageTime E A 1 1 1 E E T 3 1 s E E T 3 1 s E E E E E E E M 1 12 elementCount 4 16 xAAMAADAwAAMAA== 16 yAAMAADAwAAMAA== 16 0AAMAADAwAAMAA== 16 4AAMAADAwAAMAA== U 12 MICROSECONDS E E diff --git a/Lab2_AibesMedziai/target/classes/META-INF/CompilerHints b/Lab2_AibesMedziai/target/classes/META-INF/CompilerHints new file mode 100644 index 0000000..6a8fa73 --- /dev/null +++ b/Lab2_AibesMedziai/target/classes/META-INF/CompilerHints @@ -0,0 +1,12 @@ +dontinline,*.*_all_jmhStub +dontinline,*.*_avgt_jmhStub +dontinline,*.*_sample_jmhStub +dontinline,*.*_ss_jmhStub +dontinline,*.*_thrpt_jmhStub +inline,edu/ktu/ds/lab2/demo/Benchmark$FullSet.fillCarSet +inline,edu/ktu/ds/lab2/demo/Benchmark$FullSet.generateElements +inline,edu/ktu/ds/lab2/demo/Benchmark.addAvlRecursive +inline,edu/ktu/ds/lab2/demo/Benchmark.addBstIterative +inline,edu/ktu/ds/lab2/demo/Benchmark.addBstRecursive +inline,edu/ktu/ds/lab2/demo/Benchmark.generateElements +inline,edu/ktu/ds/lab2/demo/Benchmark.removeBst diff --git a/Lab2_AibesMedziai/target/classes/edu/ktu/ds/lab2/gui/messages.properties b/Lab2_AibesMedziai/target/classes/edu/ktu/ds/lab2/gui/messages.properties new file mode 100644 index 0000000..b4b0c67 --- /dev/null +++ b/Lab2_AibesMedziai/target/classes/edu/ktu/ds/lab2/gui/messages.properties @@ -0,0 +1,59 @@ +title=KTU IF LD2. Med\u017Eio tipo duomen\u0173 strukt\u016Br\u0173 tiriamasis darbas +author=Autorius: Vardenis Pavardenis, IF-x/x\nemail: vardenis.pavardenis@ktu.edu\n\u012Era\u0161ykite savo rekvizitus. +icon=ktu.png + +# Meniu pavadinimai +menu1=Failas +menu2=Pagalba + +menuItem11=Atidaryti.. +menuItem12=I\u0161saugoti.. +menuItem13=I\u0161eiti +menuItem21=Apie.. + +# R\u0117meli\u0173 pavadinimai +border1=Rezultatai: +border2=Parametrai: + +# Mygtuk\u0173 pavadinimai +button1=Generuoti automobili\u0173 aib\u0119 +button2=Per\u017Ei\u016Bra su iteratoriumi +button3=Papildyti aib\u0119 automobiliu +button4=Pa\u0161alinti automobil\u012F i\u0161 aib\u0117s +button5=J\u016Bs\u0173 sukurta funkcija +button6=J\u016Bs\u0173 sukurta funkcija + +# Pirmos lentel\u0117s parametrai +lblParam11=Generuojamos automobili\u0173 aib\u0117s dydis +lblParam12=Pradin\u0117 automobili\u0173 aib\u0117s imtis +lblParam13=Lik\u0119s automobili\u0173 aib\u0117s dydis +lblParam14=I\u0161barstymo koeficientas [0,1] +lblParam15=J\u016Bs\u0173 parametras +tfParam11=100 +tfParam12=10 +tfParam13= +tfParam14=0.8 +tfParam15= + +# Antros lentel\u0117s parametrai +lblParam21=Paie\u0161kos med\u017Eio tipas +lblParam22=Elemento teksto kirtiklis +lblParam23=Duomen\u0173 \u012Fvedimas + +cmbTreeType1=DP-medis +cmbTreeType2=AVL-Medis +cmbTreeType3=Kiti med\u017Eiai + +notImplemented=Dar ne\u012Fdiegta +allSetIsPrinted=Visa sugeneruota aib\u0117 jau i\u0161spausdinta +setIsEmpty=Aib\u0117 tu\u0161\u010Dia +setInTree=Duomen\u0173 aib\u0117 medyje +setRemoval=Elemento pa\u0161alinimas i\u0161 aib\u0117s +setAdd=Aib\u0117s papildymas elementu +setIterator=Aib\u0117s per\u017Ei\u016Bra su iteratoriumi + +badSetSize=Netinkamas generuojamos aib\u0117s dydis +badInitialData=Netinkama pradin\u0117 aib\u0117s imtis arba netinkamai nuskaityti duomenys +badSetSizes=Generuojama aib\u0117 turi b\u016Bti didesn\u0117 negu pradin\u0117 aib\u0117s imtis +badShuffleCoef=Netinkamas i\u0161barstymo koeficientas +systemError=Sistemin\u0117 klaida. \u017Di\u016Br\u0117ti konsol\u0117je \ No newline at end of file diff --git a/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_FullSet_jmhType.java b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_FullSet_jmhType.java new file mode 100644 index 0000000..9e92a3c --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_FullSet_jmhType.java @@ -0,0 +1,4 @@ +package edu.ktu.ds.lab2.demo.jmh_generated; +public class Benchmark_FullSet_jmhType extends Benchmark_FullSet_jmhType_B3 { +} + diff --git a/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_FullSet_jmhType_B1.java b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_FullSet_jmhType_B1.java new file mode 100644 index 0000000..e557f6b --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_FullSet_jmhType_B1.java @@ -0,0 +1,20 @@ +package edu.ktu.ds.lab2.demo.jmh_generated; +import edu.ktu.ds.lab2.demo.Benchmark.FullSet; +public class Benchmark_FullSet_jmhType_B1 extends edu.ktu.ds.lab2.demo.Benchmark.FullSet { + byte p000, p001, p002, p003, p004, p005, p006, p007, p008, p009, p010, p011, p012, p013, p014, p015; + byte p016, p017, p018, p019, p020, p021, p022, p023, p024, p025, p026, p027, p028, p029, p030, p031; + byte p032, p033, p034, p035, p036, p037, p038, p039, p040, p041, p042, p043, p044, p045, p046, p047; + byte p048, p049, p050, p051, p052, p053, p054, p055, p056, p057, p058, p059, p060, p061, p062, p063; + byte p064, p065, p066, p067, p068, p069, p070, p071, p072, p073, p074, p075, p076, p077, p078, p079; + byte p080, p081, p082, p083, p084, p085, p086, p087, p088, p089, p090, p091, p092, p093, p094, p095; + byte p096, p097, p098, p099, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111; + byte p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127; + byte p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143; + byte p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159; + byte p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175; + byte p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191; + byte p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207; + byte p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223; + byte p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239; + byte p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250, p251, p252, p253, p254, p255; +} diff --git a/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_FullSet_jmhType_B2.java b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_FullSet_jmhType_B2.java new file mode 100644 index 0000000..978c20a --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_FullSet_jmhType_B2.java @@ -0,0 +1,22 @@ +package edu.ktu.ds.lab2.demo.jmh_generated; +import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; +public class Benchmark_FullSet_jmhType_B2 extends Benchmark_FullSet_jmhType_B1 { + public volatile int setupTrialMutex; + public volatile int tearTrialMutex; + public final static AtomicIntegerFieldUpdater setupTrialMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(Benchmark_FullSet_jmhType_B2.class, "setupTrialMutex"); + public final static AtomicIntegerFieldUpdater tearTrialMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(Benchmark_FullSet_jmhType_B2.class, "tearTrialMutex"); + + public volatile int setupIterationMutex; + public volatile int tearIterationMutex; + public final static AtomicIntegerFieldUpdater setupIterationMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(Benchmark_FullSet_jmhType_B2.class, "setupIterationMutex"); + public final static AtomicIntegerFieldUpdater tearIterationMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(Benchmark_FullSet_jmhType_B2.class, "tearIterationMutex"); + + public volatile int setupInvocationMutex; + public volatile int tearInvocationMutex; + public final static AtomicIntegerFieldUpdater setupInvocationMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(Benchmark_FullSet_jmhType_B2.class, "setupInvocationMutex"); + public final static AtomicIntegerFieldUpdater tearInvocationMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(Benchmark_FullSet_jmhType_B2.class, "tearInvocationMutex"); + + public volatile boolean readyTrial; + public volatile boolean readyIteration; + public volatile boolean readyInvocation; +} diff --git a/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_FullSet_jmhType_B3.java b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_FullSet_jmhType_B3.java new file mode 100644 index 0000000..77e04bc --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_FullSet_jmhType_B3.java @@ -0,0 +1,20 @@ +package edu.ktu.ds.lab2.demo.jmh_generated; +public class Benchmark_FullSet_jmhType_B3 extends Benchmark_FullSet_jmhType_B2 { + byte p000, p001, p002, p003, p004, p005, p006, p007, p008, p009, p010, p011, p012, p013, p014, p015; + byte p016, p017, p018, p019, p020, p021, p022, p023, p024, p025, p026, p027, p028, p029, p030, p031; + byte p032, p033, p034, p035, p036, p037, p038, p039, p040, p041, p042, p043, p044, p045, p046, p047; + byte p048, p049, p050, p051, p052, p053, p054, p055, p056, p057, p058, p059, p060, p061, p062, p063; + byte p064, p065, p066, p067, p068, p069, p070, p071, p072, p073, p074, p075, p076, p077, p078, p079; + byte p080, p081, p082, p083, p084, p085, p086, p087, p088, p089, p090, p091, p092, p093, p094, p095; + byte p096, p097, p098, p099, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111; + byte p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127; + byte p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143; + byte p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159; + byte p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175; + byte p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191; + byte p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207; + byte p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223; + byte p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239; + byte p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250, p251, p252, p253, p254, p255; +} + diff --git a/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_addAvlRecursive_jmhTest.java b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_addAvlRecursive_jmhTest.java new file mode 100644 index 0000000..3318e47 --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_addAvlRecursive_jmhTest.java @@ -0,0 +1,514 @@ +package edu.ktu.ds.lab2.demo.jmh_generated; + +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.Collection; +import java.util.ArrayList; +import java.util.concurrent.TimeUnit; +import org.openjdk.jmh.annotations.CompilerControl; +import org.openjdk.jmh.runner.InfraControl; +import org.openjdk.jmh.infra.ThreadParams; +import org.openjdk.jmh.results.BenchmarkTaskResult; +import org.openjdk.jmh.results.Result; +import org.openjdk.jmh.results.ThroughputResult; +import org.openjdk.jmh.results.AverageTimeResult; +import org.openjdk.jmh.results.SampleTimeResult; +import org.openjdk.jmh.results.SingleShotResult; +import org.openjdk.jmh.util.SampleBuffer; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Threads; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.results.RawResults; +import org.openjdk.jmh.results.ResultRole; +import java.lang.reflect.Field; +import org.openjdk.jmh.infra.BenchmarkParams; +import org.openjdk.jmh.infra.IterationParams; +import org.openjdk.jmh.infra.Blackhole; +import org.openjdk.jmh.infra.Control; +import org.openjdk.jmh.results.ScalarResult; +import org.openjdk.jmh.results.AggregationPolicy; +import org.openjdk.jmh.runner.FailureAssistException; + +import edu.ktu.ds.lab2.demo.jmh_generated.Benchmark_jmhType; +public final class Benchmark_addAvlRecursive_jmhTest { + + byte p000, p001, p002, p003, p004, p005, p006, p007, p008, p009, p010, p011, p012, p013, p014, p015; + byte p016, p017, p018, p019, p020, p021, p022, p023, p024, p025, p026, p027, p028, p029, p030, p031; + byte p032, p033, p034, p035, p036, p037, p038, p039, p040, p041, p042, p043, p044, p045, p046, p047; + byte p048, p049, p050, p051, p052, p053, p054, p055, p056, p057, p058, p059, p060, p061, p062, p063; + byte p064, p065, p066, p067, p068, p069, p070, p071, p072, p073, p074, p075, p076, p077, p078, p079; + byte p080, p081, p082, p083, p084, p085, p086, p087, p088, p089, p090, p091, p092, p093, p094, p095; + byte p096, p097, p098, p099, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111; + byte p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127; + byte p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143; + byte p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159; + byte p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175; + byte p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191; + byte p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207; + byte p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223; + byte p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239; + byte p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250, p251, p252, p253, p254, p255; + int startRndMask; + BenchmarkParams benchmarkParams; + IterationParams iterationParams; + ThreadParams threadParams; + Blackhole blackhole; + Control notifyControl; + + public BenchmarkTaskResult addAvlRecursive_Throughput(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + Benchmark_jmhType l_benchmark0_G = _jmh_tryInit_f_benchmark0_G(control); + + control.preSetup(); + if (Benchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_benchmark0_G.readyIteration) { + l_benchmark0_G.generateElements(); + l_benchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.setupIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.setupIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + blackhole.consume(l_benchmark0_G.addAvlRecursive()); + res.allOps++; + } + + notifyControl.startMeasurement = true; + addAvlRecursive_thrpt_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, l_benchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + blackhole.consume(l_benchmark0_G.addAvlRecursive()); + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (Benchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_benchmark0_G.readyIteration) { + l_benchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.tearIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.tearIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + synchronized(this.getClass()) { + f_benchmark0_G = null; + } + } + res.allOps += res.measuredOps; + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + res.measuredOps /= batchSize; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new ThroughputResult(ResultRole.PRIMARY, "addAvlRecursive", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void addAvlRecursive_thrpt_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, Benchmark_jmhType l_benchmark0_G) throws Throwable { + long operations = 0; + long realTime = 0; + result.startTime = System.nanoTime(); + do { + blackhole.consume(l_benchmark0_G.addAvlRecursive()); + operations++; + } while(!control.isDone); + result.stopTime = System.nanoTime(); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult addAvlRecursive_AverageTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + Benchmark_jmhType l_benchmark0_G = _jmh_tryInit_f_benchmark0_G(control); + + control.preSetup(); + if (Benchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_benchmark0_G.readyIteration) { + l_benchmark0_G.generateElements(); + l_benchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.setupIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.setupIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + blackhole.consume(l_benchmark0_G.addAvlRecursive()); + res.allOps++; + } + + notifyControl.startMeasurement = true; + addAvlRecursive_avgt_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, l_benchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + blackhole.consume(l_benchmark0_G.addAvlRecursive()); + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (Benchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_benchmark0_G.readyIteration) { + l_benchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.tearIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.tearIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + synchronized(this.getClass()) { + f_benchmark0_G = null; + } + } + res.allOps += res.measuredOps; + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + res.measuredOps /= batchSize; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new AverageTimeResult(ResultRole.PRIMARY, "addAvlRecursive", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void addAvlRecursive_avgt_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, Benchmark_jmhType l_benchmark0_G) throws Throwable { + long operations = 0; + long realTime = 0; + result.startTime = System.nanoTime(); + do { + blackhole.consume(l_benchmark0_G.addAvlRecursive()); + operations++; + } while(!control.isDone); + result.stopTime = System.nanoTime(); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult addAvlRecursive_SampleTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + Benchmark_jmhType l_benchmark0_G = _jmh_tryInit_f_benchmark0_G(control); + + control.preSetup(); + if (Benchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_benchmark0_G.readyIteration) { + l_benchmark0_G.generateElements(); + l_benchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.setupIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.setupIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + blackhole.consume(l_benchmark0_G.addAvlRecursive()); + res.allOps++; + } + + notifyControl.startMeasurement = true; + int targetSamples = (int) (control.getDuration(TimeUnit.MILLISECONDS) * 20); // at max, 20 timestamps per millisecond + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + SampleBuffer buffer = new SampleBuffer(); + addAvlRecursive_sample_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, buffer, targetSamples, opsPerInv, batchSize, l_benchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + blackhole.consume(l_benchmark0_G.addAvlRecursive()); + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (Benchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_benchmark0_G.readyIteration) { + l_benchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.tearIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.tearIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + synchronized(this.getClass()) { + f_benchmark0_G = null; + } + } + res.allOps += res.measuredOps * batchSize; + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new SampleTimeResult(ResultRole.PRIMARY, "addAvlRecursive", buffer, benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void addAvlRecursive_sample_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, SampleBuffer buffer, int targetSamples, long opsPerInv, int batchSize, Benchmark_jmhType l_benchmark0_G) throws Throwable { + long realTime = 0; + long operations = 0; + int rnd = (int)System.nanoTime(); + int rndMask = startRndMask; + long time = 0; + int currentStride = 0; + do { + rnd = (rnd * 1664525 + 1013904223); + boolean sample = (rnd & rndMask) == 0; + if (sample) { + time = System.nanoTime(); + } + for (int b = 0; b < batchSize; b++) { + if (control.volatileSpoiler) return; + blackhole.consume(l_benchmark0_G.addAvlRecursive()); + } + if (sample) { + buffer.add((System.nanoTime() - time) / opsPerInv); + if (currentStride++ > targetSamples) { + buffer.half(); + currentStride = 0; + rndMask = (rndMask << 1) + 1; + } + } + operations++; + } while(!control.isDone); + startRndMask = Math.max(startRndMask, rndMask); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult addAvlRecursive_SingleShotTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + Benchmark_jmhType l_benchmark0_G = _jmh_tryInit_f_benchmark0_G(control); + + control.preSetup(); + if (Benchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_benchmark0_G.readyIteration) { + l_benchmark0_G.generateElements(); + l_benchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.setupIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.setupIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + notifyControl.startMeasurement = true; + RawResults res = new RawResults(); + int batchSize = iterationParams.getBatchSize(); + addAvlRecursive_ss_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, batchSize, l_benchmark0_G); + control.preTearDown(); + if (Benchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_benchmark0_G.readyIteration) { + l_benchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.tearIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.tearIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + synchronized(this.getClass()) { + f_benchmark0_G = null; + } + } + int opsPerInv = control.benchmarkParams.getOpsPerInvocation(); + long totalOps = opsPerInv; + BenchmarkTaskResult results = new BenchmarkTaskResult(totalOps, totalOps); + results.add(new SingleShotResult(ResultRole.PRIMARY, "addAvlRecursive", res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void addAvlRecursive_ss_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, int batchSize, Benchmark_jmhType l_benchmark0_G) throws Throwable { + long realTime = 0; + result.startTime = System.nanoTime(); + for (int b = 0; b < batchSize; b++) { + if (control.volatileSpoiler) return; + blackhole.consume(l_benchmark0_G.addAvlRecursive()); + } + result.stopTime = System.nanoTime(); + result.realTime = realTime; + } + + + static volatile Benchmark_jmhType f_benchmark0_G; + + Benchmark_jmhType _jmh_tryInit_f_benchmark0_G(InfraControl control) throws Throwable { + Benchmark_jmhType val = f_benchmark0_G; + if (val != null) { + return val; + } + synchronized(this.getClass()) { + try { + if (control.isFailing) throw new FailureAssistException(); + val = f_benchmark0_G; + if (val != null) { + return val; + } + val = new Benchmark_jmhType(); + Field f; + f = edu.ktu.ds.lab2.demo.Benchmark.class.getDeclaredField("elementCount"); + f.setAccessible(true); + f.set(val, Integer.valueOf(control.getParam("elementCount"))); + val.readyTrial = true; + f_benchmark0_G = val; + } catch (Throwable t) { + control.isFailing = true; + throw t; + } + } + return val; + } + + +} + diff --git a/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_addBstIterative_jmhTest.java b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_addBstIterative_jmhTest.java new file mode 100644 index 0000000..5f648a5 --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_addBstIterative_jmhTest.java @@ -0,0 +1,514 @@ +package edu.ktu.ds.lab2.demo.jmh_generated; + +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.Collection; +import java.util.ArrayList; +import java.util.concurrent.TimeUnit; +import org.openjdk.jmh.annotations.CompilerControl; +import org.openjdk.jmh.runner.InfraControl; +import org.openjdk.jmh.infra.ThreadParams; +import org.openjdk.jmh.results.BenchmarkTaskResult; +import org.openjdk.jmh.results.Result; +import org.openjdk.jmh.results.ThroughputResult; +import org.openjdk.jmh.results.AverageTimeResult; +import org.openjdk.jmh.results.SampleTimeResult; +import org.openjdk.jmh.results.SingleShotResult; +import org.openjdk.jmh.util.SampleBuffer; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Threads; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.results.RawResults; +import org.openjdk.jmh.results.ResultRole; +import java.lang.reflect.Field; +import org.openjdk.jmh.infra.BenchmarkParams; +import org.openjdk.jmh.infra.IterationParams; +import org.openjdk.jmh.infra.Blackhole; +import org.openjdk.jmh.infra.Control; +import org.openjdk.jmh.results.ScalarResult; +import org.openjdk.jmh.results.AggregationPolicy; +import org.openjdk.jmh.runner.FailureAssistException; + +import edu.ktu.ds.lab2.demo.jmh_generated.Benchmark_jmhType; +public final class Benchmark_addBstIterative_jmhTest { + + byte p000, p001, p002, p003, p004, p005, p006, p007, p008, p009, p010, p011, p012, p013, p014, p015; + byte p016, p017, p018, p019, p020, p021, p022, p023, p024, p025, p026, p027, p028, p029, p030, p031; + byte p032, p033, p034, p035, p036, p037, p038, p039, p040, p041, p042, p043, p044, p045, p046, p047; + byte p048, p049, p050, p051, p052, p053, p054, p055, p056, p057, p058, p059, p060, p061, p062, p063; + byte p064, p065, p066, p067, p068, p069, p070, p071, p072, p073, p074, p075, p076, p077, p078, p079; + byte p080, p081, p082, p083, p084, p085, p086, p087, p088, p089, p090, p091, p092, p093, p094, p095; + byte p096, p097, p098, p099, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111; + byte p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127; + byte p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143; + byte p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159; + byte p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175; + byte p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191; + byte p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207; + byte p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223; + byte p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239; + byte p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250, p251, p252, p253, p254, p255; + int startRndMask; + BenchmarkParams benchmarkParams; + IterationParams iterationParams; + ThreadParams threadParams; + Blackhole blackhole; + Control notifyControl; + + public BenchmarkTaskResult addBstIterative_Throughput(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + Benchmark_jmhType l_benchmark0_G = _jmh_tryInit_f_benchmark0_G(control); + + control.preSetup(); + if (Benchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_benchmark0_G.readyIteration) { + l_benchmark0_G.generateElements(); + l_benchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.setupIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.setupIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + blackhole.consume(l_benchmark0_G.addBstIterative()); + res.allOps++; + } + + notifyControl.startMeasurement = true; + addBstIterative_thrpt_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, l_benchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + blackhole.consume(l_benchmark0_G.addBstIterative()); + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (Benchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_benchmark0_G.readyIteration) { + l_benchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.tearIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.tearIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + synchronized(this.getClass()) { + f_benchmark0_G = null; + } + } + res.allOps += res.measuredOps; + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + res.measuredOps /= batchSize; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new ThroughputResult(ResultRole.PRIMARY, "addBstIterative", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void addBstIterative_thrpt_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, Benchmark_jmhType l_benchmark0_G) throws Throwable { + long operations = 0; + long realTime = 0; + result.startTime = System.nanoTime(); + do { + blackhole.consume(l_benchmark0_G.addBstIterative()); + operations++; + } while(!control.isDone); + result.stopTime = System.nanoTime(); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult addBstIterative_AverageTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + Benchmark_jmhType l_benchmark0_G = _jmh_tryInit_f_benchmark0_G(control); + + control.preSetup(); + if (Benchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_benchmark0_G.readyIteration) { + l_benchmark0_G.generateElements(); + l_benchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.setupIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.setupIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + blackhole.consume(l_benchmark0_G.addBstIterative()); + res.allOps++; + } + + notifyControl.startMeasurement = true; + addBstIterative_avgt_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, l_benchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + blackhole.consume(l_benchmark0_G.addBstIterative()); + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (Benchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_benchmark0_G.readyIteration) { + l_benchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.tearIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.tearIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + synchronized(this.getClass()) { + f_benchmark0_G = null; + } + } + res.allOps += res.measuredOps; + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + res.measuredOps /= batchSize; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new AverageTimeResult(ResultRole.PRIMARY, "addBstIterative", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void addBstIterative_avgt_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, Benchmark_jmhType l_benchmark0_G) throws Throwable { + long operations = 0; + long realTime = 0; + result.startTime = System.nanoTime(); + do { + blackhole.consume(l_benchmark0_G.addBstIterative()); + operations++; + } while(!control.isDone); + result.stopTime = System.nanoTime(); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult addBstIterative_SampleTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + Benchmark_jmhType l_benchmark0_G = _jmh_tryInit_f_benchmark0_G(control); + + control.preSetup(); + if (Benchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_benchmark0_G.readyIteration) { + l_benchmark0_G.generateElements(); + l_benchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.setupIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.setupIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + blackhole.consume(l_benchmark0_G.addBstIterative()); + res.allOps++; + } + + notifyControl.startMeasurement = true; + int targetSamples = (int) (control.getDuration(TimeUnit.MILLISECONDS) * 20); // at max, 20 timestamps per millisecond + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + SampleBuffer buffer = new SampleBuffer(); + addBstIterative_sample_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, buffer, targetSamples, opsPerInv, batchSize, l_benchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + blackhole.consume(l_benchmark0_G.addBstIterative()); + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (Benchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_benchmark0_G.readyIteration) { + l_benchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.tearIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.tearIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + synchronized(this.getClass()) { + f_benchmark0_G = null; + } + } + res.allOps += res.measuredOps * batchSize; + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new SampleTimeResult(ResultRole.PRIMARY, "addBstIterative", buffer, benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void addBstIterative_sample_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, SampleBuffer buffer, int targetSamples, long opsPerInv, int batchSize, Benchmark_jmhType l_benchmark0_G) throws Throwable { + long realTime = 0; + long operations = 0; + int rnd = (int)System.nanoTime(); + int rndMask = startRndMask; + long time = 0; + int currentStride = 0; + do { + rnd = (rnd * 1664525 + 1013904223); + boolean sample = (rnd & rndMask) == 0; + if (sample) { + time = System.nanoTime(); + } + for (int b = 0; b < batchSize; b++) { + if (control.volatileSpoiler) return; + blackhole.consume(l_benchmark0_G.addBstIterative()); + } + if (sample) { + buffer.add((System.nanoTime() - time) / opsPerInv); + if (currentStride++ > targetSamples) { + buffer.half(); + currentStride = 0; + rndMask = (rndMask << 1) + 1; + } + } + operations++; + } while(!control.isDone); + startRndMask = Math.max(startRndMask, rndMask); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult addBstIterative_SingleShotTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + Benchmark_jmhType l_benchmark0_G = _jmh_tryInit_f_benchmark0_G(control); + + control.preSetup(); + if (Benchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_benchmark0_G.readyIteration) { + l_benchmark0_G.generateElements(); + l_benchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.setupIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.setupIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + notifyControl.startMeasurement = true; + RawResults res = new RawResults(); + int batchSize = iterationParams.getBatchSize(); + addBstIterative_ss_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, batchSize, l_benchmark0_G); + control.preTearDown(); + if (Benchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_benchmark0_G.readyIteration) { + l_benchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.tearIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.tearIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + synchronized(this.getClass()) { + f_benchmark0_G = null; + } + } + int opsPerInv = control.benchmarkParams.getOpsPerInvocation(); + long totalOps = opsPerInv; + BenchmarkTaskResult results = new BenchmarkTaskResult(totalOps, totalOps); + results.add(new SingleShotResult(ResultRole.PRIMARY, "addBstIterative", res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void addBstIterative_ss_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, int batchSize, Benchmark_jmhType l_benchmark0_G) throws Throwable { + long realTime = 0; + result.startTime = System.nanoTime(); + for (int b = 0; b < batchSize; b++) { + if (control.volatileSpoiler) return; + blackhole.consume(l_benchmark0_G.addBstIterative()); + } + result.stopTime = System.nanoTime(); + result.realTime = realTime; + } + + + static volatile Benchmark_jmhType f_benchmark0_G; + + Benchmark_jmhType _jmh_tryInit_f_benchmark0_G(InfraControl control) throws Throwable { + Benchmark_jmhType val = f_benchmark0_G; + if (val != null) { + return val; + } + synchronized(this.getClass()) { + try { + if (control.isFailing) throw new FailureAssistException(); + val = f_benchmark0_G; + if (val != null) { + return val; + } + val = new Benchmark_jmhType(); + Field f; + f = edu.ktu.ds.lab2.demo.Benchmark.class.getDeclaredField("elementCount"); + f.setAccessible(true); + f.set(val, Integer.valueOf(control.getParam("elementCount"))); + val.readyTrial = true; + f_benchmark0_G = val; + } catch (Throwable t) { + control.isFailing = true; + throw t; + } + } + return val; + } + + +} + diff --git a/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_addBstRecursive_jmhTest.java b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_addBstRecursive_jmhTest.java new file mode 100644 index 0000000..a891f70 --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_addBstRecursive_jmhTest.java @@ -0,0 +1,514 @@ +package edu.ktu.ds.lab2.demo.jmh_generated; + +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.Collection; +import java.util.ArrayList; +import java.util.concurrent.TimeUnit; +import org.openjdk.jmh.annotations.CompilerControl; +import org.openjdk.jmh.runner.InfraControl; +import org.openjdk.jmh.infra.ThreadParams; +import org.openjdk.jmh.results.BenchmarkTaskResult; +import org.openjdk.jmh.results.Result; +import org.openjdk.jmh.results.ThroughputResult; +import org.openjdk.jmh.results.AverageTimeResult; +import org.openjdk.jmh.results.SampleTimeResult; +import org.openjdk.jmh.results.SingleShotResult; +import org.openjdk.jmh.util.SampleBuffer; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Threads; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.results.RawResults; +import org.openjdk.jmh.results.ResultRole; +import java.lang.reflect.Field; +import org.openjdk.jmh.infra.BenchmarkParams; +import org.openjdk.jmh.infra.IterationParams; +import org.openjdk.jmh.infra.Blackhole; +import org.openjdk.jmh.infra.Control; +import org.openjdk.jmh.results.ScalarResult; +import org.openjdk.jmh.results.AggregationPolicy; +import org.openjdk.jmh.runner.FailureAssistException; + +import edu.ktu.ds.lab2.demo.jmh_generated.Benchmark_jmhType; +public final class Benchmark_addBstRecursive_jmhTest { + + byte p000, p001, p002, p003, p004, p005, p006, p007, p008, p009, p010, p011, p012, p013, p014, p015; + byte p016, p017, p018, p019, p020, p021, p022, p023, p024, p025, p026, p027, p028, p029, p030, p031; + byte p032, p033, p034, p035, p036, p037, p038, p039, p040, p041, p042, p043, p044, p045, p046, p047; + byte p048, p049, p050, p051, p052, p053, p054, p055, p056, p057, p058, p059, p060, p061, p062, p063; + byte p064, p065, p066, p067, p068, p069, p070, p071, p072, p073, p074, p075, p076, p077, p078, p079; + byte p080, p081, p082, p083, p084, p085, p086, p087, p088, p089, p090, p091, p092, p093, p094, p095; + byte p096, p097, p098, p099, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111; + byte p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127; + byte p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143; + byte p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159; + byte p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175; + byte p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191; + byte p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207; + byte p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223; + byte p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239; + byte p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250, p251, p252, p253, p254, p255; + int startRndMask; + BenchmarkParams benchmarkParams; + IterationParams iterationParams; + ThreadParams threadParams; + Blackhole blackhole; + Control notifyControl; + + public BenchmarkTaskResult addBstRecursive_Throughput(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + Benchmark_jmhType l_benchmark0_G = _jmh_tryInit_f_benchmark0_G(control); + + control.preSetup(); + if (Benchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_benchmark0_G.readyIteration) { + l_benchmark0_G.generateElements(); + l_benchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.setupIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.setupIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + blackhole.consume(l_benchmark0_G.addBstRecursive()); + res.allOps++; + } + + notifyControl.startMeasurement = true; + addBstRecursive_thrpt_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, l_benchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + blackhole.consume(l_benchmark0_G.addBstRecursive()); + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (Benchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_benchmark0_G.readyIteration) { + l_benchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.tearIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.tearIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + synchronized(this.getClass()) { + f_benchmark0_G = null; + } + } + res.allOps += res.measuredOps; + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + res.measuredOps /= batchSize; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new ThroughputResult(ResultRole.PRIMARY, "addBstRecursive", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void addBstRecursive_thrpt_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, Benchmark_jmhType l_benchmark0_G) throws Throwable { + long operations = 0; + long realTime = 0; + result.startTime = System.nanoTime(); + do { + blackhole.consume(l_benchmark0_G.addBstRecursive()); + operations++; + } while(!control.isDone); + result.stopTime = System.nanoTime(); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult addBstRecursive_AverageTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + Benchmark_jmhType l_benchmark0_G = _jmh_tryInit_f_benchmark0_G(control); + + control.preSetup(); + if (Benchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_benchmark0_G.readyIteration) { + l_benchmark0_G.generateElements(); + l_benchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.setupIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.setupIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + blackhole.consume(l_benchmark0_G.addBstRecursive()); + res.allOps++; + } + + notifyControl.startMeasurement = true; + addBstRecursive_avgt_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, l_benchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + blackhole.consume(l_benchmark0_G.addBstRecursive()); + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (Benchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_benchmark0_G.readyIteration) { + l_benchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.tearIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.tearIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + synchronized(this.getClass()) { + f_benchmark0_G = null; + } + } + res.allOps += res.measuredOps; + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + res.measuredOps /= batchSize; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new AverageTimeResult(ResultRole.PRIMARY, "addBstRecursive", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void addBstRecursive_avgt_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, Benchmark_jmhType l_benchmark0_G) throws Throwable { + long operations = 0; + long realTime = 0; + result.startTime = System.nanoTime(); + do { + blackhole.consume(l_benchmark0_G.addBstRecursive()); + operations++; + } while(!control.isDone); + result.stopTime = System.nanoTime(); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult addBstRecursive_SampleTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + Benchmark_jmhType l_benchmark0_G = _jmh_tryInit_f_benchmark0_G(control); + + control.preSetup(); + if (Benchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_benchmark0_G.readyIteration) { + l_benchmark0_G.generateElements(); + l_benchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.setupIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.setupIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + blackhole.consume(l_benchmark0_G.addBstRecursive()); + res.allOps++; + } + + notifyControl.startMeasurement = true; + int targetSamples = (int) (control.getDuration(TimeUnit.MILLISECONDS) * 20); // at max, 20 timestamps per millisecond + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + SampleBuffer buffer = new SampleBuffer(); + addBstRecursive_sample_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, buffer, targetSamples, opsPerInv, batchSize, l_benchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + blackhole.consume(l_benchmark0_G.addBstRecursive()); + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (Benchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_benchmark0_G.readyIteration) { + l_benchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.tearIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.tearIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + synchronized(this.getClass()) { + f_benchmark0_G = null; + } + } + res.allOps += res.measuredOps * batchSize; + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new SampleTimeResult(ResultRole.PRIMARY, "addBstRecursive", buffer, benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void addBstRecursive_sample_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, SampleBuffer buffer, int targetSamples, long opsPerInv, int batchSize, Benchmark_jmhType l_benchmark0_G) throws Throwable { + long realTime = 0; + long operations = 0; + int rnd = (int)System.nanoTime(); + int rndMask = startRndMask; + long time = 0; + int currentStride = 0; + do { + rnd = (rnd * 1664525 + 1013904223); + boolean sample = (rnd & rndMask) == 0; + if (sample) { + time = System.nanoTime(); + } + for (int b = 0; b < batchSize; b++) { + if (control.volatileSpoiler) return; + blackhole.consume(l_benchmark0_G.addBstRecursive()); + } + if (sample) { + buffer.add((System.nanoTime() - time) / opsPerInv); + if (currentStride++ > targetSamples) { + buffer.half(); + currentStride = 0; + rndMask = (rndMask << 1) + 1; + } + } + operations++; + } while(!control.isDone); + startRndMask = Math.max(startRndMask, rndMask); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult addBstRecursive_SingleShotTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + Benchmark_jmhType l_benchmark0_G = _jmh_tryInit_f_benchmark0_G(control); + + control.preSetup(); + if (Benchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_benchmark0_G.readyIteration) { + l_benchmark0_G.generateElements(); + l_benchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.setupIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.setupIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + notifyControl.startMeasurement = true; + RawResults res = new RawResults(); + int batchSize = iterationParams.getBatchSize(); + addBstRecursive_ss_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, batchSize, l_benchmark0_G); + control.preTearDown(); + if (Benchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_benchmark0_G.readyIteration) { + l_benchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.tearIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.tearIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + synchronized(this.getClass()) { + f_benchmark0_G = null; + } + } + int opsPerInv = control.benchmarkParams.getOpsPerInvocation(); + long totalOps = opsPerInv; + BenchmarkTaskResult results = new BenchmarkTaskResult(totalOps, totalOps); + results.add(new SingleShotResult(ResultRole.PRIMARY, "addBstRecursive", res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void addBstRecursive_ss_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, int batchSize, Benchmark_jmhType l_benchmark0_G) throws Throwable { + long realTime = 0; + result.startTime = System.nanoTime(); + for (int b = 0; b < batchSize; b++) { + if (control.volatileSpoiler) return; + blackhole.consume(l_benchmark0_G.addBstRecursive()); + } + result.stopTime = System.nanoTime(); + result.realTime = realTime; + } + + + static volatile Benchmark_jmhType f_benchmark0_G; + + Benchmark_jmhType _jmh_tryInit_f_benchmark0_G(InfraControl control) throws Throwable { + Benchmark_jmhType val = f_benchmark0_G; + if (val != null) { + return val; + } + synchronized(this.getClass()) { + try { + if (control.isFailing) throw new FailureAssistException(); + val = f_benchmark0_G; + if (val != null) { + return val; + } + val = new Benchmark_jmhType(); + Field f; + f = edu.ktu.ds.lab2.demo.Benchmark.class.getDeclaredField("elementCount"); + f.setAccessible(true); + f.set(val, Integer.valueOf(control.getParam("elementCount"))); + val.readyTrial = true; + f_benchmark0_G = val; + } catch (Throwable t) { + control.isFailing = true; + throw t; + } + } + return val; + } + + +} + diff --git a/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_jmhType.java b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_jmhType.java new file mode 100644 index 0000000..42e87ca --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_jmhType.java @@ -0,0 +1,4 @@ +package edu.ktu.ds.lab2.demo.jmh_generated; +public class Benchmark_jmhType extends Benchmark_jmhType_B3 { +} + diff --git a/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_jmhType_B1.java b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_jmhType_B1.java new file mode 100644 index 0000000..a50e559 --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_jmhType_B1.java @@ -0,0 +1,20 @@ +package edu.ktu.ds.lab2.demo.jmh_generated; +import edu.ktu.ds.lab2.demo.Benchmark; +public class Benchmark_jmhType_B1 extends edu.ktu.ds.lab2.demo.Benchmark { + byte p000, p001, p002, p003, p004, p005, p006, p007, p008, p009, p010, p011, p012, p013, p014, p015; + byte p016, p017, p018, p019, p020, p021, p022, p023, p024, p025, p026, p027, p028, p029, p030, p031; + byte p032, p033, p034, p035, p036, p037, p038, p039, p040, p041, p042, p043, p044, p045, p046, p047; + byte p048, p049, p050, p051, p052, p053, p054, p055, p056, p057, p058, p059, p060, p061, p062, p063; + byte p064, p065, p066, p067, p068, p069, p070, p071, p072, p073, p074, p075, p076, p077, p078, p079; + byte p080, p081, p082, p083, p084, p085, p086, p087, p088, p089, p090, p091, p092, p093, p094, p095; + byte p096, p097, p098, p099, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111; + byte p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127; + byte p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143; + byte p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159; + byte p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175; + byte p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191; + byte p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207; + byte p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223; + byte p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239; + byte p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250, p251, p252, p253, p254, p255; +} diff --git a/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_jmhType_B2.java b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_jmhType_B2.java new file mode 100644 index 0000000..06526fd --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_jmhType_B2.java @@ -0,0 +1,22 @@ +package edu.ktu.ds.lab2.demo.jmh_generated; +import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; +public class Benchmark_jmhType_B2 extends Benchmark_jmhType_B1 { + public volatile int setupTrialMutex; + public volatile int tearTrialMutex; + public final static AtomicIntegerFieldUpdater setupTrialMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(Benchmark_jmhType_B2.class, "setupTrialMutex"); + public final static AtomicIntegerFieldUpdater tearTrialMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(Benchmark_jmhType_B2.class, "tearTrialMutex"); + + public volatile int setupIterationMutex; + public volatile int tearIterationMutex; + public final static AtomicIntegerFieldUpdater setupIterationMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(Benchmark_jmhType_B2.class, "setupIterationMutex"); + public final static AtomicIntegerFieldUpdater tearIterationMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(Benchmark_jmhType_B2.class, "tearIterationMutex"); + + public volatile int setupInvocationMutex; + public volatile int tearInvocationMutex; + public final static AtomicIntegerFieldUpdater setupInvocationMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(Benchmark_jmhType_B2.class, "setupInvocationMutex"); + public final static AtomicIntegerFieldUpdater tearInvocationMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(Benchmark_jmhType_B2.class, "tearInvocationMutex"); + + public volatile boolean readyTrial; + public volatile boolean readyIteration; + public volatile boolean readyInvocation; +} diff --git a/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_jmhType_B3.java b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_jmhType_B3.java new file mode 100644 index 0000000..3ac989a --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_jmhType_B3.java @@ -0,0 +1,20 @@ +package edu.ktu.ds.lab2.demo.jmh_generated; +public class Benchmark_jmhType_B3 extends Benchmark_jmhType_B2 { + byte p000, p001, p002, p003, p004, p005, p006, p007, p008, p009, p010, p011, p012, p013, p014, p015; + byte p016, p017, p018, p019, p020, p021, p022, p023, p024, p025, p026, p027, p028, p029, p030, p031; + byte p032, p033, p034, p035, p036, p037, p038, p039, p040, p041, p042, p043, p044, p045, p046, p047; + byte p048, p049, p050, p051, p052, p053, p054, p055, p056, p057, p058, p059, p060, p061, p062, p063; + byte p064, p065, p066, p067, p068, p069, p070, p071, p072, p073, p074, p075, p076, p077, p078, p079; + byte p080, p081, p082, p083, p084, p085, p086, p087, p088, p089, p090, p091, p092, p093, p094, p095; + byte p096, p097, p098, p099, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111; + byte p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127; + byte p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143; + byte p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159; + byte p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175; + byte p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191; + byte p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207; + byte p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223; + byte p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239; + byte p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250, p251, p252, p253, p254, p255; +} + diff --git a/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_removeBst_jmhTest.java b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_removeBst_jmhTest.java new file mode 100644 index 0000000..149f348 --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-sources/annotations/edu/ktu/ds/lab2/demo/jmh_generated/Benchmark_removeBst_jmhTest.java @@ -0,0 +1,1082 @@ +package edu.ktu.ds.lab2.demo.jmh_generated; + +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.Collection; +import java.util.ArrayList; +import java.util.concurrent.TimeUnit; +import org.openjdk.jmh.annotations.CompilerControl; +import org.openjdk.jmh.runner.InfraControl; +import org.openjdk.jmh.infra.ThreadParams; +import org.openjdk.jmh.results.BenchmarkTaskResult; +import org.openjdk.jmh.results.Result; +import org.openjdk.jmh.results.ThroughputResult; +import org.openjdk.jmh.results.AverageTimeResult; +import org.openjdk.jmh.results.SampleTimeResult; +import org.openjdk.jmh.results.SingleShotResult; +import org.openjdk.jmh.util.SampleBuffer; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Threads; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.results.RawResults; +import org.openjdk.jmh.results.ResultRole; +import java.lang.reflect.Field; +import org.openjdk.jmh.infra.BenchmarkParams; +import org.openjdk.jmh.infra.IterationParams; +import org.openjdk.jmh.infra.Blackhole; +import org.openjdk.jmh.infra.Control; +import org.openjdk.jmh.results.ScalarResult; +import org.openjdk.jmh.results.AggregationPolicy; +import org.openjdk.jmh.runner.FailureAssistException; + +import edu.ktu.ds.lab2.demo.jmh_generated.Benchmark_jmhType; +import edu.ktu.ds.lab2.demo.jmh_generated.Benchmark_FullSet_jmhType; +public final class Benchmark_removeBst_jmhTest { + + byte p000, p001, p002, p003, p004, p005, p006, p007, p008, p009, p010, p011, p012, p013, p014, p015; + byte p016, p017, p018, p019, p020, p021, p022, p023, p024, p025, p026, p027, p028, p029, p030, p031; + byte p032, p033, p034, p035, p036, p037, p038, p039, p040, p041, p042, p043, p044, p045, p046, p047; + byte p048, p049, p050, p051, p052, p053, p054, p055, p056, p057, p058, p059, p060, p061, p062, p063; + byte p064, p065, p066, p067, p068, p069, p070, p071, p072, p073, p074, p075, p076, p077, p078, p079; + byte p080, p081, p082, p083, p084, p085, p086, p087, p088, p089, p090, p091, p092, p093, p094, p095; + byte p096, p097, p098, p099, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111; + byte p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127; + byte p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143; + byte p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159; + byte p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175; + byte p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191; + byte p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207; + byte p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223; + byte p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239; + byte p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250, p251, p252, p253, p254, p255; + int startRndMask; + BenchmarkParams benchmarkParams; + IterationParams iterationParams; + ThreadParams threadParams; + Blackhole blackhole; + Control notifyControl; + + public BenchmarkTaskResult removeBst_Throughput(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + Benchmark_jmhType l_benchmark0_G = _jmh_tryInit_f_benchmark0_G(control); + Benchmark_FullSet_jmhType l_fullset1_G = _jmh_tryInit_f_fullset1_G(control); + + control.preSetup(); + if (Benchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_benchmark0_G.readyIteration) { + l_benchmark0_G.generateElements(); + l_benchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.setupIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.setupIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + if (Benchmark_FullSet_jmhType.setupIterationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_fullset1_G.readyIteration) { + l_fullset1_G.generateElements(benchmarkParams); + l_fullset1_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.setupIterationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.setupIterationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + if (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_fullset1_G.readyInvocation) { + l_fullset1_G.fillCarSet(benchmarkParams); + l_fullset1_G.readyInvocation = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + l_benchmark0_G.removeBst(l_fullset1_G); + if (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_fullset1_G.readyInvocation) { + l_fullset1_G.readyInvocation = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + res.allOps++; + } + + notifyControl.startMeasurement = true; + removeBst_thrpt_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, l_fullset1_G, l_benchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + if (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_fullset1_G.readyInvocation) { + l_fullset1_G.fillCarSet(benchmarkParams); + l_fullset1_G.readyInvocation = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + l_benchmark0_G.removeBst(l_fullset1_G); + if (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_fullset1_G.readyInvocation) { + l_fullset1_G.readyInvocation = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (Benchmark_FullSet_jmhType.tearIterationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_fullset1_G.readyIteration) { + l_fullset1_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.tearIterationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.tearIterationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + if (Benchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_benchmark0_G.readyIteration) { + l_benchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.tearIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.tearIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + synchronized(this.getClass()) { + f_fullset1_G = null; + } + synchronized(this.getClass()) { + f_benchmark0_G = null; + } + } + res.allOps += res.measuredOps; + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + res.measuredOps /= batchSize; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new ThroughputResult(ResultRole.PRIMARY, "removeBst", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void removeBst_thrpt_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, Benchmark_FullSet_jmhType l_fullset1_G, Benchmark_jmhType l_benchmark0_G) throws Throwable { + long operations = 0; + long realTime = 0; + result.startTime = System.nanoTime(); + do { + if (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_fullset1_G.readyInvocation) { + l_fullset1_G.fillCarSet(benchmarkParams); + l_fullset1_G.readyInvocation = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + long rt = System.nanoTime(); + l_benchmark0_G.removeBst(l_fullset1_G); + realTime += (System.nanoTime() - rt); + if (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_fullset1_G.readyInvocation) { + l_fullset1_G.readyInvocation = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + operations++; + } while(!control.isDone); + result.stopTime = System.nanoTime(); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult removeBst_AverageTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + Benchmark_jmhType l_benchmark0_G = _jmh_tryInit_f_benchmark0_G(control); + Benchmark_FullSet_jmhType l_fullset1_G = _jmh_tryInit_f_fullset1_G(control); + + control.preSetup(); + if (Benchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_benchmark0_G.readyIteration) { + l_benchmark0_G.generateElements(); + l_benchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.setupIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.setupIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + if (Benchmark_FullSet_jmhType.setupIterationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_fullset1_G.readyIteration) { + l_fullset1_G.generateElements(benchmarkParams); + l_fullset1_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.setupIterationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.setupIterationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + if (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_fullset1_G.readyInvocation) { + l_fullset1_G.fillCarSet(benchmarkParams); + l_fullset1_G.readyInvocation = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + l_benchmark0_G.removeBst(l_fullset1_G); + if (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_fullset1_G.readyInvocation) { + l_fullset1_G.readyInvocation = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + res.allOps++; + } + + notifyControl.startMeasurement = true; + removeBst_avgt_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, l_fullset1_G, l_benchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + if (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_fullset1_G.readyInvocation) { + l_fullset1_G.fillCarSet(benchmarkParams); + l_fullset1_G.readyInvocation = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + l_benchmark0_G.removeBst(l_fullset1_G); + if (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_fullset1_G.readyInvocation) { + l_fullset1_G.readyInvocation = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (Benchmark_FullSet_jmhType.tearIterationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_fullset1_G.readyIteration) { + l_fullset1_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.tearIterationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.tearIterationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + if (Benchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_benchmark0_G.readyIteration) { + l_benchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.tearIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.tearIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + synchronized(this.getClass()) { + f_fullset1_G = null; + } + synchronized(this.getClass()) { + f_benchmark0_G = null; + } + } + res.allOps += res.measuredOps; + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + res.measuredOps /= batchSize; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new AverageTimeResult(ResultRole.PRIMARY, "removeBst", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void removeBst_avgt_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, Benchmark_FullSet_jmhType l_fullset1_G, Benchmark_jmhType l_benchmark0_G) throws Throwable { + long operations = 0; + long realTime = 0; + result.startTime = System.nanoTime(); + do { + if (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_fullset1_G.readyInvocation) { + l_fullset1_G.fillCarSet(benchmarkParams); + l_fullset1_G.readyInvocation = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + long rt = System.nanoTime(); + l_benchmark0_G.removeBst(l_fullset1_G); + realTime += (System.nanoTime() - rt); + if (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_fullset1_G.readyInvocation) { + l_fullset1_G.readyInvocation = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + operations++; + } while(!control.isDone); + result.stopTime = System.nanoTime(); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult removeBst_SampleTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + Benchmark_jmhType l_benchmark0_G = _jmh_tryInit_f_benchmark0_G(control); + Benchmark_FullSet_jmhType l_fullset1_G = _jmh_tryInit_f_fullset1_G(control); + + control.preSetup(); + if (Benchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_benchmark0_G.readyIteration) { + l_benchmark0_G.generateElements(); + l_benchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.setupIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.setupIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + if (Benchmark_FullSet_jmhType.setupIterationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_fullset1_G.readyIteration) { + l_fullset1_G.generateElements(benchmarkParams); + l_fullset1_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.setupIterationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.setupIterationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + if (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_fullset1_G.readyInvocation) { + l_fullset1_G.fillCarSet(benchmarkParams); + l_fullset1_G.readyInvocation = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + l_benchmark0_G.removeBst(l_fullset1_G); + if (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_fullset1_G.readyInvocation) { + l_fullset1_G.readyInvocation = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + res.allOps++; + } + + notifyControl.startMeasurement = true; + int targetSamples = (int) (control.getDuration(TimeUnit.MILLISECONDS) * 20); // at max, 20 timestamps per millisecond + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + SampleBuffer buffer = new SampleBuffer(); + removeBst_sample_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, buffer, targetSamples, opsPerInv, batchSize, l_fullset1_G, l_benchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + if (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_fullset1_G.readyInvocation) { + l_fullset1_G.fillCarSet(benchmarkParams); + l_fullset1_G.readyInvocation = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + l_benchmark0_G.removeBst(l_fullset1_G); + if (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_fullset1_G.readyInvocation) { + l_fullset1_G.readyInvocation = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (Benchmark_FullSet_jmhType.tearIterationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_fullset1_G.readyIteration) { + l_fullset1_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.tearIterationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.tearIterationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + if (Benchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_benchmark0_G.readyIteration) { + l_benchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.tearIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.tearIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + synchronized(this.getClass()) { + f_fullset1_G = null; + } + synchronized(this.getClass()) { + f_benchmark0_G = null; + } + } + res.allOps += res.measuredOps * batchSize; + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new SampleTimeResult(ResultRole.PRIMARY, "removeBst", buffer, benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void removeBst_sample_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, SampleBuffer buffer, int targetSamples, long opsPerInv, int batchSize, Benchmark_FullSet_jmhType l_fullset1_G, Benchmark_jmhType l_benchmark0_G) throws Throwable { + long realTime = 0; + long operations = 0; + int rnd = (int)System.nanoTime(); + int rndMask = startRndMask; + long time = 0; + int currentStride = 0; + do { + if (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_fullset1_G.readyInvocation) { + l_fullset1_G.fillCarSet(benchmarkParams); + l_fullset1_G.readyInvocation = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + long rt = System.nanoTime(); + rnd = (rnd * 1664525 + 1013904223); + boolean sample = (rnd & rndMask) == 0; + if (sample) { + time = System.nanoTime(); + } + for (int b = 0; b < batchSize; b++) { + if (control.volatileSpoiler) return; + l_benchmark0_G.removeBst(l_fullset1_G); + } + if (sample) { + buffer.add((System.nanoTime() - time) / opsPerInv); + if (currentStride++ > targetSamples) { + buffer.half(); + currentStride = 0; + rndMask = (rndMask << 1) + 1; + } + } + realTime += (System.nanoTime() - rt); + if (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_fullset1_G.readyInvocation) { + l_fullset1_G.readyInvocation = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + operations++; + } while(!control.isDone); + startRndMask = Math.max(startRndMask, rndMask); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult removeBst_SingleShotTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + Benchmark_jmhType l_benchmark0_G = _jmh_tryInit_f_benchmark0_G(control); + Benchmark_FullSet_jmhType l_fullset1_G = _jmh_tryInit_f_fullset1_G(control); + + control.preSetup(); + if (Benchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_benchmark0_G.readyIteration) { + l_benchmark0_G.generateElements(); + l_benchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.setupIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.setupIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + if (Benchmark_FullSet_jmhType.setupIterationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_fullset1_G.readyIteration) { + l_fullset1_G.generateElements(benchmarkParams); + l_fullset1_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.setupIterationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.setupIterationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + notifyControl.startMeasurement = true; + RawResults res = new RawResults(); + int batchSize = iterationParams.getBatchSize(); + removeBst_ss_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, batchSize, l_fullset1_G, l_benchmark0_G); + control.preTearDown(); + if (Benchmark_FullSet_jmhType.tearIterationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_fullset1_G.readyIteration) { + l_fullset1_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.tearIterationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.tearIterationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + if (Benchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_benchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_benchmark0_G.readyIteration) { + l_benchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_jmhType.tearIterationMutexUpdater.set(l_benchmark0_G, 0); + } + } else { + while (Benchmark_jmhType.tearIterationMutexUpdater.get(l_benchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + synchronized(this.getClass()) { + f_fullset1_G = null; + } + synchronized(this.getClass()) { + f_benchmark0_G = null; + } + } + int opsPerInv = control.benchmarkParams.getOpsPerInvocation(); + long totalOps = opsPerInv; + BenchmarkTaskResult results = new BenchmarkTaskResult(totalOps, totalOps); + results.add(new SingleShotResult(ResultRole.PRIMARY, "removeBst", res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void removeBst_ss_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, int batchSize, Benchmark_FullSet_jmhType l_fullset1_G, Benchmark_jmhType l_benchmark0_G) throws Throwable { + long realTime = 0; + result.startTime = System.nanoTime(); + for (int b = 0; b < batchSize; b++) { + if (control.volatileSpoiler) return; + if (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_fullset1_G.readyInvocation) { + l_fullset1_G.fillCarSet(benchmarkParams); + l_fullset1_G.readyInvocation = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.setupInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + long rt = System.nanoTime(); + l_benchmark0_G.removeBst(l_fullset1_G); + realTime += (System.nanoTime() - rt); + if (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.compareAndSet(l_fullset1_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_fullset1_G.readyInvocation) { + l_fullset1_G.readyInvocation = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.set(l_fullset1_G, 0); + } + } else { + while (Benchmark_FullSet_jmhType.tearInvocationMutexUpdater.get(l_fullset1_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + } + result.stopTime = System.nanoTime(); + result.realTime = realTime; + } + + + static volatile Benchmark_jmhType f_benchmark0_G; + + Benchmark_jmhType _jmh_tryInit_f_benchmark0_G(InfraControl control) throws Throwable { + Benchmark_jmhType val = f_benchmark0_G; + if (val != null) { + return val; + } + synchronized(this.getClass()) { + try { + if (control.isFailing) throw new FailureAssistException(); + val = f_benchmark0_G; + if (val != null) { + return val; + } + val = new Benchmark_jmhType(); + Field f; + f = edu.ktu.ds.lab2.demo.Benchmark.class.getDeclaredField("elementCount"); + f.setAccessible(true); + f.set(val, Integer.valueOf(control.getParam("elementCount"))); + val.readyTrial = true; + f_benchmark0_G = val; + } catch (Throwable t) { + control.isFailing = true; + throw t; + } + } + return val; + } + + static volatile Benchmark_FullSet_jmhType f_fullset1_G; + + Benchmark_FullSet_jmhType _jmh_tryInit_f_fullset1_G(InfraControl control) throws Throwable { + Benchmark_FullSet_jmhType val = f_fullset1_G; + if (val != null) { + return val; + } + synchronized(this.getClass()) { + try { + if (control.isFailing) throw new FailureAssistException(); + val = f_fullset1_G; + if (val != null) { + return val; + } + val = new Benchmark_FullSet_jmhType(); + val.readyTrial = true; + f_fullset1_G = val; + } catch (Throwable t) { + control.isFailing = true; + throw t; + } + } + return val; + } + + +} + diff --git a/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_avlSetAddAll_jmhTest.java b/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_avlSetAddAll_jmhTest.java new file mode 100644 index 0000000..9211117 --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_avlSetAddAll_jmhTest.java @@ -0,0 +1,599 @@ +package edu.ktu.ds.lab2.jmh_generated; + +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.Collection; +import java.util.ArrayList; +import java.util.concurrent.TimeUnit; +import org.openjdk.jmh.annotations.CompilerControl; +import org.openjdk.jmh.runner.InfraControl; +import org.openjdk.jmh.infra.ThreadParams; +import org.openjdk.jmh.results.BenchmarkTaskResult; +import org.openjdk.jmh.results.Result; +import org.openjdk.jmh.results.ThroughputResult; +import org.openjdk.jmh.results.AverageTimeResult; +import org.openjdk.jmh.results.SampleTimeResult; +import org.openjdk.jmh.results.SingleShotResult; +import org.openjdk.jmh.util.SampleBuffer; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Threads; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.results.RawResults; +import org.openjdk.jmh.results.ResultRole; +import java.lang.reflect.Field; +import org.openjdk.jmh.infra.BenchmarkParams; +import org.openjdk.jmh.infra.IterationParams; +import org.openjdk.jmh.infra.Blackhole; +import org.openjdk.jmh.infra.Control; +import org.openjdk.jmh.results.ScalarResult; +import org.openjdk.jmh.results.AggregationPolicy; +import org.openjdk.jmh.runner.FailureAssistException; + +import edu.ktu.ds.lab2.jmh_generated.AddAllBenchmark_jmhType; +public final class AddAllBenchmark_avlSetAddAll_jmhTest { + + byte p000, p001, p002, p003, p004, p005, p006, p007, p008, p009, p010, p011, p012, p013, p014, p015; + byte p016, p017, p018, p019, p020, p021, p022, p023, p024, p025, p026, p027, p028, p029, p030, p031; + byte p032, p033, p034, p035, p036, p037, p038, p039, p040, p041, p042, p043, p044, p045, p046, p047; + byte p048, p049, p050, p051, p052, p053, p054, p055, p056, p057, p058, p059, p060, p061, p062, p063; + byte p064, p065, p066, p067, p068, p069, p070, p071, p072, p073, p074, p075, p076, p077, p078, p079; + byte p080, p081, p082, p083, p084, p085, p086, p087, p088, p089, p090, p091, p092, p093, p094, p095; + byte p096, p097, p098, p099, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111; + byte p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127; + byte p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143; + byte p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159; + byte p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175; + byte p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191; + byte p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207; + byte p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223; + byte p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239; + byte p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250, p251, p252, p253, p254, p255; + int startRndMask; + BenchmarkParams benchmarkParams; + IterationParams iterationParams; + ThreadParams threadParams; + Blackhole blackhole; + Control notifyControl; + + public BenchmarkTaskResult avlSetAddAll_Throughput(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + AddAllBenchmark_jmhType l_addallbenchmark0_G = _jmh_tryInit_f_addallbenchmark0_G(control); + + control.preSetup(); + if (AddAllBenchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_addallbenchmark0_G.readyIteration) { + l_addallbenchmark0_G.createSets(); + l_addallbenchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.setupIterationMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + while (AddAllBenchmark_jmhType.setupIterationMutexUpdater.get(l_addallbenchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + l_addallbenchmark0_G.avlSetAddAll(blackhole); + res.allOps++; + } + + notifyControl.startMeasurement = true; + avlSetAddAll_thrpt_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, l_addallbenchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + l_addallbenchmark0_G.avlSetAddAll(blackhole); + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (AddAllBenchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_addallbenchmark0_G.readyIteration) { + l_addallbenchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.tearIterationMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + while (AddAllBenchmark_jmhType.tearIterationMutexUpdater.get(l_addallbenchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + if (AddAllBenchmark_jmhType.tearTrialMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_addallbenchmark0_G.readyTrial) { + l_addallbenchmark0_G.readyTrial = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.tearTrialMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + long l_addallbenchmark0_G_backoff = 1; + while (AddAllBenchmark_jmhType.tearTrialMutexUpdater.get(l_addallbenchmark0_G) == 1) { + TimeUnit.MILLISECONDS.sleep(l_addallbenchmark0_G_backoff); + l_addallbenchmark0_G_backoff = Math.max(1024, l_addallbenchmark0_G_backoff * 2); + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + synchronized(this.getClass()) { + f_addallbenchmark0_G = null; + } + } + res.allOps += res.measuredOps; + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + res.measuredOps /= batchSize; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new ThroughputResult(ResultRole.PRIMARY, "avlSetAddAll", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void avlSetAddAll_thrpt_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, AddAllBenchmark_jmhType l_addallbenchmark0_G) throws Throwable { + long operations = 0; + long realTime = 0; + result.startTime = System.nanoTime(); + do { + l_addallbenchmark0_G.avlSetAddAll(blackhole); + operations++; + } while(!control.isDone); + result.stopTime = System.nanoTime(); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult avlSetAddAll_AverageTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + AddAllBenchmark_jmhType l_addallbenchmark0_G = _jmh_tryInit_f_addallbenchmark0_G(control); + + control.preSetup(); + if (AddAllBenchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_addallbenchmark0_G.readyIteration) { + l_addallbenchmark0_G.createSets(); + l_addallbenchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.setupIterationMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + while (AddAllBenchmark_jmhType.setupIterationMutexUpdater.get(l_addallbenchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + l_addallbenchmark0_G.avlSetAddAll(blackhole); + res.allOps++; + } + + notifyControl.startMeasurement = true; + avlSetAddAll_avgt_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, l_addallbenchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + l_addallbenchmark0_G.avlSetAddAll(blackhole); + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (AddAllBenchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_addallbenchmark0_G.readyIteration) { + l_addallbenchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.tearIterationMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + while (AddAllBenchmark_jmhType.tearIterationMutexUpdater.get(l_addallbenchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + if (AddAllBenchmark_jmhType.tearTrialMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_addallbenchmark0_G.readyTrial) { + l_addallbenchmark0_G.readyTrial = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.tearTrialMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + long l_addallbenchmark0_G_backoff = 1; + while (AddAllBenchmark_jmhType.tearTrialMutexUpdater.get(l_addallbenchmark0_G) == 1) { + TimeUnit.MILLISECONDS.sleep(l_addallbenchmark0_G_backoff); + l_addallbenchmark0_G_backoff = Math.max(1024, l_addallbenchmark0_G_backoff * 2); + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + synchronized(this.getClass()) { + f_addallbenchmark0_G = null; + } + } + res.allOps += res.measuredOps; + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + res.measuredOps /= batchSize; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new AverageTimeResult(ResultRole.PRIMARY, "avlSetAddAll", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void avlSetAddAll_avgt_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, AddAllBenchmark_jmhType l_addallbenchmark0_G) throws Throwable { + long operations = 0; + long realTime = 0; + result.startTime = System.nanoTime(); + do { + l_addallbenchmark0_G.avlSetAddAll(blackhole); + operations++; + } while(!control.isDone); + result.stopTime = System.nanoTime(); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult avlSetAddAll_SampleTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + AddAllBenchmark_jmhType l_addallbenchmark0_G = _jmh_tryInit_f_addallbenchmark0_G(control); + + control.preSetup(); + if (AddAllBenchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_addallbenchmark0_G.readyIteration) { + l_addallbenchmark0_G.createSets(); + l_addallbenchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.setupIterationMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + while (AddAllBenchmark_jmhType.setupIterationMutexUpdater.get(l_addallbenchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + l_addallbenchmark0_G.avlSetAddAll(blackhole); + res.allOps++; + } + + notifyControl.startMeasurement = true; + int targetSamples = (int) (control.getDuration(TimeUnit.MILLISECONDS) * 20); // at max, 20 timestamps per millisecond + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + SampleBuffer buffer = new SampleBuffer(); + avlSetAddAll_sample_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, buffer, targetSamples, opsPerInv, batchSize, l_addallbenchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + l_addallbenchmark0_G.avlSetAddAll(blackhole); + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (AddAllBenchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_addallbenchmark0_G.readyIteration) { + l_addallbenchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.tearIterationMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + while (AddAllBenchmark_jmhType.tearIterationMutexUpdater.get(l_addallbenchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + if (AddAllBenchmark_jmhType.tearTrialMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_addallbenchmark0_G.readyTrial) { + l_addallbenchmark0_G.readyTrial = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.tearTrialMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + long l_addallbenchmark0_G_backoff = 1; + while (AddAllBenchmark_jmhType.tearTrialMutexUpdater.get(l_addallbenchmark0_G) == 1) { + TimeUnit.MILLISECONDS.sleep(l_addallbenchmark0_G_backoff); + l_addallbenchmark0_G_backoff = Math.max(1024, l_addallbenchmark0_G_backoff * 2); + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + synchronized(this.getClass()) { + f_addallbenchmark0_G = null; + } + } + res.allOps += res.measuredOps * batchSize; + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new SampleTimeResult(ResultRole.PRIMARY, "avlSetAddAll", buffer, benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void avlSetAddAll_sample_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, SampleBuffer buffer, int targetSamples, long opsPerInv, int batchSize, AddAllBenchmark_jmhType l_addallbenchmark0_G) throws Throwable { + long realTime = 0; + long operations = 0; + int rnd = (int)System.nanoTime(); + int rndMask = startRndMask; + long time = 0; + int currentStride = 0; + do { + rnd = (rnd * 1664525 + 1013904223); + boolean sample = (rnd & rndMask) == 0; + if (sample) { + time = System.nanoTime(); + } + for (int b = 0; b < batchSize; b++) { + if (control.volatileSpoiler) return; + l_addallbenchmark0_G.avlSetAddAll(blackhole); + } + if (sample) { + buffer.add((System.nanoTime() - time) / opsPerInv); + if (currentStride++ > targetSamples) { + buffer.half(); + currentStride = 0; + rndMask = (rndMask << 1) + 1; + } + } + operations++; + } while(!control.isDone); + startRndMask = Math.max(startRndMask, rndMask); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult avlSetAddAll_SingleShotTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + AddAllBenchmark_jmhType l_addallbenchmark0_G = _jmh_tryInit_f_addallbenchmark0_G(control); + + control.preSetup(); + if (AddAllBenchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_addallbenchmark0_G.readyIteration) { + l_addallbenchmark0_G.createSets(); + l_addallbenchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.setupIterationMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + while (AddAllBenchmark_jmhType.setupIterationMutexUpdater.get(l_addallbenchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + notifyControl.startMeasurement = true; + RawResults res = new RawResults(); + int batchSize = iterationParams.getBatchSize(); + avlSetAddAll_ss_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, batchSize, l_addallbenchmark0_G); + control.preTearDown(); + if (AddAllBenchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_addallbenchmark0_G.readyIteration) { + l_addallbenchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.tearIterationMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + while (AddAllBenchmark_jmhType.tearIterationMutexUpdater.get(l_addallbenchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + if (AddAllBenchmark_jmhType.tearTrialMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_addallbenchmark0_G.readyTrial) { + l_addallbenchmark0_G.readyTrial = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.tearTrialMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + long l_addallbenchmark0_G_backoff = 1; + while (AddAllBenchmark_jmhType.tearTrialMutexUpdater.get(l_addallbenchmark0_G) == 1) { + TimeUnit.MILLISECONDS.sleep(l_addallbenchmark0_G_backoff); + l_addallbenchmark0_G_backoff = Math.max(1024, l_addallbenchmark0_G_backoff * 2); + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + synchronized(this.getClass()) { + f_addallbenchmark0_G = null; + } + } + int opsPerInv = control.benchmarkParams.getOpsPerInvocation(); + long totalOps = opsPerInv; + BenchmarkTaskResult results = new BenchmarkTaskResult(totalOps, totalOps); + results.add(new SingleShotResult(ResultRole.PRIMARY, "avlSetAddAll", res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void avlSetAddAll_ss_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, int batchSize, AddAllBenchmark_jmhType l_addallbenchmark0_G) throws Throwable { + long realTime = 0; + result.startTime = System.nanoTime(); + for (int b = 0; b < batchSize; b++) { + if (control.volatileSpoiler) return; + l_addallbenchmark0_G.avlSetAddAll(blackhole); + } + result.stopTime = System.nanoTime(); + result.realTime = realTime; + } + + + static volatile AddAllBenchmark_jmhType f_addallbenchmark0_G; + + AddAllBenchmark_jmhType _jmh_tryInit_f_addallbenchmark0_G(InfraControl control) throws Throwable { + AddAllBenchmark_jmhType val = f_addallbenchmark0_G; + if (val != null) { + return val; + } + synchronized(this.getClass()) { + try { + if (control.isFailing) throw new FailureAssistException(); + val = f_addallbenchmark0_G; + if (val != null) { + return val; + } + val = new AddAllBenchmark_jmhType(); + Field f; + f = edu.ktu.ds.lab2.AddAllBenchmark.class.getDeclaredField("listSize"); + f.setAccessible(true); + f.set(val, Integer.valueOf(control.getParam("listSize"))); + val.generateChunks(); + val.readyTrial = true; + f_addallbenchmark0_G = val; + } catch (Throwable t) { + control.isFailing = true; + throw t; + } + } + return val; + } + + +} + diff --git a/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_bstSetAddAll_jmhTest.java b/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_bstSetAddAll_jmhTest.java new file mode 100644 index 0000000..5e23719 --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_bstSetAddAll_jmhTest.java @@ -0,0 +1,599 @@ +package edu.ktu.ds.lab2.jmh_generated; + +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.Collection; +import java.util.ArrayList; +import java.util.concurrent.TimeUnit; +import org.openjdk.jmh.annotations.CompilerControl; +import org.openjdk.jmh.runner.InfraControl; +import org.openjdk.jmh.infra.ThreadParams; +import org.openjdk.jmh.results.BenchmarkTaskResult; +import org.openjdk.jmh.results.Result; +import org.openjdk.jmh.results.ThroughputResult; +import org.openjdk.jmh.results.AverageTimeResult; +import org.openjdk.jmh.results.SampleTimeResult; +import org.openjdk.jmh.results.SingleShotResult; +import org.openjdk.jmh.util.SampleBuffer; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Threads; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.results.RawResults; +import org.openjdk.jmh.results.ResultRole; +import java.lang.reflect.Field; +import org.openjdk.jmh.infra.BenchmarkParams; +import org.openjdk.jmh.infra.IterationParams; +import org.openjdk.jmh.infra.Blackhole; +import org.openjdk.jmh.infra.Control; +import org.openjdk.jmh.results.ScalarResult; +import org.openjdk.jmh.results.AggregationPolicy; +import org.openjdk.jmh.runner.FailureAssistException; + +import edu.ktu.ds.lab2.jmh_generated.AddAllBenchmark_jmhType; +public final class AddAllBenchmark_bstSetAddAll_jmhTest { + + byte p000, p001, p002, p003, p004, p005, p006, p007, p008, p009, p010, p011, p012, p013, p014, p015; + byte p016, p017, p018, p019, p020, p021, p022, p023, p024, p025, p026, p027, p028, p029, p030, p031; + byte p032, p033, p034, p035, p036, p037, p038, p039, p040, p041, p042, p043, p044, p045, p046, p047; + byte p048, p049, p050, p051, p052, p053, p054, p055, p056, p057, p058, p059, p060, p061, p062, p063; + byte p064, p065, p066, p067, p068, p069, p070, p071, p072, p073, p074, p075, p076, p077, p078, p079; + byte p080, p081, p082, p083, p084, p085, p086, p087, p088, p089, p090, p091, p092, p093, p094, p095; + byte p096, p097, p098, p099, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111; + byte p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127; + byte p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143; + byte p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159; + byte p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175; + byte p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191; + byte p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207; + byte p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223; + byte p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239; + byte p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250, p251, p252, p253, p254, p255; + int startRndMask; + BenchmarkParams benchmarkParams; + IterationParams iterationParams; + ThreadParams threadParams; + Blackhole blackhole; + Control notifyControl; + + public BenchmarkTaskResult bstSetAddAll_Throughput(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + AddAllBenchmark_jmhType l_addallbenchmark0_G = _jmh_tryInit_f_addallbenchmark0_G(control); + + control.preSetup(); + if (AddAllBenchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_addallbenchmark0_G.readyIteration) { + l_addallbenchmark0_G.createSets(); + l_addallbenchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.setupIterationMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + while (AddAllBenchmark_jmhType.setupIterationMutexUpdater.get(l_addallbenchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + l_addallbenchmark0_G.bstSetAddAll(blackhole); + res.allOps++; + } + + notifyControl.startMeasurement = true; + bstSetAddAll_thrpt_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, l_addallbenchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + l_addallbenchmark0_G.bstSetAddAll(blackhole); + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (AddAllBenchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_addallbenchmark0_G.readyIteration) { + l_addallbenchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.tearIterationMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + while (AddAllBenchmark_jmhType.tearIterationMutexUpdater.get(l_addallbenchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + if (AddAllBenchmark_jmhType.tearTrialMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_addallbenchmark0_G.readyTrial) { + l_addallbenchmark0_G.readyTrial = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.tearTrialMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + long l_addallbenchmark0_G_backoff = 1; + while (AddAllBenchmark_jmhType.tearTrialMutexUpdater.get(l_addallbenchmark0_G) == 1) { + TimeUnit.MILLISECONDS.sleep(l_addallbenchmark0_G_backoff); + l_addallbenchmark0_G_backoff = Math.max(1024, l_addallbenchmark0_G_backoff * 2); + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + synchronized(this.getClass()) { + f_addallbenchmark0_G = null; + } + } + res.allOps += res.measuredOps; + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + res.measuredOps /= batchSize; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new ThroughputResult(ResultRole.PRIMARY, "bstSetAddAll", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void bstSetAddAll_thrpt_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, AddAllBenchmark_jmhType l_addallbenchmark0_G) throws Throwable { + long operations = 0; + long realTime = 0; + result.startTime = System.nanoTime(); + do { + l_addallbenchmark0_G.bstSetAddAll(blackhole); + operations++; + } while(!control.isDone); + result.stopTime = System.nanoTime(); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult bstSetAddAll_AverageTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + AddAllBenchmark_jmhType l_addallbenchmark0_G = _jmh_tryInit_f_addallbenchmark0_G(control); + + control.preSetup(); + if (AddAllBenchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_addallbenchmark0_G.readyIteration) { + l_addallbenchmark0_G.createSets(); + l_addallbenchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.setupIterationMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + while (AddAllBenchmark_jmhType.setupIterationMutexUpdater.get(l_addallbenchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + l_addallbenchmark0_G.bstSetAddAll(blackhole); + res.allOps++; + } + + notifyControl.startMeasurement = true; + bstSetAddAll_avgt_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, l_addallbenchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + l_addallbenchmark0_G.bstSetAddAll(blackhole); + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (AddAllBenchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_addallbenchmark0_G.readyIteration) { + l_addallbenchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.tearIterationMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + while (AddAllBenchmark_jmhType.tearIterationMutexUpdater.get(l_addallbenchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + if (AddAllBenchmark_jmhType.tearTrialMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_addallbenchmark0_G.readyTrial) { + l_addallbenchmark0_G.readyTrial = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.tearTrialMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + long l_addallbenchmark0_G_backoff = 1; + while (AddAllBenchmark_jmhType.tearTrialMutexUpdater.get(l_addallbenchmark0_G) == 1) { + TimeUnit.MILLISECONDS.sleep(l_addallbenchmark0_G_backoff); + l_addallbenchmark0_G_backoff = Math.max(1024, l_addallbenchmark0_G_backoff * 2); + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + synchronized(this.getClass()) { + f_addallbenchmark0_G = null; + } + } + res.allOps += res.measuredOps; + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + res.measuredOps /= batchSize; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new AverageTimeResult(ResultRole.PRIMARY, "bstSetAddAll", res.measuredOps, res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void bstSetAddAll_avgt_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, AddAllBenchmark_jmhType l_addallbenchmark0_G) throws Throwable { + long operations = 0; + long realTime = 0; + result.startTime = System.nanoTime(); + do { + l_addallbenchmark0_G.bstSetAddAll(blackhole); + operations++; + } while(!control.isDone); + result.stopTime = System.nanoTime(); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult bstSetAddAll_SampleTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + RawResults res = new RawResults(); + AddAllBenchmark_jmhType l_addallbenchmark0_G = _jmh_tryInit_f_addallbenchmark0_G(control); + + control.preSetup(); + if (AddAllBenchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_addallbenchmark0_G.readyIteration) { + l_addallbenchmark0_G.createSets(); + l_addallbenchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.setupIterationMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + while (AddAllBenchmark_jmhType.setupIterationMutexUpdater.get(l_addallbenchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + control.announceWarmupReady(); + while (control.warmupShouldWait) { + l_addallbenchmark0_G.bstSetAddAll(blackhole); + res.allOps++; + } + + notifyControl.startMeasurement = true; + int targetSamples = (int) (control.getDuration(TimeUnit.MILLISECONDS) * 20); // at max, 20 timestamps per millisecond + int batchSize = iterationParams.getBatchSize(); + int opsPerInv = benchmarkParams.getOpsPerInvocation(); + SampleBuffer buffer = new SampleBuffer(); + bstSetAddAll_sample_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, buffer, targetSamples, opsPerInv, batchSize, l_addallbenchmark0_G); + notifyControl.stopMeasurement = true; + control.announceWarmdownReady(); + try { + while (control.warmdownShouldWait) { + l_addallbenchmark0_G.bstSetAddAll(blackhole); + res.allOps++; + } + control.preTearDown(); + } catch (InterruptedException ie) { + control.preTearDownForce(); + } + if (AddAllBenchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_addallbenchmark0_G.readyIteration) { + l_addallbenchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.tearIterationMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + while (AddAllBenchmark_jmhType.tearIterationMutexUpdater.get(l_addallbenchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + if (AddAllBenchmark_jmhType.tearTrialMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_addallbenchmark0_G.readyTrial) { + l_addallbenchmark0_G.readyTrial = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.tearTrialMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + long l_addallbenchmark0_G_backoff = 1; + while (AddAllBenchmark_jmhType.tearTrialMutexUpdater.get(l_addallbenchmark0_G) == 1) { + TimeUnit.MILLISECONDS.sleep(l_addallbenchmark0_G_backoff); + l_addallbenchmark0_G_backoff = Math.max(1024, l_addallbenchmark0_G_backoff * 2); + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + synchronized(this.getClass()) { + f_addallbenchmark0_G = null; + } + } + res.allOps += res.measuredOps * batchSize; + res.allOps *= opsPerInv; + res.allOps /= batchSize; + res.measuredOps *= opsPerInv; + BenchmarkTaskResult results = new BenchmarkTaskResult(res.allOps, res.measuredOps); + results.add(new SampleTimeResult(ResultRole.PRIMARY, "bstSetAddAll", buffer, benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void bstSetAddAll_sample_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, SampleBuffer buffer, int targetSamples, long opsPerInv, int batchSize, AddAllBenchmark_jmhType l_addallbenchmark0_G) throws Throwable { + long realTime = 0; + long operations = 0; + int rnd = (int)System.nanoTime(); + int rndMask = startRndMask; + long time = 0; + int currentStride = 0; + do { + rnd = (rnd * 1664525 + 1013904223); + boolean sample = (rnd & rndMask) == 0; + if (sample) { + time = System.nanoTime(); + } + for (int b = 0; b < batchSize; b++) { + if (control.volatileSpoiler) return; + l_addallbenchmark0_G.bstSetAddAll(blackhole); + } + if (sample) { + buffer.add((System.nanoTime() - time) / opsPerInv); + if (currentStride++ > targetSamples) { + buffer.half(); + currentStride = 0; + rndMask = (rndMask << 1) + 1; + } + } + operations++; + } while(!control.isDone); + startRndMask = Math.max(startRndMask, rndMask); + result.realTime = realTime; + result.measuredOps = operations; + } + + + public BenchmarkTaskResult bstSetAddAll_SingleShotTime(InfraControl control, ThreadParams threadParams) throws Throwable { + this.benchmarkParams = control.benchmarkParams; + this.iterationParams = control.iterationParams; + this.threadParams = threadParams; + this.notifyControl = control.notifyControl; + if (this.blackhole == null) { + this.blackhole = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); + } + if (threadParams.getSubgroupIndex() == 0) { + AddAllBenchmark_jmhType l_addallbenchmark0_G = _jmh_tryInit_f_addallbenchmark0_G(control); + + control.preSetup(); + if (AddAllBenchmark_jmhType.setupIterationMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (!l_addallbenchmark0_G.readyIteration) { + l_addallbenchmark0_G.createSets(); + l_addallbenchmark0_G.readyIteration = true; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.setupIterationMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + while (AddAllBenchmark_jmhType.setupIterationMutexUpdater.get(l_addallbenchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + + notifyControl.startMeasurement = true; + RawResults res = new RawResults(); + int batchSize = iterationParams.getBatchSize(); + bstSetAddAll_ss_jmhStub(control, res, benchmarkParams, iterationParams, threadParams, blackhole, notifyControl, startRndMask, batchSize, l_addallbenchmark0_G); + control.preTearDown(); + if (AddAllBenchmark_jmhType.tearIterationMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_addallbenchmark0_G.readyIteration) { + l_addallbenchmark0_G.readyIteration = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.tearIterationMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + while (AddAllBenchmark_jmhType.tearIterationMutexUpdater.get(l_addallbenchmark0_G) == 1) { + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + + if (control.isLastIteration()) { + if (AddAllBenchmark_jmhType.tearTrialMutexUpdater.compareAndSet(l_addallbenchmark0_G, 0, 1)) { + try { + if (control.isFailing) throw new FailureAssistException(); + if (l_addallbenchmark0_G.readyTrial) { + l_addallbenchmark0_G.readyTrial = false; + } + } catch (Throwable t) { + control.isFailing = true; + throw t; + } finally { + AddAllBenchmark_jmhType.tearTrialMutexUpdater.set(l_addallbenchmark0_G, 0); + } + } else { + long l_addallbenchmark0_G_backoff = 1; + while (AddAllBenchmark_jmhType.tearTrialMutexUpdater.get(l_addallbenchmark0_G) == 1) { + TimeUnit.MILLISECONDS.sleep(l_addallbenchmark0_G_backoff); + l_addallbenchmark0_G_backoff = Math.max(1024, l_addallbenchmark0_G_backoff * 2); + if (control.isFailing) throw new FailureAssistException(); + if (Thread.interrupted()) throw new InterruptedException(); + } + } + synchronized(this.getClass()) { + f_addallbenchmark0_G = null; + } + } + int opsPerInv = control.benchmarkParams.getOpsPerInvocation(); + long totalOps = opsPerInv; + BenchmarkTaskResult results = new BenchmarkTaskResult(totalOps, totalOps); + results.add(new SingleShotResult(ResultRole.PRIMARY, "bstSetAddAll", res.getTime(), benchmarkParams.getTimeUnit())); + this.blackhole.evaporate("Yes, I am Stephen Hawking, and know a thing or two about black holes."); + return results; + } else + throw new IllegalStateException("Harness failed to distribute threads among groups properly"); + } + + public static void bstSetAddAll_ss_jmhStub(InfraControl control, RawResults result, BenchmarkParams benchmarkParams, IterationParams iterationParams, ThreadParams threadParams, Blackhole blackhole, Control notifyControl, int startRndMask, int batchSize, AddAllBenchmark_jmhType l_addallbenchmark0_G) throws Throwable { + long realTime = 0; + result.startTime = System.nanoTime(); + for (int b = 0; b < batchSize; b++) { + if (control.volatileSpoiler) return; + l_addallbenchmark0_G.bstSetAddAll(blackhole); + } + result.stopTime = System.nanoTime(); + result.realTime = realTime; + } + + + static volatile AddAllBenchmark_jmhType f_addallbenchmark0_G; + + AddAllBenchmark_jmhType _jmh_tryInit_f_addallbenchmark0_G(InfraControl control) throws Throwable { + AddAllBenchmark_jmhType val = f_addallbenchmark0_G; + if (val != null) { + return val; + } + synchronized(this.getClass()) { + try { + if (control.isFailing) throw new FailureAssistException(); + val = f_addallbenchmark0_G; + if (val != null) { + return val; + } + val = new AddAllBenchmark_jmhType(); + Field f; + f = edu.ktu.ds.lab2.AddAllBenchmark.class.getDeclaredField("listSize"); + f.setAccessible(true); + f.set(val, Integer.valueOf(control.getParam("listSize"))); + val.generateChunks(); + val.readyTrial = true; + f_addallbenchmark0_G = val; + } catch (Throwable t) { + control.isFailing = true; + throw t; + } + } + return val; + } + + +} + diff --git a/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_jmhType.java b/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_jmhType.java new file mode 100644 index 0000000..ad33ceb --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_jmhType.java @@ -0,0 +1,4 @@ +package edu.ktu.ds.lab2.jmh_generated; +public class AddAllBenchmark_jmhType extends AddAllBenchmark_jmhType_B3 { +} + diff --git a/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_jmhType_B1.java b/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_jmhType_B1.java new file mode 100644 index 0000000..72f53c4 --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_jmhType_B1.java @@ -0,0 +1,20 @@ +package edu.ktu.ds.lab2.jmh_generated; +import edu.ktu.ds.lab2.AddAllBenchmark; +public class AddAllBenchmark_jmhType_B1 extends edu.ktu.ds.lab2.AddAllBenchmark { + byte p000, p001, p002, p003, p004, p005, p006, p007, p008, p009, p010, p011, p012, p013, p014, p015; + byte p016, p017, p018, p019, p020, p021, p022, p023, p024, p025, p026, p027, p028, p029, p030, p031; + byte p032, p033, p034, p035, p036, p037, p038, p039, p040, p041, p042, p043, p044, p045, p046, p047; + byte p048, p049, p050, p051, p052, p053, p054, p055, p056, p057, p058, p059, p060, p061, p062, p063; + byte p064, p065, p066, p067, p068, p069, p070, p071, p072, p073, p074, p075, p076, p077, p078, p079; + byte p080, p081, p082, p083, p084, p085, p086, p087, p088, p089, p090, p091, p092, p093, p094, p095; + byte p096, p097, p098, p099, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111; + byte p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127; + byte p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143; + byte p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159; + byte p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175; + byte p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191; + byte p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207; + byte p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223; + byte p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239; + byte p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250, p251, p252, p253, p254, p255; +} diff --git a/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_jmhType_B2.java b/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_jmhType_B2.java new file mode 100644 index 0000000..974d761 --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_jmhType_B2.java @@ -0,0 +1,22 @@ +package edu.ktu.ds.lab2.jmh_generated; +import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; +public class AddAllBenchmark_jmhType_B2 extends AddAllBenchmark_jmhType_B1 { + public volatile int setupTrialMutex; + public volatile int tearTrialMutex; + public final static AtomicIntegerFieldUpdater setupTrialMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(AddAllBenchmark_jmhType_B2.class, "setupTrialMutex"); + public final static AtomicIntegerFieldUpdater tearTrialMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(AddAllBenchmark_jmhType_B2.class, "tearTrialMutex"); + + public volatile int setupIterationMutex; + public volatile int tearIterationMutex; + public final static AtomicIntegerFieldUpdater setupIterationMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(AddAllBenchmark_jmhType_B2.class, "setupIterationMutex"); + public final static AtomicIntegerFieldUpdater tearIterationMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(AddAllBenchmark_jmhType_B2.class, "tearIterationMutex"); + + public volatile int setupInvocationMutex; + public volatile int tearInvocationMutex; + public final static AtomicIntegerFieldUpdater setupInvocationMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(AddAllBenchmark_jmhType_B2.class, "setupInvocationMutex"); + public final static AtomicIntegerFieldUpdater tearInvocationMutexUpdater = AtomicIntegerFieldUpdater.newUpdater(AddAllBenchmark_jmhType_B2.class, "tearInvocationMutex"); + + public volatile boolean readyTrial; + public volatile boolean readyIteration; + public volatile boolean readyInvocation; +} diff --git a/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_jmhType_B3.java b/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_jmhType_B3.java new file mode 100644 index 0000000..447e7d4 --- /dev/null +++ b/Lab2_AibesMedziai/target/generated-test-sources/test-annotations/edu/ktu/ds/lab2/jmh_generated/AddAllBenchmark_jmhType_B3.java @@ -0,0 +1,20 @@ +package edu.ktu.ds.lab2.jmh_generated; +public class AddAllBenchmark_jmhType_B3 extends AddAllBenchmark_jmhType_B2 { + byte p000, p001, p002, p003, p004, p005, p006, p007, p008, p009, p010, p011, p012, p013, p014, p015; + byte p016, p017, p018, p019, p020, p021, p022, p023, p024, p025, p026, p027, p028, p029, p030, p031; + byte p032, p033, p034, p035, p036, p037, p038, p039, p040, p041, p042, p043, p044, p045, p046, p047; + byte p048, p049, p050, p051, p052, p053, p054, p055, p056, p057, p058, p059, p060, p061, p062, p063; + byte p064, p065, p066, p067, p068, p069, p070, p071, p072, p073, p074, p075, p076, p077, p078, p079; + byte p080, p081, p082, p083, p084, p085, p086, p087, p088, p089, p090, p091, p092, p093, p094, p095; + byte p096, p097, p098, p099, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111; + byte p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127; + byte p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143; + byte p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159; + byte p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175; + byte p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191; + byte p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207; + byte p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223; + byte p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239; + byte p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250, p251, p252, p253, p254, p255; +} + diff --git a/Lab2_AibesMedziai/target/test-classes/META-INF/BenchmarkList b/Lab2_AibesMedziai/target/test-classes/META-INF/BenchmarkList new file mode 100644 index 0000000..8459cab --- /dev/null +++ b/Lab2_AibesMedziai/target/test-classes/META-INF/BenchmarkList @@ -0,0 +1,2 @@ +JMH S 31 edu.ktu.ds.lab2.AddAllBenchmark S 66 edu.ktu.ds.lab2.jmh_generated.AddAllBenchmark_bstSetAddAll_jmhTest S 12 bstSetAddAll S 11 AverageTime E A 1 1 1 E E T 3 1 s E E T 3 1 s E E E E E E E M 1 8 listSize 6 16 0AAMAADAwAA===== 16 4AAMAADAwAA===== 16 xAgNAADAwAAMAA== 16 zAgMAADAwAAMAA== 16 2AANAADAwAAMAA== 16 xAgMAgDAwAAMAADA U 12 MICROSECONDS E E +JMH S 31 edu.ktu.ds.lab2.AddAllBenchmark S 66 edu.ktu.ds.lab2.jmh_generated.AddAllBenchmark_avlSetAddAll_jmhTest S 12 avlSetAddAll S 11 AverageTime E A 1 1 1 E E T 3 1 s E E T 3 1 s E E E E E E E M 1 8 listSize 6 16 0AAMAADAwAA===== 16 4AAMAADAwAA===== 16 xAgNAADAwAAMAA== 16 zAgMAADAwAAMAA== 16 2AANAADAwAAMAA== 16 xAgMAgDAwAAMAADA U 12 MICROSECONDS E E diff --git a/Lab2_AibesMedziai/target/test-classes/META-INF/CompilerHints b/Lab2_AibesMedziai/target/test-classes/META-INF/CompilerHints new file mode 100644 index 0000000..0384b3b --- /dev/null +++ b/Lab2_AibesMedziai/target/test-classes/META-INF/CompilerHints @@ -0,0 +1,9 @@ +dontinline,*.*_all_jmhStub +dontinline,*.*_avgt_jmhStub +dontinline,*.*_sample_jmhStub +dontinline,*.*_ss_jmhStub +dontinline,*.*_thrpt_jmhStub +inline,edu/ktu/ds/lab2/AddAllBenchmark.avlSetAddAll +inline,edu/ktu/ds/lab2/AddAllBenchmark.bstSetAddAll +inline,edu/ktu/ds/lab2/AddAllBenchmark.createSets +inline,edu/ktu/ds/lab2/AddAllBenchmark.generateChunks