Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b39cbc2
Allocator: added
morell0809 Jan 29, 2021
e154c78
Allocators -> seminar15
morell0809 Jan 31, 2021
d449e3f
homework: Allocator
morell0809 Jan 31, 2021
1f1f2d5
CI: added
morell0809 Jan 31, 2021
64c55c2
Allocator: C++14
morell0809 Feb 9, 2021
353d44b
seminar16:
morell0809 Feb 12, 2021
693af30
homework: Variant
morell0809 Feb 13, 2021
192d540
homework: Optional
morell0809 Feb 13, 2021
c3f2300
homework: SharedPointer
morell0809 Feb 18, 2021
2643dcc
grim
morell0809 Feb 19, 2021
7081e48
homework: Optional
morell0809 Feb 21, 2021
bee15c5
homework: Variant
morell0809 Feb 21, 2021
b7902f0
homework: TypeTraits
morell0809 Feb 23, 2021
572b10f
seminars: 18 added
morell0809 Feb 26, 2021
7a45e50
lectures: 1,3-course, lecture 3 fix
morell0809 Mar 4, 2021
0eb954a
seminars: 19 added
morell0809 Mar 5, 2021
63fb2fd
homework: variant get fixes
morell0809 Mar 8, 2021
08c1804
seminars: 20 added
Mar 12, 2021
ea94966
seminars: 21 added
Mar 19, 2021
a7e8729
seminars: 22 added
Mar 26, 2021
591d508
submodule: clangformat-cmake
Mar 27, 2021
e6bb4f6
ci.yml: clang-format, clang-tidy
Mar 27, 2021
6979cd8
homework: Allocator
Mar 27, 2021
c4a539a
homework: Optional
Mar 27, 2021
b5f8f92
homework: SharedPtr
Mar 28, 2021
d89e4dc
homework: Variant
Mar 28, 2021
7540ea8
homework: TypeTraits
Mar 28, 2021
2374682
seminars: 23 added
Apr 9, 2021
33108c0
ci.yml: fix
Apr 11, 2021
6d94f6d
seminars: 3-8 added
Apr 12, 2021
30f57e0
clang-format submodule: in-place editing removed
May 6, 2021
1cb7fe3
clang-format submodule: dry-run, Werror
May 6, 2021
66412dc
ci.yml: clang-tidy/format 10
May 15, 2021
acb4c4d
clang-tidy: Werror removed
May 15, 2021
ed47cec
Allocator solution
Meranolean Jun 11, 2021
82e3775
fix clang-format errors
Meranolean Jun 11, 2021
42e7f5e
fix clang-format errors 2.0
Meranolean Jun 11, 2021
3cdc381
fix clang-format errors 2.1
Meranolean Jun 11, 2021
6386660
fix clang-format errors 2.2
Meranolean Jun 11, 2021
1205c6c
fix commetns
Meranolean Jun 12, 2021
297b8b8
add {} instead ()
Meranolean Jun 12, 2021
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
11 changes: 11 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
BasedOnStyle: Google
IndentWidth: 4
AccessModifierOffset: -4
ColumnLimit: 100
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
DerivePointerAlignment: true
KeepEmptyLinesAtTheStartOfBlocks: true
SortIncludes: true

48 changes: 48 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---

Checks: '-*,cppcoreguidelines-avoid-goto,cppcoreguidelines-pro-type-const-cast, google-runtime-int, modernize-use-nullptr, readability-braces-around-statements, readability-container-size-empty, readability-redundant-control-flow, readability-identifier-naming, readability-simplify-boolean-expr, google-build-using-namespace, readability-implicit-bool-conversion, google-explicit-constructor'

CheckOptions:
- key: readability-identifier-naming.NamespaceCase
value: lower_case
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.StructCase
value: CamelCase
- key: readability-identifier-naming.TypedefCase
value: lower_case
- key: readability-identifier-naming.TypeAliasCase
value: lower_case
- key: readability-identifier-naming.FunctionCase
value: CamelCase
- key: readability-identifier-naming.ParameterCase
value: lower_case
- key: readability-identifier-naming.VariableCase
value: lower_case
- key: readability-identifier-naming.PrivateMemberCase
value: lower_case
- key: readability-identifier-naming.PrivateMemberSuffix
value: '_'
- 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.ConstexprVariableCase
value: CamelCase
- key: readability-identifier-naming.ConstexprVariablePrefix
value: k
- key: readability-identifier-naming.TypeTemplateParameterCase
value: CamelCase
- key: readability-identifier-naming.ClassMemberCase
value: lower_case
- key: readability-identifier-naming.ClassMemberSuffix
value: '_'
- key: readability-simplify-boolean-expr.ChainedConditionalReturn
value: '1'
- key: readability-simplify-boolean-expr.ChainedConditionalAssignment
value: '1'

30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: ci

on: [pull_request]

jobs:
ci:
runs-on: ubuntu-20.04
steps:
- name: checkout
uses: actions/checkout@v2

- name: tests
env:
CLANG_FORMAT_SUBMODULE: /home/runner/work/HSE-Course/HSE-Course/clangformat-cmake
TITLE: ${{github.event.pull_request.title}}
working-directory: ./module-1/homework/
run:
sudo apt-get install clang-tidy-10 &&
sudo apt-get install clang-format-10 &&
sudo rm -rf /usr/bin/clang-tidy &&
sudo rm -rf /usr/bin/clang-format &&
sudo ln -s /usr/bin/clang-tidy-10 /usr/bin/clang-tidy &&
sudo ln -s /usr/bin/clang-format-10 /usr/bin/clang-format &&
clang-tidy --version &&
clang-format --version &&
git submodule update --init --recursive &&
prname=${TITLE} &&
cmake -B ${prname}/build -S ${prname} &&
cmake --build ${prname}/build --target runner clangformat &&
./${prname}/build/runner
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "clangformat-cmake"]
path = clangformat-cmake
url = https://github.com/morell5/clangformat-cmake.git
[submodule "module-1/homework/Allocator/clangformat-cmake"]
path = module-1/homework/Allocator/clangformat-cmake
url = https://github.com/zemasoft/clangformat-cmake
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

## Структура репозитория

`module-1` - задания и семинары за 1-ое учебное полугодие</br>
`module-2` - задания и семинары за 2-ое учебное полугодие</br>
`module-1` - задания и семинары</br>

## Сдача заданий

Expand All @@ -23,4 +22,4 @@

## Связь

[Slack Workspace](https://join.slack.com/t/1c-hseworkspace/shared_invite/zt-h4q9ff3l-oKj26qGMHhmoLH5G7hDpYA)
[Slack Workspace](https://join.slack.com/t/1c-hseworkspace/shared_invite/zt-n67k87vo-d~ypzAzri~Tu4e15zQLSBw)
1 change: 1 addition & 0 deletions clangformat-cmake
Submodule clangformat-cmake added at af9301
56 changes: 56 additions & 0 deletions module-1/homework/Allocator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
cmake_minimum_required(VERSION 3.16)

include(GoogleTest)

project("runner")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

################ gtest ################
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)

execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .

RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )

if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)

if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
endif()

################ Sanitizers ################
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=gold -fsanitize=undefined,address -fno-sanitize-recover=all -O2 -Wall -Werror -Wsign-compare")

################ clang-tidy ################
set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-header-filter=.")

add_executable(runner tests.cpp)

################ clang-format ################
list(APPEND CMAKE_MODULE_PATH $ENV{CLANG_FORMAT_SUBMODULE}/cmake)
include(ClangFormat)
target_clangformat_setup(runner)

add_subdirectory(src/allocator)
add_subdirectory(src/list)

target_link_libraries(runner LINK_PUBLIC list allocator gtest_main)

add_test(NAME runner_test COMMAND runner)
15 changes: 15 additions & 0 deletions module-1/homework/Allocator/CMakeLists.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 2.8.2)

project(googletest-download NONE)

include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
1 change: 1 addition & 0 deletions module-1/homework/Allocator/clangformat-cmake
Submodule clangformat-cmake added at ced236
11 changes: 11 additions & 0 deletions module-1/homework/Allocator/src/allocator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.16)

project(runner)

add_library(allocator allocator.h)
set_target_properties(allocator PROPERTIES LINKER_LANGUAGE CXX)

################ clang-format ################
list(APPEND CMAKE_MODULE_PATH $ENV{CLANG_FORMAT_SUBMODULE}/cmake)
include(ClangFormat)
target_clangformat_setup(allocator)
120 changes: 120 additions & 0 deletions module-1/homework/Allocator/src/allocator/allocator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#include <memory>
#include <type_traits>

template <typename T>
class CustomAllocator {
public:
template <typename U>
struct rebind { // NOLINT
using other = CustomAllocator<U>;
};
using value_type = T;
using pointer = T*;
using const_pointer = const T*;
using reference = T&;
using const_reference = const T&;
using size_type = size_t;
using difference_type = ptrdiff_t;

// Influence on container operations
using propagate_on_container_move_assignment = std::false_type;
using propagate_on_container_copy_assignment = std::false_type;
using propagate_on_container_swap = std::true_type;
using is_always_equal = std::false_type;

CustomAllocator();
CustomAllocator(const CustomAllocator& other) noexcept;
~CustomAllocator();

template <typename U>
explicit CustomAllocator(const CustomAllocator<U>& other) noexcept;

T* allocate(size_t n) { // NOLINT
if (*arena_offset_ + n > ARENA_BASIC_SIZE) {
throw std::runtime_error("Allocator's arena is full");
}

*arena_offset_ += n;

return static_cast<pointer>(arena_) + (*arena_offset_ - n);
}

void deallocate(T*, size_t) { // NOLINT
}

template <typename... Args>
void construct(pointer p, Args&&... args) { // NOLINT
::new (p) value_type(std::forward<Args>(args)...);
};

void destroy(pointer p) { // NOLINT
p->~T();
};

void* get_arena() const {
return arena_;
}

size_t* get_arena_offset() const {
return arena_offset_;
}

size_t* get_allocators_count() const {
return allocators_count_;
}

template <typename K, typename U>
friend bool operator==(const CustomAllocator<K>& lhs, const CustomAllocator<U>& rhs) noexcept;
template <typename K, typename U>
friend bool operator!=(const CustomAllocator<K>& lhs, const CustomAllocator<U>& rhs) noexcept;

private:
static const size_t ARENA_BASIC_SIZE = 65536;
void* arena_ = nullptr;
size_t* arena_offset_ = nullptr;
size_t* allocators_count_ = nullptr;
};

template <typename T>
CustomAllocator<T>::CustomAllocator() {
arena_ = ::operator new(ARENA_BASIC_SIZE * sizeof(T));
arena_offset_ = new size_type(0);
allocators_count_ = new size_type(1);
}

template <typename T>
CustomAllocator<T>::CustomAllocator(const CustomAllocator& other) noexcept
: arena_{other.arena_},
arena_offset_{other.arena_offset_},
allocators_count_{other.allocators_count_} {
++(*allocators_count_);
}

template <typename T>
CustomAllocator<T>::~CustomAllocator() {
--(*allocators_count_);
if (*allocators_count_ == 0) {
::operator delete(arena_);
delete arena_offset_;
delete allocators_count_;
}
}

template <typename T>
template <typename U>
CustomAllocator<T>::CustomAllocator(const CustomAllocator<U>& other) noexcept
: arena_{other.get_arena()},
arena_offset_{other.get_arena_offset()},
allocators_count_{other.get_allocators_count()} {
++(*allocators_count_);
}

template <typename T, typename U>
bool operator==(const CustomAllocator<T>& lhs, const CustomAllocator<U>& rhs) noexcept {
return lhs.arena_ == rhs.arena_;
}

template <typename T, typename U>
bool operator!=(const CustomAllocator<T>& lhs, const CustomAllocator<U>& rhs) noexcept {
return lhs.arena_ != rhs.arena_;
}
11 changes: 11 additions & 0 deletions module-1/homework/Allocator/src/list/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.16)

project(runner)

add_library(list list.h)
set_target_properties(list PROPERTIES LINKER_LANGUAGE CXX)

################ clang-format ################
list(APPEND CMAKE_MODULE_PATH $ENV{CLANG_FORMAT_SUBMODULE}/cmake)
include(ClangFormat)
target_clangformat_setup(list)
Loading