diff options
author | aosipenko <aosipenko@yandex-team.ru> | 2022-02-10 16:48:08 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:08 +0300 |
commit | 69e3c43df1c96bc2ac8946bf4dfb1f5fc438ff7f (patch) | |
tree | b222e5ac2e2e98872661c51ccceee5da0d291e13 /util/draft | |
parent | 948fd24d47d4b3b7815aaef1686aea00ef3f4288 (diff) | |
download | ydb-69e3c43df1c96bc2ac8946bf4dfb1f5fc438ff7f.tar.gz |
Restoring authorship annotation for <aosipenko@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/draft')
-rw-r--r-- | util/draft/holder_vector.h | 14 | ||||
-rw-r--r-- | util/draft/holder_vector_ut.cpp | 26 | ||||
-rw-r--r-- | util/draft/matrix.h | 116 |
3 files changed, 78 insertions, 78 deletions
diff --git a/util/draft/holder_vector.h b/util/draft/holder_vector.h index 7c80c64453..1c62055bd9 100644 --- a/util/draft/holder_vector.h +++ b/util/draft/holder_vector.h @@ -42,9 +42,9 @@ public: } void PushBack(std::unique_ptr<T> t) { - PushBack(t.release()); - } - + PushBack(t.release()); + } + void PushBack(THolder<T> t) { PushBack(t.Release()); } @@ -78,10 +78,10 @@ public: TBase::resize(newSize); } - void Swap(THolderVector& other) { - TBase::swap(other); - } - + void Swap(THolderVector& other) { + TBase::swap(other); + } + using TBase::operator[]; using TBase::operator bool; using TBase::at; diff --git a/util/draft/holder_vector_ut.cpp b/util/draft/holder_vector_ut.cpp index 265af73549..f64393860a 100644 --- a/util/draft/holder_vector_ut.cpp +++ b/util/draft/holder_vector_ut.cpp @@ -49,21 +49,21 @@ Y_UNIT_TEST_SUITE(THolderVectorTest) { UNIT_ASSERT_VALUES_EQUAL(*ints[0], 1); UNIT_ASSERT(!holder); } - + Y_UNIT_TEST(TestSwap) { - THolderVector<int> v1; - v1.PushBack(new int(1)); - - THolderVector<int> v2; - v1.Swap(v2); - UNIT_ASSERT(v1.empty() && v2.size() == 1 && *v2.front() == 1); - } - + THolderVector<int> v1; + v1.PushBack(new int(1)); + + THolderVector<int> v2; + v1.Swap(v2); + UNIT_ASSERT(v1.empty() && v2.size() == 1 && *v2.front() == 1); + } + Y_UNIT_TEST(TestUniquePtr) { THolderVector<TString> v; std::unique_ptr<TString> str(new TString("hello")); - v.PushBack(std::move(str)); - UNIT_ASSERT(v.Size() == 1); - UNIT_ASSERT(str.get() == nullptr); - } + v.PushBack(std::move(str)); + UNIT_ASSERT(v.Size() == 1); + UNIT_ASSERT(str.get() == nullptr); + } } diff --git a/util/draft/matrix.h b/util/draft/matrix.h index 6383cee03d..154d00b35e 100644 --- a/util/draft/matrix.h +++ b/util/draft/matrix.h @@ -1,15 +1,15 @@ #pragma once - + #include <util/generic/noncopyable.h> #include <util/system/yassert.h> #include <util/system/defaults.h> -#include <string.h> - +#include <string.h> + template <typename T> class TMatrix: TNonCopyable { // Constructor/Destructor -public: - TMatrix() +public: + TMatrix() : Buf(nullptr) , Arr(nullptr) , M(0) @@ -17,7 +17,7 @@ public: , BufSize(0) { } - + TMatrix(size_t m, size_t n) : Buf(new T[m * n]) , Arr(Buf) @@ -26,7 +26,7 @@ public: , BufSize(m * n) { } - + TMatrix(size_t m, size_t n, T* buf) : Buf(nullptr) , Arr(buf) @@ -35,74 +35,74 @@ public: , BufSize(m * n) { } - - ~TMatrix() { - delete[] Buf; - } - + + ~TMatrix() { + delete[] Buf; + } + // Properties/Methods -public: - void Clear() { - M = N = 0; - } - +public: + void Clear() { + M = N = 0; + } + void ReDim(size_t m, size_t n) { Y_ASSERT(m >= 1 && n >= 1); - size_t newSize = m * n; - if (newSize > BufSize) { - T* newBuf = new T[newSize]; + size_t newSize = m * n; + if (newSize > BufSize) { + T* newBuf = new T[newSize]; delete[] Buf; - Arr = Buf = newBuf; - BufSize = newSize; - } + Arr = Buf = newBuf; + BufSize = newSize; + } M = m; N = n; - } - + } + size_t Width() const { - return N; - } - + return N; + } + size_t Height() const { - return M; - } - - // Access element matrix[i][j] + return M; + } + + // Access element matrix[i][j] T* operator[](size_t i) { Y_ASSERT(i >= 0 && i < M); - return Arr + i * N; - } - - // Access element matrix[i][j] + return Arr + i * N; + } + + // Access element matrix[i][j] const T* operator[](size_t i) const { Y_ASSERT(i >= 0 && i < M); - return Arr + i * N; - } - - // Access element matrix(i, j) + return Arr + i * N; + } + + // Access element matrix(i, j) T& operator()(size_t i, size_t j) { Y_ASSERT(i >= 0 && i < M && j >= 0 && j < N); - return Arr[i * N + j]; - } - - // Access element matrix(i, j) + return Arr[i * N + j]; + } + + // Access element matrix(i, j) const T& operator()(size_t i, size_t j) const { Y_ASSERT(i >= 0 && i < M && j >= 0 && j < N); - return Arr[i * N + j]; - } - - void Zero() { + return Arr[i * N + j]; + } + + void Zero() { memset((void*)Arr, 0, M * N * sizeof(T)); - } + } - void Fill(T value) { + void Fill(T value) { for (T *p = Arr, *end = Arr + M * N; p < end; ++p) - *p = value; - } - -private: - T* Buf; - T* Arr; + *p = value; + } + +private: + T* Buf; + T* Arr; size_t M, N; - size_t BufSize; -}; + size_t BufSize; +}; |