Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tasks/timofeev_n_radix_batcher_sort/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Language: Cpp
Standard: c++20
BasedOnStyle: Google
ColumnLimit: 120
UseTab: Never
AllowShortFunctionsOnASingleLine: Empty
IndentPPDirectives: AfterHash
SortIncludes: true
FixNamespaceComments: true
InsertBraces: true
QualifierAlignment: Left
PointerAlignment: Right
ReferenceAlignment: Right
SortUsingDeclarations: LexicographicNumeric
InsertNewlineAtEOF: true
LambdaBodyIndentation: OuterScope
MaxEmptyLinesToKeep: 1
EnumTrailingComma: Insert
KeepEmptyLines:
AtStartOfFile: false
AtStartOfBlock: false
AtEndOfFile: false
LineEnding: LF
110 changes: 110 additions & 0 deletions tasks/timofeev_n_radix_batcher_sort/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
Checks: >
bugprone-*,
cert-dcl50-cpp,
cert-dcl58-cpp,
cert-env33-c,
cert-err34-c,
cert-err52-cpp,
cert-err60-cpp,
cert-flp30-c,
cert-mem57-cpp,
cert-msc50-cpp,
cert-msc51-cpp,
cert-oop57-cpp,
cert-oop58-cpp,
clang-*,
concurrency-*,
cppcoreguidelines-*,
google-*,
llvm-include-order,
llvm-namespace-comment,
misc-*,
modernize-*,
mpi-*,
openmp-*,
performance-*,
portability-*,
readability-*,
-bugprone-casting-through-void,
-bugprone-easily-swappable-parameters,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-special-member-functions,
-misc-const-correctness,
-misc-non-private-member-variables-in-classes,
-modernize-avoid-c-arrays,
-modernize-use-trailing-return-type,
-portability-avoid-pragma-once,
-portability-template-virtual-member-function,
-readability-magic-numbers

HeaderFilterRegex: '.*/(modules|tasks)/.*'

CheckOptions:
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.ClassMemberCase
value: lower_case
- key: readability-identifier-naming.ConstexprVariableCase
value: CamelCase
- key: readability-identifier-naming.ConstexprVariablePrefix
value: k
- key: readability-identifier-naming.EnumCase
value: CamelCase
- key: readability-identifier-naming.EnumConstantCase
value: CamelCase
- key: readability-identifier-naming.EnumConstantPrefix
value: k
- key: readability-identifier-naming.FunctionCase
value: CamelCase
- key: readability-identifier-naming.GlobalConstantCase
value: CamelCase
- key: readability-identifier-naming.GlobalConstantPrefix
value: k
- key: readability-identifier-naming.StaticConstantCase
value: CamelCase
- key: readability-identifier-naming.StaticConstantPrefix
value: k
- key: readability-identifier-naming.StaticVariableCase
value: lower_case
- key: readability-identifier-naming.MacroDefinitionCase
value: UPPER_CASE
- key: readability-identifier-naming.MacroDefinitionIgnoredRegexp
value: '^[A-Z]+(_[A-Z]+)*_$'
- key: readability-identifier-naming.MemberCase
value: lower_case
- key: readability-identifier-naming.PrivateMemberSuffix
value: _
- key: readability-identifier-naming.PublicMemberSuffix
value: ''
- key: readability-identifier-naming.NamespaceCase
value: lower_case
- key: readability-identifier-naming.ParameterCase
value: lower_case
- key: readability-identifier-naming.TypeAliasCase
value: CamelCase
- key: readability-identifier-naming.TypedefCase
value: CamelCase
- key: readability-identifier-naming.VariableCase
value: lower_case
- key: readability-identifier-naming.IgnoreMainLikeFunctions
value: 1
# Functions with scores beyond 15 are typically flagged as potentially problematic (empirically)
- key: readability-function-cognitive-complexity.Threshold
value: 15 # default: 25
- key: readability-identifier-length.MinimumVariableNameLength
value: 1
- key: readability-identifier-length.MinimumParameterNameLength
value: 1
- key: misc-include-cleaner.IgnoreHeaders
value: '(__chrono/.*|stdlib\.h|3rdparty/.*)'
- key: cppcoreguidelines-avoid-non-const-global-variables.AllowInternalLinkage
value: 1
- key: modernize-type-traits.IgnoreMacros
value: 1
- key: cppcoreguidelines-avoid-goto.IgnoreMacros
value: 1
17 changes: 17 additions & 0 deletions tasks/timofeev_n_radix_batcher_sort/common/include/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <string>
#include <tuple>
#include <vector>

#include "task/include/task.hpp"

namespace timofeev_n_radix_batcher_sort_threads {

using InType = std::vector<int>;
using OutType = std::vector<int>;
// вход, выход, проверка, имя
using TestType = std::tuple<std::vector<int>, std::vector<int>, int, std::string>;
using BaseTask = ppc::task::Task<InType, OutType>;

} // namespace timofeev_n_radix_batcher_sort_threads
9 changes: 9 additions & 0 deletions tasks/timofeev_n_radix_batcher_sort/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"student": {
"first_name": "Никита",
"group_number": "3823Б1ПР2",
"last_name": "Тимофеев",
"middle_name": "Сергеевич",
"task_number": "1"
}
}
30 changes: 30 additions & 0 deletions tasks/timofeev_n_radix_batcher_sort/seq/include/ops_seq.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include <vector>

#include "task/include/task.hpp"
#include "timofeev_n_radix_batcher_sort/common/include/common.hpp"

namespace timofeev_n_radix_batcher_sort_threads {

class TimofeevNRadixBatcherSEQ : public BaseTask {
public:
static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() {
return ppc::task::TypeOfTask::kSEQ;
}
explicit TimofeevNRadixBatcherSEQ(const InType &in);

private:
bool ValidationImpl() override;
bool PreProcessingImpl() override;
bool RunImpl() override;
bool PostProcessingImpl() override;

static int Loggo(int inputa);
static void CompExch(int &a, int &b, int digit);
static void BubbleSort(std::vector<int> &arr, int digit, int left, int right);
static void ComparR(int &a, int &b);
static void OddEvenMerge(std::vector<int> &arr, int lft, int n);
};

} // namespace timofeev_n_radix_batcher_sort_threads
123 changes: 123 additions & 0 deletions tasks/timofeev_n_radix_batcher_sort/seq/src/ops_seq.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#include "timofeev_n_radix_batcher_sort/seq/include/ops_seq.hpp"

#include <algorithm>
#include <climits>
#include <utility>
#include <vector>

#include "timofeev_n_radix_batcher_sort/common/include/common.hpp"
// #include "util/include/util.hpp"

namespace timofeev_n_radix_batcher_sort_threads {

TimofeevNRadixBatcherSEQ::TimofeevNRadixBatcherSEQ(const InType &in) {
SetTypeOfTask(GetStaticTypeOfTask());
GetInput() = in;
GetOutput() = in;
}

void TimofeevNRadixBatcherSEQ::CompExch(int &a, int &b, int digit) {
int b_r = b % (digit * 10) / digit;
int a_r = a % (digit * 10) / digit;
if (b_r < a_r) {
std::swap(a, b);
}
}

void TimofeevNRadixBatcherSEQ::BubbleSort(std::vector<int> &arr, int digit, int left, int right) {
for (int i = left; i <= right; i++) {
for (int j = 0; j + 1 < right - left; j++) {
CompExch(arr[left + j], arr[left + j + 1], digit);
}
}
}

void TimofeevNRadixBatcherSEQ::ComparR(int &a, int &b) {
if (a > b) {
std::swap(a, b);
}
}

void TimofeevNRadixBatcherSEQ::OddEvenMerge(std::vector<int> &arr, int lft, int n) {
if (n <= 1) {
return;
}

int otstup = n / 2;
for (int i = 0; i < otstup; i += 1) {
if (arr[lft + i] > arr[lft + otstup + i]) {
std::swap(arr[lft + i], arr[lft + otstup + i]);
}
}

for (otstup = n / 4; otstup > 0; otstup /= 2) {
int h = otstup * 2;
for (int start = otstup; start + otstup < n; start += h) {
for (int i = 0; i < otstup; i += 1) {
ComparR(arr[lft + start + i], arr[lft + start + i + otstup]);
}
}
}
}

int TimofeevNRadixBatcherSEQ::Loggo(int inputa) {
int count = 0;
while (inputa > 1) {
inputa /= 2;
count++;
}
return count;
}

bool TimofeevNRadixBatcherSEQ::ValidationImpl() {
return GetInput().size() >= 2;
}

bool TimofeevNRadixBatcherSEQ::PreProcessingImpl() {
return true;
}

bool TimofeevNRadixBatcherSEQ::RunImpl() {
std::vector<int> in = GetInput();
int n = static_cast<int>(in.size());
int m = n;
while (n % 2 == 0) {
n /= 2;
}
if (n > 1) {
n = static_cast<int>(in.size());
int p = 1;
while (p < n) {
p *= 2;
}
n = p;
} else {
n = m;
}
int max_x = *(std::ranges::max_element(in.begin(), in.end()));
if (n != m) {
in.resize(n, max_x);
}
// std::cout << "\n\n" << n << " " << in.size() << " " << "1\n\n";
for (int i = 0; std::cmp_less(i, static_cast<int>(in.size())); i += static_cast<int>(in.size() / 2)) {
for (int k = 1; k <= max_x; k *= 10) {
BubbleSort(in, k, i, i + static_cast<int>(in.size() / 2));
}
}
OddEvenMerge(in, 0, static_cast<int>(in.size()));
// std::cout << "\n\n" << n << " " << in.size() << " " << "2\n\n";
if (m != n) {
in.resize(m);
}
for (int i = 0; std::cmp_less(i, static_cast<int>(in.size())); i++) {
GetInput()[i] = in[i];
}
GetOutput() = GetInput();
return true;
}

bool TimofeevNRadixBatcherSEQ::PostProcessingImpl() {
return true;
}

} // namespace timofeev_n_radix_batcher_sort_threads
10 changes: 10 additions & 0 deletions tasks/timofeev_n_radix_batcher_sort/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"tasks": {
"all": "enabled",
"omp": "enabled",
"seq": "enabled",
"stl": "enabled",
"tbb": "enabled"
},
"tasks_type": "threads"
}
Loading
Loading