aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/containers/2d_array
diff options
context:
space:
mode:
authorleo <leo@yandex-team.ru>2022-02-10 16:46:40 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:40 +0300
commit980edcd3304699edf9d4e4d6a656e585028e2a72 (patch)
tree139f47f3911484ae9af0eb347b1a88bd6c4bb35f /library/cpp/containers/2d_array
parentb036a557f285146e5e35d4213e29a094ab907bcf (diff)
downloadydb-980edcd3304699edf9d4e4d6a656e585028e2a72.tar.gz
Restoring authorship annotation for <leo@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/containers/2d_array')
-rw-r--r--library/cpp/containers/2d_array/2d_array.h150
1 files changed, 75 insertions, 75 deletions
diff --git a/library/cpp/containers/2d_array/2d_array.h b/library/cpp/containers/2d_array/2d_array.h
index 9e24650637..090a8aff57 100644
--- a/library/cpp/containers/2d_array/2d_array.h
+++ b/library/cpp/containers/2d_array/2d_array.h
@@ -1,110 +1,110 @@
#pragma once
#include <util/system/yassert.h>
-#include <util/generic/algorithm.h>
+#include <util/generic/algorithm.h>
-#ifdef _DEBUG
-template <class T>
-struct TBoundCheck {
- T* Data;
+#ifdef _DEBUG
+template <class T>
+struct TBoundCheck {
+ T* Data;
size_t Size;
TBoundCheck(T* d, size_t s) {
- Data = d;
- Size = s;
- }
+ Data = d;
+ Size = s;
+ }
T& operator[](size_t i) const {
Y_ASSERT(i >= 0 && i < Size);
- return Data[i];
- }
+ return Data[i];
+ }
};
-#endif
+#endif
template <class T>
-class TArray2D {
-private:
- typedef T* PT;
- T* Data;
- T** PData;
+class TArray2D {
+private:
+ typedef T* PT;
+ T* Data;
+ T** PData;
size_t XSize;
size_t YSize;
-private:
+private:
void Copy(const TArray2D& a) {
- XSize = a.XSize;
- YSize = a.YSize;
- Create();
+ XSize = a.XSize;
+ YSize = a.YSize;
+ Create();
for (size_t i = 0; i < XSize * YSize; i++)
- Data[i] = a.Data[i];
- }
- void Destroy() {
- delete[] Data;
- delete[] PData;
- }
- void Create() {
- Data = new T[XSize * YSize];
- PData = new PT[YSize];
+ Data[i] = a.Data[i];
+ }
+ void Destroy() {
+ delete[] Data;
+ delete[] PData;
+ }
+ void Create() {
+ Data = new T[XSize * YSize];
+ PData = new PT[YSize];
for (size_t i = 0; i < YSize; i++)
- PData[i] = Data + i * XSize;
- }
+ PData[i] = Data + i * XSize;
+ }
public:
TArray2D(size_t xsize = 1, size_t ysize = 1) {
- XSize = xsize;
- YSize = ysize;
- Create();
- }
+ XSize = xsize;
+ YSize = ysize;
+ Create();
+ }
TArray2D(const TArray2D& a) {
- Copy(a);
- }
+ Copy(a);
+ }
TArray2D& operator=(const TArray2D& a) {
- Destroy();
- Copy(a);
- return *this;
- }
- ~TArray2D() {
- Destroy();
- }
+ Destroy();
+ Copy(a);
+ return *this;
+ }
+ ~TArray2D() {
+ Destroy();
+ }
void SetSizes(size_t xsize, size_t ysize) {
- if (XSize == xsize && YSize == ysize)
- return;
- Destroy();
- XSize = xsize;
- YSize = ysize;
- Create();
- }
- void Clear() {
+ if (XSize == xsize && YSize == ysize)
+ return;
+ Destroy();
+ XSize = xsize;
+ YSize = ysize;
+ Create();
+ }
+ void Clear() {
SetSizes(1, 1);
- }
+ }
#ifdef _DEBUG
TBoundCheck<T> operator[](size_t i) const {
Y_ASSERT(i < YSize);
- return TBoundCheck<T>(PData[i], XSize);
- }
+ return TBoundCheck<T>(PData[i], XSize);
+ }
#else
T* operator[](size_t i) const {
Y_ASSERT(i < YSize);
- return PData[i];
- }
+ return PData[i];
+ }
#endif
size_t GetXSize() const {
- return XSize;
- }
+ return XSize;
+ }
size_t GetYSize() const {
- return YSize;
- }
- void FillZero() {
- memset(Data, 0, sizeof(T) * XSize * YSize);
- }
- void FillEvery(const T& a) {
+ return YSize;
+ }
+ void FillZero() {
+ memset(Data, 0, sizeof(T) * XSize * YSize);
+ }
+ void FillEvery(const T& a) {
for (size_t i = 0; i < XSize * YSize; i++)
- Data[i] = a;
- }
- void Swap(TArray2D& a) {
- std::swap(Data, a.Data);
- std::swap(PData, a.PData);
- std::swap(XSize, a.XSize);
- std::swap(YSize, a.YSize);
- }
+ Data[i] = a;
+ }
+ void Swap(TArray2D& a) {
+ std::swap(Data, a.Data);
+ std::swap(PData, a.PData);
+ std::swap(XSize, a.XSize);
+ std::swap(YSize, a.YSize);
+ }
};
template <class T>
@@ -121,5 +121,5 @@ inline bool operator==(const TArray2D<T>& a, const TArray2D<T>& b) {
template <class T>
inline bool operator!=(const TArray2D<T>& a, const TArray2D<T>& b) {
- return !(a == b);
-}
+ return !(a == b);
+}