aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorekrokhalev <ekrokhalev@yandex-team.ru>2022-02-10 16:50:10 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:10 +0300
commit8d3a5b9c70bfb823a30242286328d6017b82b9ce (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /util
parent1c01ed5294724fda060c1f0bd674b315fe249598 (diff)
downloadydb-8d3a5b9c70bfb823a30242286328d6017b82b9ce.tar.gz
Restoring authorship annotation for <ekrokhalev@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util')
-rw-r--r--util/charset/unidata.h36
-rw-r--r--util/generic/xrange.h94
-rw-r--r--util/generic/xrange_ut.cpp46
-rw-r--r--util/stream/pipe.cpp56
-rw-r--r--util/stream/pipe.h18
5 files changed, 125 insertions, 125 deletions
diff --git a/util/charset/unidata.h b/util/charset/unidata.h
index f4d5a82f0d..400d314186 100644
--- a/util/charset/unidata.h
+++ b/util/charset/unidata.h
@@ -400,22 +400,22 @@ inline bool IsPrint(wchar32 ch) {
return IsAlnum(ch) || IsPunct(ch) || IsSymbol(ch) || IsBlank(ch);
}
-inline bool IsRomanDigit(wchar32 ch) {
- if (NUnicode::CharHasType(ch, SHIFT(Nl_LETTER)) && 0x2160 <= ch && ch <= 0x2188)
- return true;
- if (ch < 127) {
- switch (static_cast<char>(::ToLower(ch))) {
- case 'i':
- case 'v':
- case 'x':
- case 'l':
- case 'c':
- case 'd':
- case 'm':
- return true;
- }
- }
- return false;
-}
-
+inline bool IsRomanDigit(wchar32 ch) {
+ if (NUnicode::CharHasType(ch, SHIFT(Nl_LETTER)) && 0x2160 <= ch && ch <= 0x2188)
+ return true;
+ if (ch < 127) {
+ switch (static_cast<char>(::ToLower(ch))) {
+ case 'i':
+ case 'v':
+ case 'x':
+ case 'l':
+ case 'c':
+ case 'd':
+ case 'm':
+ return true;
+ }
+ }
+ return false;
+}
+
#undef SHIFT
diff --git a/util/generic/xrange.h b/util/generic/xrange.h
index 95864d65a3..5fc8c82912 100644
--- a/util/generic/xrange.h
+++ b/util/generic/xrange.h
@@ -20,7 +20,7 @@
namespace NPrivate {
template <typename T>
- class TSimpleXRange {
+ class TSimpleXRange {
using TDiff = decltype(T() - T());
public:
@@ -125,21 +125,21 @@ namespace NPrivate {
T Finish;
};
- template <typename T>
- class TSteppedXRange {
- using TDiff = decltype(T() - T());
+ template <typename T>
+ class TSteppedXRange {
+ using TDiff = decltype(T() - T());
- public:
+ public:
constexpr TSteppedXRange(T start, T finish, TDiff step) noexcept
: Start_(start)
, Step_(step)
, Finish_(CalcRealFinish(Start_, finish, Step_))
{
static_assert(std::is_integral<T>::value || std::is_pointer<T>::value, "T should be integral type or pointer");
- }
-
+ }
+
class TIterator {
- public:
+ public:
using value_type = T;
using difference_type = TDiff;
using pointer = const T*;
@@ -150,16 +150,16 @@ namespace NPrivate {
: Value_(value)
, Parent_(&parent)
{
- }
-
+ }
+
constexpr T operator*() const noexcept {
- return Value_;
- }
-
+ return Value_;
+ }
+
constexpr bool operator!=(const TIterator& other) const noexcept {
- return Value_ != other.Value_;
- }
-
+ return Value_ != other.Value_;
+ }
+
constexpr bool operator==(const TIterator& other) const noexcept {
return Value_ == other.Value_;
}
@@ -167,8 +167,8 @@ namespace NPrivate {
TIterator& operator++() noexcept {
Value_ += Parent_->Step_;
return *this;
- }
-
+ }
+
TIterator& operator--() noexcept {
Value_ -= Parent_->Step_;
return *this;
@@ -200,34 +200,34 @@ namespace NPrivate {
return *this;
}
- private:
- T Value_;
+ private:
+ T Value_;
const TSteppedXRange* Parent_;
- };
-
+ };
+
using value_type = T;
using iterator = TIterator;
using const_iterator = TIterator;
constexpr TIterator begin() const noexcept {
- return TIterator(Start_, *this);
- }
-
+ return TIterator(Start_, *this);
+ }
+
constexpr TIterator end() const noexcept {
- return TIterator(Finish_, *this);
- }
-
- static T CalcRealFinish(T start, T expFinish, TDiff step) {
+ return TIterator(Finish_, *this);
+ }
+
+ static T CalcRealFinish(T start, T expFinish, TDiff step) {
Y_ASSERT(step != 0);
- if (step > 0) {
- if (expFinish > start) {
- return start + step * ((expFinish - 1 - start) / step + 1);
- }
- return start;
- }
- return start - TSteppedXRange<TDiff>::CalcRealFinish(0, start - expFinish, -step);
- }
-
+ if (step > 0) {
+ if (expFinish > start) {
+ return start + step * ((expFinish - 1 - start) / step + 1);
+ }
+ return start;
+ }
+ return start - TSteppedXRange<TDiff>::CalcRealFinish(0, start - expFinish, -step);
+ }
+
constexpr T size() const noexcept {
return (Finish_ - Start_) / Step_;
}
@@ -237,12 +237,12 @@ namespace NPrivate {
return Container(begin(), end());
}
- private:
- const T Start_;
- const TDiff Step_;
- const T Finish_;
- };
-
+ private:
+ const T Start_;
+ const TDiff Step_;
+ const T Finish_;
+ };
+
}
/**
@@ -250,11 +250,11 @@ namespace NPrivate {
*
* @param step must be non-zero
*/
-template <typename T>
+template <typename T>
constexpr ::NPrivate::TSteppedXRange<T> xrange(T start, T finish, decltype(T() - T()) step) noexcept {
return {start, finish, step};
-}
-
+}
+
/// generate sequence [start; finish)
template <typename T>
constexpr ::NPrivate::TSimpleXRange<T> xrange(T start, T finish) noexcept {
diff --git a/util/generic/xrange_ut.cpp b/util/generic/xrange_ut.cpp
index 6f870e9d40..8106da03e7 100644
--- a/util/generic/xrange_ut.cpp
+++ b/util/generic/xrange_ut.cpp
@@ -31,26 +31,26 @@ Y_UNIT_TEST_SUITE(XRange) {
}
void TestSteppedXRangeImpl(int begin, int end, int step, const TVector<int>& expected) {
- size_t expInd = 0;
+ size_t expInd = 0;
for (auto i : xrange(begin, end, step)) {
- UNIT_ASSERT(expInd < expected.size());
- UNIT_ASSERT_VALUES_EQUAL(i, expected[expInd]);
- ++expInd;
- }
- UNIT_ASSERT_VALUES_EQUAL(expInd, expected.size());
- }
-
+ UNIT_ASSERT(expInd < expected.size());
+ UNIT_ASSERT_VALUES_EQUAL(i, expected[expInd]);
+ ++expInd;
+ }
+ UNIT_ASSERT_VALUES_EQUAL(expInd, expected.size());
+ }
+
Y_UNIT_TEST(IncrementWorks) {
TestXRangeImpl(0, 10);
TestXRangeImpl(10, 20);
}
-
+
Y_UNIT_TEST(DecrementWorks) {
TestSteppedXRangeImpl(10, 0, -1, {10, 9, 8, 7, 6, 5, 4, 3, 2, 1});
TestSteppedXRangeImpl(10, -1, -1, {10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0});
TestSteppedXRangeImpl(20, 9, -1, {20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10});
- }
-
+ }
+
Y_UNIT_TEST(StepWorks) {
TestSteppedXRangeImpl(0, 0, 1, {});
TestSteppedXRangeImpl(0, 9, 3, {0, 3, 6});
@@ -62,22 +62,22 @@ Y_UNIT_TEST_SUITE(XRange) {
TestSteppedXRangeImpl(15, 0, -4, {15, 11, 7, 3});
TestSteppedXRangeImpl(15, -1, -4, {15, 11, 7, 3});
TestSteppedXRangeImpl(15, -2, -4, {15, 11, 7, 3, -1});
- }
-
+ }
+
Y_UNIT_TEST(PointersWorks) {
TVector<size_t> data = {3, 1, 4, 1, 5, 9, 2, 6};
- const size_t digSumExpected = Accumulate(data.begin(), data.end(), static_cast<size_t>(0));
- size_t digSumByIt = 0;
+ const size_t digSumExpected = Accumulate(data.begin(), data.end(), static_cast<size_t>(0));
+ size_t digSumByIt = 0;
for (auto ptr : xrange(data.begin(), data.end())) {
- digSumByIt += *ptr;
- }
- UNIT_ASSERT_VALUES_EQUAL(digSumByIt, digSumExpected);
- size_t digSumByPtr = 0;
+ digSumByIt += *ptr;
+ }
+ UNIT_ASSERT_VALUES_EQUAL(digSumByIt, digSumExpected);
+ size_t digSumByPtr = 0;
for (auto ptr : xrange(&data[0], &data[0] + data.size())) {
- digSumByPtr += *ptr;
- }
- UNIT_ASSERT_VALUES_EQUAL(digSumByPtr, digSumExpected);
- }
+ digSumByPtr += *ptr;
+ }
+ UNIT_ASSERT_VALUES_EQUAL(digSumByPtr, digSumExpected);
+ }
Y_UNIT_TEST(SizeMethodCheck) {
UNIT_ASSERT_VALUES_EQUAL(xrange(5).size(), 5);
diff --git a/util/stream/pipe.cpp b/util/stream/pipe.cpp
index 556c5766d7..51be1934a7 100644
--- a/util/stream/pipe.cpp
+++ b/util/stream/pipe.cpp
@@ -82,40 +82,40 @@ void TPipeOutput::Close() {
}
}
-TPipedBase::TPipedBase(PIPEHANDLE fd)
- : Handle_(fd)
-{
-}
-
+TPipedBase::TPipedBase(PIPEHANDLE fd)
+ : Handle_(fd)
+{
+}
+
TPipedBase::~TPipedBase() {
if (Handle_.IsOpen()) {
- Handle_.Close();
+ Handle_.Close();
}
-}
-
+}
+
TPipedInput::TPipedInput(PIPEHANDLE fd)
- : TPipedBase(fd)
-{
-}
-
+ : TPipedBase(fd)
+{
+}
+
TPipedInput::~TPipedInput() = default;
-
-size_t TPipedInput::DoRead(void* buf, size_t len) {
+
+size_t TPipedInput::DoRead(void* buf, size_t len) {
if (!Handle_.IsOpen()) {
- return 0;
+ return 0;
}
return Handle_.Read(buf, len);
-}
-
-TPipedOutput::TPipedOutput(PIPEHANDLE fd)
- : TPipedBase(fd)
-{
-}
-
+}
+
+TPipedOutput::TPipedOutput(PIPEHANDLE fd)
+ : TPipedBase(fd)
+{
+}
+
TPipedOutput::~TPipedOutput() = default;
-
-void TPipedOutput::DoWrite(const void* buf, size_t len) {
- if (!Handle_.IsOpen() || static_cast<ssize_t>(len) != Handle_.Write(buf, len)) {
- ythrow TSystemError() << "pipe writing failed";
- }
-}
+
+void TPipedOutput::DoWrite(const void* buf, size_t len) {
+ if (!Handle_.IsOpen() || static_cast<ssize_t>(len) != Handle_.Write(buf, len)) {
+ ythrow TSystemError() << "pipe writing failed";
+ }
+}
diff --git a/util/stream/pipe.h b/util/stream/pipe.h
index 7ef5766e6e..18525b9517 100644
--- a/util/stream/pipe.h
+++ b/util/stream/pipe.h
@@ -76,15 +76,15 @@ private:
void DoWrite(const void* buf, size_t len) override;
};
-class TPipedBase {
+class TPipedBase {
protected:
TPipedBase(PIPEHANDLE fd);
virtual ~TPipedBase();
protected:
TPipeHandle Handle_;
-};
-
+};
+
/**
* Input stream that binds to a standard output stream of an existing process.
*/
@@ -92,11 +92,11 @@ class TPipedInput: public TPipedBase, public IInputStream {
public:
TPipedInput(PIPEHANDLE fd);
~TPipedInput() override;
-
+
private:
size_t DoRead(void* buf, size_t len) override;
-};
-
+};
+
/**
* Output stream that binds to a standard input stream of an existing process.
*/
@@ -104,9 +104,9 @@ class TPipedOutput: public TPipedBase, public IOutputStream {
public:
TPipedOutput(PIPEHANDLE fd);
~TPipedOutput() override;
-
+
private:
void DoWrite(const void* buf, size_t len) override;
-};
-
+};
+
/** @} */