diff options
author | dobrokot <dobrokot@yandex-team.ru> | 2022-02-10 16:49:07 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:07 +0300 |
commit | 25d83bf841d8b3ce3886525078f1964ac3c293c5 (patch) | |
tree | bd52fa16c8dd727890b2ef9d87d1a402bd0d3a9a /util | |
parent | 1d2e8a8e9976488ea69a7e4763aa749244f82612 (diff) | |
download | ydb-25d83bf841d8b3ce3886525078f1964ac3c293c5.tar.gz |
Restoring authorship annotation for <dobrokot@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util')
41 files changed, 480 insertions, 480 deletions
diff --git a/util/charset/generated/unidata.cpp b/util/charset/generated/unidata.cpp index 6f5adbbc0a..f8344a9724 100644 --- a/util/charset/generated/unidata.cpp +++ b/util/charset/generated/unidata.cpp @@ -5340,7 +5340,7 @@ namespace { namespace NUnidataTableGenerated { }, // P[614] }; // static const NUnicode::NPrivate::TUnidataTable::TValuePtr P[][32] - static const NUnicode::NPrivate::TUnidataTable::TValuePtr* const Indexes[] = { + static const NUnicode::NPrivate::TUnidataTable::TValuePtr* const Indexes[] = { P[0], P[1], P[2], P[3], P[4], P[5], P[6], P[7], P[8], P[9], P[10], P[11], P[12], P[13], P[14], P[15], P[16], P[17], P[18], P[19], P[20], P[21], P[22], P[23], P[24], P[25], P[26], P[27], P[28], P[29], P[30], P[31], P[32], P[33], P[34], P[35], P[36], P[37], P[38], P[39], P[37], P[40], P[41], P[42], P[43], P[44], P[45], P[46], @@ -7517,7 +7517,7 @@ namespace { namespace NUnidataTableGenerated { P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[614], - }; // static const NUnicode::NPrivate::TUnidataTable::TValuePtr* const Indexes[] + }; // static const NUnicode::NPrivate::TUnidataTable::TValuePtr* const Indexes[] static const size_t Size = 1114110; }} // namespace NUnidataTableGenerated diff --git a/util/charset/ut/ya.make b/util/charset/ut/ya.make index 6526815e92..de47f72202 100644 --- a/util/charset/ut/ya.make +++ b/util/charset/ut/ya.make @@ -7,7 +7,7 @@ DATA(arcadia/util/charset/ut/utf8) SRCS( utf8_ut.cpp - wide_ut.cpp + wide_ut.cpp ) INCLUDE(${ARCADIA_ROOT}/util/tests/ya_util_tests.inc) diff --git a/util/charset/utf8_ut.cpp b/util/charset/utf8_ut.cpp index 9e68881cca..115dac8271 100644 --- a/util/charset/utf8_ut.cpp +++ b/util/charset/utf8_ut.cpp @@ -1,22 +1,22 @@ #include "utf8.h" -#include "wide.h" - +#include "wide.h" + #include <util/stream/file.h> #include <util/ysaveload.h> #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/testing/unittest/env.h> - + Y_UNIT_TEST_SUITE(TUtfUtilTest) { Y_UNIT_TEST(TestUTF8Len) { UNIT_ASSERT_EQUAL(GetNumberOfUTF8Chars("привет!"), 7); - } - + } + Y_UNIT_TEST(TestToLowerUtfString) { - UNIT_ASSERT_VALUES_EQUAL(ToLowerUTF8("xyz XYZ ПРИВЕТ!"), "xyz xyz привет!"); - + UNIT_ASSERT_VALUES_EQUAL(ToLowerUTF8("xyz XYZ ПРИВЕТ!"), "xyz xyz привет!"); + UNIT_ASSERT_VALUES_EQUAL(ToLowerUTF8(TStringBuf("xyz")), "xyz"); - + { TString s = "привет!"; TString q = "ПРИВЕТ!"; @@ -24,7 +24,7 @@ Y_UNIT_TEST_SUITE(TUtfUtilTest) { UNIT_ASSERT(ToLowerUTF8Impl(s.data(), s.size(), tmp) == false); UNIT_ASSERT(ToLowerUTF8Impl(q.data(), q.size(), tmp) == true); } - + { const char* weird = "\xC8\xBE"; // 'Ⱦ', U+023E. strlen(weird)==2, strlen(tolower_utf8(weird)) is 3 const char* turkI = "İ"; //strlen("İ") == 2, strlen(tolower_utf8("İ") == 1 @@ -41,16 +41,16 @@ Y_UNIT_TEST_SUITE(TUtfUtilTest) { s += chars[k % N]; k /= N; } - + TUtf16String tmp = UTF8ToWide(s); tmp.to_lower(); - + UNIT_ASSERT_VALUES_EQUAL(ToLowerUTF8(s), WideToUTF8(tmp)); } numberOfVariants *= N; - } - } - } + } + } + } Y_UNIT_TEST(TestToUpperUtfString) { UNIT_ASSERT_VALUES_EQUAL(ToUpperUTF8("xyz XYZ привет!"), "XYZ XYZ ПРИВЕТ!"); @@ -123,4 +123,4 @@ Y_UNIT_TEST_SUITE(TUtfUtilTest) { wtextScalar.remove(wtextSSE.size()); UNIT_ASSERT(wtextScalar == wtextSSE); } -} +} diff --git a/util/charset/wide.h b/util/charset/wide.h index 04e6928aab..d9402f5f05 100644 --- a/util/charset/wide.h +++ b/util/charset/wide.h @@ -811,21 +811,21 @@ TUtf32String ToTitleRet(const TUtf32StringBuf text, size_t pos = 0, size_t count // insertBr=true - replace '\r' and '\n' with "<BR>" template <bool insertBr> void EscapeHtmlChars(TUtf16String& str); - -//! returns number of characters in range. Handle surrogate pairs as one character. -inline size_t CountWideChars(const wchar16* b, const wchar16* e) { - size_t count = 0; + +//! returns number of characters in range. Handle surrogate pairs as one character. +inline size_t CountWideChars(const wchar16* b, const wchar16* e) { + size_t count = 0; Y_ENSURE(b <= e, TStringBuf("invalid iterators")); - while (b < e) { - b = SkipSymbol(b, e); + while (b < e) { + b = SkipSymbol(b, e); ++count; - } - return count; -} - + } + return count; +} + inline size_t CountWideChars(const TWtringBuf str) { - return CountWideChars(str.begin(), str.end()); -} + return CountWideChars(str.begin(), str.end()); +} //! checks whether the range is valid UTF-16 sequence inline bool IsValidUTF16(const wchar16* b, const wchar16* e) { diff --git a/util/charset/wide_ut.cpp b/util/charset/wide_ut.cpp index d8f3233e73..6612d59aa0 100644 --- a/util/charset/wide_ut.cpp +++ b/util/charset/wide_ut.cpp @@ -545,8 +545,8 @@ void TConversionTest::TestGetNumOfUTF8Chars() { result = GetNumberOfUTF8Chars(utext, 1, n); UNIT_ASSERT(!result); UNIT_ASSERT(n == 0); - - UNIT_ASSERT_EQUAL(GetNumberOfUTF8Chars("привет!"), 7); + + UNIT_ASSERT_EQUAL(GetNumberOfUTF8Chars("привет!"), 7); } void TConversionTest::TestSubstrUTF8() { diff --git a/util/datetime/systime.cpp b/util/datetime/systime.cpp index 6ee7e8fc6e..9944642dad 100644 --- a/util/datetime/systime.cpp +++ b/util/datetime/systime.cpp @@ -61,7 +61,7 @@ char* ctime_r(const time_t* clock, char* buf) { //! @note this code adopted from //! http://osdir.com/ml/web.wget.patches/2005-07/msg00010.html //! Subject: A more robust timegm - msg#00010 -time_t TimeGM(const struct tm* t) { +time_t TimeGM(const struct tm* t) { static const unsigned short int month_to_days[][13] = { {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}, {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}}; diff --git a/util/datetime/systime.h b/util/datetime/systime.h index 491d36e802..a498ed7ab2 100644 --- a/util/datetime/systime.h +++ b/util/datetime/systime.h @@ -6,7 +6,7 @@ #include <ctime> // timegm and gmtime_r versions that don't need access to filesystem or a big stack -time_t TimeGM(const struct tm* t); +time_t TimeGM(const struct tm* t); struct tm* GmTimeR(const time_t* timer, struct tm* tmbuf); // safe version of ctime, convinient version of ctime_r TString CTimeR(const time_t* timer); diff --git a/util/digest/city.cpp b/util/digest/city.cpp index c25f175d54..566b66aa48 100644 --- a/util/digest/city.cpp +++ b/util/digest/city.cpp @@ -311,13 +311,13 @@ uint128 CityHash128(const char* s, size_t len) noexcept { } // TODO(yazevnul): move this function to unittests -void TestCompilationOfCityHashTemplates() { +void TestCompilationOfCityHashTemplates() { TStringBuf s; CityHash64(s); CityHash64WithSeed(s, 1); CityHash64WithSeeds(s, 1, 2); CityHash128(s); CityHash128WithSeed(s, uint128(1, 2)); -} - +} + #endif diff --git a/util/digest/city.h b/util/digest/city.h index 675a798074..77ecba67a2 100644 --- a/util/digest/city.h +++ b/util/digest/city.h @@ -1,7 +1,7 @@ #pragma once #include <util/generic/utility.h> -#include <util/generic/strbuf.h> +#include <util/generic/strbuf.h> #include <utility> @@ -18,9 +18,9 @@ constexpr ui64 Uint128High64(const uint128& x) { return x.second; } -// Hash functions for a byte array. -// http://en.wikipedia.org/wiki/CityHash - +// Hash functions for a byte array. +// http://en.wikipedia.org/wiki/CityHash + Y_PURE_FUNCTION ui64 CityHash64(const char* buf, size_t len) noexcept; Y_PURE_FUNCTION ui64 CityHash64WithSeed(const char* buf, size_t len, ui64 seed) noexcept; @@ -43,41 +43,41 @@ inline ui64 Hash128to64(const uint128& x) { b *= kMul; return b; } - + namespace NPrivateCityHash { template <class TStringType> inline TStringBuf GetBufFromStr(const TStringType& str) { static_assert(std::is_integral<std::remove_reference_t<decltype(*str.data())>>::value, "invalid type passed to hash function"); return TStringBuf(reinterpret_cast<const char*>(str.data()), (str.size()) * sizeof(*str.data())); } -} - +} + template <class TStringType> inline ui64 CityHash64(const TStringType& str) { TStringBuf buf = NPrivateCityHash::GetBufFromStr(str); return CityHash64(buf.data(), buf.size()); -} - +} + template <class TStringType> inline ui64 CityHash64WithSeeds(const TStringType& str, ui64 seed0, ui64 seed1) { TStringBuf buf = NPrivateCityHash::GetBufFromStr(str); return CityHash64WithSeeds(buf.data(), buf.size(), seed0, seed1); -} - +} + template <class TStringType> inline ui64 CityHash64WithSeed(const TStringType& str, ui64 seed) { TStringBuf buf = NPrivateCityHash::GetBufFromStr(str); return CityHash64WithSeed(buf.data(), buf.size(), seed); -} - +} + template <class TStringType> inline uint128 CityHash128(const TStringType& str) { TStringBuf buf = NPrivateCityHash::GetBufFromStr(str); return CityHash128(buf.data(), buf.size()); -} - +} + template <class TStringType> inline uint128 CityHash128WithSeed(const TStringType& str, uint128 seed) { TStringBuf buf = NPrivateCityHash::GetBufFromStr(str); return CityHash128WithSeed(buf.data(), buf.size(), seed); -} +} diff --git a/util/digest/murmur.cpp b/util/digest/murmur.cpp index b041d3e5f2..22ef50014e 100644 --- a/util/digest/murmur.cpp +++ b/util/digest/murmur.cpp @@ -1,5 +1,5 @@ -#include "murmur.h" - +#include "murmur.h" + #include <util/system/unaligned_mem.h> namespace NMurmurPrivate { diff --git a/util/digest/murmur.h b/util/digest/murmur.h index 6b519b430a..87ad2c2d4c 100644 --- a/util/digest/murmur.h +++ b/util/digest/murmur.h @@ -36,7 +36,7 @@ static inline T MurmurHash(const void* buf, size_t len, T init) noexcept { template <class T> static inline T MurmurHash(const void* buf, size_t len) noexcept { - return MurmurHash<T>(buf, len, (T)0); + return MurmurHash<T>(buf, len, (T)0); } //non-inline version diff --git a/util/digest/murmur_ut.cpp b/util/digest/murmur_ut.cpp index 29287668bc..0316264e72 100644 --- a/util/digest/murmur_ut.cpp +++ b/util/digest/murmur_ut.cpp @@ -1,4 +1,4 @@ - + #include "murmur.h" #include <library/cpp/testing/unittest/registar.h> diff --git a/util/generic/algorithm.h b/util/generic/algorithm.h index badfb88993..cbfb41ff04 100644 --- a/util/generic/algorithm.h +++ b/util/generic/algorithm.h @@ -3,9 +3,9 @@ #include "is_in.h" #include "utility.h" -#include <util/system/defaults.h> +#include <util/system/defaults.h> #include <util/generic/fwd.h> - + #include <numeric> #include <algorithm> #include <iterator> @@ -154,51 +154,51 @@ static inline auto FindIf(C&& c, P p) { } template <class I, class P> -static inline bool AllOf(I f, I l, P pred) { +static inline bool AllOf(I f, I l, P pred) { return std::all_of(f, l, pred); -} - +} + template <class C, class P> -static inline bool AllOf(const C& c, P pred) { +static inline bool AllOf(const C& c, P pred) { using std::begin; using std::end; return AllOf(begin(c), end(c), pred); -} - +} + template <class I, class P> -static inline bool AnyOf(I f, I l, P pred) { +static inline bool AnyOf(I f, I l, P pred) { return std::any_of(f, l, pred); -} - +} + template <class C, class P> -static inline bool AnyOf(const C& c, P pred) { +static inline bool AnyOf(const C& c, P pred) { using std::begin; using std::end; return AnyOf(begin(c), end(c), pred); -} - -// FindIfPtr - return NULL if not found. Works for arrays, containers, iterators +} + +// FindIfPtr - return NULL if not found. Works for arrays, containers, iterators template <class I, class P> static inline auto FindIfPtr(I f, I l, P pred) -> decltype(&*f) { - I found = FindIf(f, l, pred); + I found = FindIf(f, l, pred); return (found != l) ? &*found : nullptr; -} - +} + template <class C, class P> static inline auto FindIfPtr(C&& c, P pred) { using std::begin; using std::end; return FindIfPtr(begin(c), end(c), pred); -} - -template <class C, class T> +} + +template <class C, class T> static inline size_t FindIndex(C&& c, const T& x) { using std::begin; using std::end; auto it = Find(begin(c), end(c), x); return it == end(c) ? NPOS : (it - begin(c)); -} - +} + template <class C, class P> static inline size_t FindIndexIf(C&& c, P p) { using std::begin; @@ -207,17 +207,17 @@ static inline size_t FindIndexIf(C&& c, P p) { return it == end(c) ? NPOS : (it - begin(c)); } -//EqualToOneOf(x, "apple", "orange") means (x == "apple" || x == "orange") +//EqualToOneOf(x, "apple", "orange") means (x == "apple" || x == "orange") template <typename T> inline bool EqualToOneOf(const T&) { - return false; -} + return false; +} template <typename T, typename U, typename... Other> inline bool EqualToOneOf(const T& x, const U& y, const Other&... other) { - return x == y || EqualToOneOf(x, other...); -} - + return x == y || EqualToOneOf(x, other...); +} + template <typename T> static inline size_t CountOf(const T&) { return 0; @@ -342,11 +342,11 @@ void Erase(C& c, const TValue& value) { c.erase(std::remove(c.begin(), c.end(), value), c.end()); } -template <class C, class P> -void EraseIf(C& c, P p) { +template <class C, class P> +void EraseIf(C& c, P p) { c.erase(std::remove_if(c.begin(), c.end(), p), c.end()); -} - +} + template <class C, class P> void EraseNodesIf(C& c, P p) { for (auto iter = c.begin(), last = c.end(); iter != last;) { @@ -643,18 +643,18 @@ static inline auto Count(const TContainer& container, const TValue& value) { return Count(std::cbegin(container), std::cend(container), value); } -template <class It, class P> +template <class It, class P> static inline auto CountIf(It first, It last, P p) { return std::count_if(first, last, p); -} - +} + template <class C, class P> static inline auto CountIf(const C& c, P pred) { using std::begin; using std::end; return CountIf(begin(c), end(c), pred); -} - +} + template <class I1, class I2> static inline std::pair<I1, I2> Mismatch(I1 b1, I1 e1, I2 b2) { return std::mismatch(b1, e1, b2); diff --git a/util/generic/algorithm_ut.cpp b/util/generic/algorithm_ut.cpp index 8d732fcc0c..8db678f3cb 100644 --- a/util/generic/algorithm_ut.cpp +++ b/util/generic/algorithm_ut.cpp @@ -1,11 +1,11 @@ #include <library/cpp/testing/unittest/registar.h> - + #include "algorithm.h" #include "strbuf.h" #include "string.h" - -static auto isOne = [](char c) { return c == '1'; }; - + +static auto isOne = [](char c) { return c == '1'; }; + Y_UNIT_TEST_SUITE(TAlgorithm) { Y_UNIT_TEST(AnyTest) { UNIT_ASSERT(0 == AnyOf(TStringBuf("00"), isOne)); @@ -18,8 +18,8 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT(0 == AnyOf(array00, isOne)); const char array01[]{'0', '1'}; UNIT_ASSERT(1 == AnyOf(array01, isOne)); - } - + } + Y_UNIT_TEST(AllOfTest) { UNIT_ASSERT(0 == AllOf(TStringBuf("00"), isOne)); UNIT_ASSERT(0 == AllOf(TStringBuf("01"), isOne)); @@ -31,8 +31,8 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT(0 == AllOf(array01, isOne)); const char array11[]{'1', '1'}; UNIT_ASSERT(1 == AllOf(array11, isOne)); - } - + } + Y_UNIT_TEST(CountIfTest) { UNIT_ASSERT(3 == CountIf(TStringBuf("____1________1____1_______"), isOne)); UNIT_ASSERT(5 == CountIf(TStringBuf("1____1________1____1_______1"), isOne)); @@ -42,8 +42,8 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { const char array[] = "____1________1____1_______"; UNIT_ASSERT(3 == CountIf(array, isOne)); - } - + } + Y_UNIT_TEST(CountTest) { UNIT_ASSERT(3 == Count("____1________1____1_______", '1')); UNIT_ASSERT(3 == Count(TStringBuf("____1________1____1_______"), '1')); @@ -66,15 +66,15 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { private: TStrokaNoCopy(const TStrokaNoCopy&); void operator=(const TStrokaNoCopy&); - }; - + }; + Y_UNIT_TEST(CountOfTest) { UNIT_ASSERT_VALUES_EQUAL(CountOf(1, 2), 0); UNIT_ASSERT_VALUES_EQUAL(CountOf(1, 1), 1); UNIT_ASSERT_VALUES_EQUAL(CountOf(2, 4, 5), 0); UNIT_ASSERT_VALUES_EQUAL(CountOf(2, 4, 2), 1); UNIT_ASSERT_VALUES_EQUAL(CountOf(3, 3, 3), 2); - + // Checking comparison of different types. UNIT_ASSERT_VALUES_EQUAL(CountOf(0x61, 'x', 'y', 'z'), 0); UNIT_ASSERT_VALUES_EQUAL(CountOf(0x61, 'a', 'b', 'c', 0x61), 2); @@ -102,32 +102,32 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } Y_UNIT_TEST(EqualToOneOfTest) { - UNIT_ASSERT(1 == EqualToOneOf(1, 1, 2)); - UNIT_ASSERT(1 == EqualToOneOf(2, 1, 2)); - UNIT_ASSERT(0 == EqualToOneOf(3, 1, 2)); - UNIT_ASSERT(1 == EqualToOneOf(1, 1)); - UNIT_ASSERT(0 == EqualToOneOf(1, 2)); - UNIT_ASSERT(0 == EqualToOneOf(3)); - - //test, that EqualToOneOf can compare different types, and don't copy objects: - TStrokaNoCopy x("x"); - TStrokaNoCopy y("y"); - TStrokaNoCopy z("z"); + UNIT_ASSERT(1 == EqualToOneOf(1, 1, 2)); + UNIT_ASSERT(1 == EqualToOneOf(2, 1, 2)); + UNIT_ASSERT(0 == EqualToOneOf(3, 1, 2)); + UNIT_ASSERT(1 == EqualToOneOf(1, 1)); + UNIT_ASSERT(0 == EqualToOneOf(1, 2)); + UNIT_ASSERT(0 == EqualToOneOf(3)); + + //test, that EqualToOneOf can compare different types, and don't copy objects: + TStrokaNoCopy x("x"); + TStrokaNoCopy y("y"); + TStrokaNoCopy z("z"); const char* px = "x"; const char* py = "y"; const char* pz = "z"; - - UNIT_ASSERT(1 == EqualToOneOf(x, px, py)); - UNIT_ASSERT(1 == EqualToOneOf(y, px, py)); - UNIT_ASSERT(1 == EqualToOneOf(y, px, y)); - UNIT_ASSERT(1 == EqualToOneOf(y, x, py)); - UNIT_ASSERT(0 == EqualToOneOf(z, px, py)); - UNIT_ASSERT(1 == EqualToOneOf(px, x, y)); - UNIT_ASSERT(1 == EqualToOneOf(py, x, y)); - UNIT_ASSERT(0 == EqualToOneOf(pz, x, y)); - } - - template <class TTestConstPtr> + + UNIT_ASSERT(1 == EqualToOneOf(x, px, py)); + UNIT_ASSERT(1 == EqualToOneOf(y, px, py)); + UNIT_ASSERT(1 == EqualToOneOf(y, px, y)); + UNIT_ASSERT(1 == EqualToOneOf(y, x, py)); + UNIT_ASSERT(0 == EqualToOneOf(z, px, py)); + UNIT_ASSERT(1 == EqualToOneOf(px, x, y)); + UNIT_ASSERT(1 == EqualToOneOf(py, x, y)); + UNIT_ASSERT(0 == EqualToOneOf(pz, x, y)); + } + + template <class TTestConstPtr> void TestFindPtrFoundValue(int j, TTestConstPtr root) { if (j == 3) { UNIT_ASSERT(root && *root == 3); @@ -139,35 +139,35 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } template <class TTestConstPtr> - void TestFindIfPtrFoundValue(int j, TTestConstPtr root) { - if (j == 3) { + void TestFindIfPtrFoundValue(int j, TTestConstPtr root) { + if (j == 3) { UNIT_ASSERT(root == nullptr); - } else if (j == 4) { - UNIT_ASSERT(root && *root == 2); - } else { - ythrow yexception() << "invalid param " << j; - } - } - + } else if (j == 4) { + UNIT_ASSERT(root && *root == 2); + } else { + ythrow yexception() << "invalid param " << j; + } + } + struct TVectorNoCopy: std::vector<int> { - public: + public: TVectorNoCopy() = default; - private: - TVectorNoCopy(const TVectorNoCopy&); - void operator=(const TVectorNoCopy&); - }; - + private: + TVectorNoCopy(const TVectorNoCopy&); + void operator=(const TVectorNoCopy&); + }; + Y_UNIT_TEST(FindPtrTest) { - TVectorNoCopy v; - v.push_back(1); - v.push_back(2); - v.push_back(3); - + TVectorNoCopy v; + v.push_back(1); + v.push_back(2); + v.push_back(3); + int array[3] = {1, 2, 3}; const int array_const[3] = {1, 2, 3}; - - //test (const, non-const) * (iterator, vector, array) * (found, not found) variants. + + //test (const, non-const) * (iterator, vector, array) * (found, not found) variants. // value '3' is in container, value '4' is not for (int j = 3; j <= 4; ++j) { TestFindPtrFoundValue<int*>(j, FindPtr(v, j)); @@ -190,40 +190,40 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { const int array_const[3] = {1, 2, 3}; //test (const, non-const) * (iterator, vector, array) * (found, not found) variants. - // search, that 2*2 == 4, but there is no value 'x' in array that (x*x == 3) - for (int j = 3; j <= 4; ++j) { + // search, that 2*2 == 4, but there is no value 'x' in array that (x*x == 3) + for (int j = 3; j <= 4; ++j) { TestFindIfPtrFoundValue<int*>(j, FindIfPtr(v, [j](int i) { return i * i == j; })); TestFindIfPtrFoundValue<int*>(j, FindIfPtr(v.begin(), v.end(), [j](int i) { return i * i == j; })); const TVectorNoCopy& q = v; TestFindIfPtrFoundValue<const int*>(j, FindIfPtr(q, [j](int i) { return i * i == j; })); - + TestFindIfPtrFoundValue<const int*>(j, FindIfPtr(q.begin(), q.end(), [j](int i) { return i * i == j; })); TestFindIfPtrFoundValue<int*>(j, FindIfPtr(array, [j](int i) { return i * i == j; })); TestFindIfPtrFoundValue<const int*>(j, FindIfPtr(array_const, [j](int i) { return i * i == j; })); - } - } - + } + } + Y_UNIT_TEST(FindIndexTest) { - TVectorNoCopy v; - v.push_back(1); - v.push_back(2); - v.push_back(3); - - UNIT_ASSERT_EQUAL(0, FindIndex(v, 1)); - UNIT_ASSERT_EQUAL(1, FindIndex(v, 2)); - UNIT_ASSERT_EQUAL(2, FindIndex(v, 3)); - UNIT_ASSERT_EQUAL(NPOS, FindIndex(v, 42)); - + TVectorNoCopy v; + v.push_back(1); + v.push_back(2); + v.push_back(3); + + UNIT_ASSERT_EQUAL(0, FindIndex(v, 1)); + UNIT_ASSERT_EQUAL(1, FindIndex(v, 2)); + UNIT_ASSERT_EQUAL(2, FindIndex(v, 3)); + UNIT_ASSERT_EQUAL(NPOS, FindIndex(v, 42)); + int array[3] = {1, 2, 3}; - - UNIT_ASSERT_EQUAL(0, FindIndex(array, 1)); - UNIT_ASSERT_EQUAL(1, FindIndex(array, 2)); - UNIT_ASSERT_EQUAL(2, FindIndex(array, 3)); - UNIT_ASSERT_EQUAL(NPOS, FindIndex(array, 42)); - + + UNIT_ASSERT_EQUAL(0, FindIndex(array, 1)); + UNIT_ASSERT_EQUAL(1, FindIndex(array, 2)); + UNIT_ASSERT_EQUAL(2, FindIndex(array, 3)); + UNIT_ASSERT_EQUAL(NPOS, FindIndex(array, 42)); + TVector<int> empty; - UNIT_ASSERT_EQUAL(NPOS, FindIndex(empty, 0)); - } + UNIT_ASSERT_EQUAL(NPOS, FindIndex(empty, 0)); + } Y_UNIT_TEST(FindIndexIfTest) { TVectorNoCopy v; @@ -276,10 +276,10 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { Y_UNIT_TEST(EraseIfTest) { TVector<int> data = {5, 4, 3, 2, 1, 0}; TVector<int> expected = {2, 1, 0}; - EraseIf(data, [](int i) { return i >= 3; }); - UNIT_ASSERT_EQUAL(data, expected); - } - + EraseIf(data, [](int i) { return i >= 3; }); + UNIT_ASSERT_EQUAL(data, expected); + } + Y_UNIT_TEST(EraseNodesIfTest) { TMap<int, int> map{{1, 1}, {2, 2}, {3, 5}}; TMap<int, int> expectedMap{{1, 1}}; diff --git a/util/generic/cast.h b/util/generic/cast.h index 0d4a41f385..268b79baf4 100644 --- a/util/generic/cast.h +++ b/util/generic/cast.h @@ -53,7 +53,7 @@ static inline T CheckedCast(F f) { } return static_cast<T>(f); -#endif // USE_DEBUG_CHECKED_CAST +#endif // USE_DEBUG_CHECKED_CAST } /* diff --git a/util/generic/hash.h b/util/generic/hash.h index e46db21fa9..1f2ae2ca38 100644 --- a/util/generic/hash.h +++ b/util/generic/hash.h @@ -1,7 +1,7 @@ #pragma once #include "fwd.h" -#include "mapfindptr.h" +#include "mapfindptr.h" #include <util/memory/alloc.h> #include <util/system/type_name.h> diff --git a/util/generic/map.h b/util/generic/map.h index b5001b56c0..92e79ad9af 100644 --- a/util/generic/map.h +++ b/util/generic/map.h @@ -1,7 +1,7 @@ #pragma once #include "fwd.h" -#include "mapfindptr.h" +#include "mapfindptr.h" #include <util/str_stl.h> #include <util/memory/alloc.h> diff --git a/util/generic/mapfindptr.h b/util/generic/mapfindptr.h index bc10cac60f..fdacd9e997 100644 --- a/util/generic/mapfindptr.h +++ b/util/generic/mapfindptr.h @@ -1,41 +1,41 @@ -#pragma once - +#pragma once + #include <type_traits> -/** MapFindPtr usage: - -if (T* value = MapFindPtr(myMap, someKey) { - Cout << *value; -} - -*/ - +/** MapFindPtr usage: + +if (T* value = MapFindPtr(myMap, someKey) { + Cout << *value; +} + +*/ + template <class Map, class K> inline auto MapFindPtr(Map& map, const K& key) { auto i = map.find(key); return (i == map.end() ? nullptr : &i->second); -} - +} + template <class Map, class K> inline auto MapFindPtr(const Map& map, const K& key) { auto i = map.find(key); return (i == map.end() ? nullptr : &i->second); -} - +} + /** helper for THashMap/TMap */ template <class Derived> -struct TMapOps { +struct TMapOps { template <class K> inline auto FindPtr(const K& key) { - return MapFindPtr(static_cast<Derived&>(*this), key); - } + return MapFindPtr(static_cast<Derived&>(*this), key); + } template <class K> inline auto FindPtr(const K& key) const { - return MapFindPtr(static_cast<const Derived&>(*this), key); - } + return MapFindPtr(static_cast<const Derived&>(*this), key); + } template <class K, class DefaultValue> inline auto Value(const K& key, const DefaultValue& defaultValue) const -> std::remove_reference_t<decltype(*this->FindPtr(key))> { @@ -57,4 +57,4 @@ struct TMapOps { template <class K, class V> inline const V& ValueRef(const K& key, V&& defaultValue) const = delete; -}; +}; diff --git a/util/generic/mapfindptr_ut.cpp b/util/generic/mapfindptr_ut.cpp index 613da7a96b..e78817425b 100644 --- a/util/generic/mapfindptr_ut.cpp +++ b/util/generic/mapfindptr_ut.cpp @@ -2,26 +2,26 @@ #include "hash.h" #include <library/cpp/testing/unittest/registar.h> - + #include <map> #include "mapfindptr.h" Y_UNIT_TEST_SUITE(TMapFindPtrTest) { struct TTestMap: std::map<int, TString>, TMapOps<TTestMap> {}; - + Y_UNIT_TEST(TestDerivedClass) { TTestMap a; - + a[42] = "cat"; UNIT_ASSERT(a.FindPtr(42)); UNIT_ASSERT_EQUAL(*a.FindPtr(42), "cat"); UNIT_ASSERT_EQUAL(a.FindPtr(0), nullptr); - + //test mutation if (TString* p = a.FindPtr(42)) { *p = "dog"; - } + } UNIT_ASSERT(a.FindPtr(42)); UNIT_ASSERT_EQUAL(*a.FindPtr(42), "dog"); diff --git a/util/generic/ptr.h b/util/generic/ptr.h index 19db0e3ec5..2af6603934 100644 --- a/util/generic/ptr.h +++ b/util/generic/ptr.h @@ -17,13 +17,13 @@ using TGuardConversion = typename std::enable_if_t<std::is_convertible<U*, T*>:: template <class T> inline void AssertTypeComplete() { - // If compiler triggers this error from destructor of your class with - // smart pointer, then may be you should move the destructor definition - // to the .cpp file, where type T have full definition. - // - // 'delete' called on pointer to incomplete type is - // undefined behavior (missing destructor call/corrupted memory manager). - // 'sizeof' is used to trigger compile-time error. + // If compiler triggers this error from destructor of your class with + // smart pointer, then may be you should move the destructor definition + // to the .cpp file, where type T have full definition. + // + // 'delete' called on pointer to incomplete type is + // undefined behavior (missing destructor call/corrupted memory manager). + // 'sizeof' is used to trigger compile-time error. static_assert(sizeof(T) != 0, "Type must be complete"); } diff --git a/util/generic/refcount.h b/util/generic/refcount.h index 966e853b77..3f37e76cd7 100644 --- a/util/generic/refcount.h +++ b/util/generic/refcount.h @@ -63,9 +63,9 @@ protected: }; #if defined(SIMPLE_COUNTER_THREAD_CHECK) - + #include <util/system/thread.i> - + class TCheckPolicy { public: inline TCheckPolicy() { diff --git a/util/generic/strbase.h b/util/generic/strbase.h index ab39fc7537..eed24a1615 100644 --- a/util/generic/strbase.h +++ b/util/generic/strbase.h @@ -475,18 +475,18 @@ public: return AsStringView().rfind(str.data(), pos, str.size()); } - //~~~~Contains~~~~ + //~~~~Contains~~~~ /** * @returns Whether this string contains the provided substring. */ inline bool Contains(const TStringView s, size_t pos = 0) const noexcept { return !s.length() || find(s, pos) != npos; - } - + } + inline bool Contains(TChar c, size_t pos = 0) const noexcept { - return find(c, pos) != npos; - } - + return find(c, pos) != npos; + } + inline void Contains(std::enable_if<std::is_unsigned<TCharType>::value, char> c, size_t pos = 0) const noexcept { return find(ui8(c), pos) != npos; } diff --git a/util/generic/strbuf.h b/util/generic/strbuf.h index 70b9360d58..ab463595a9 100644 --- a/util/generic/strbuf.h +++ b/util/generic/strbuf.h @@ -321,19 +321,19 @@ public: inline bool AfterPrefix(const TdSelf& prefix, TdSelf& result) const noexcept { if (this->StartsWith(prefix)) { result = Tail(prefix.size()); - return true; - } - return false; - } - + return true; + } + return false; + } + inline bool BeforeSuffix(const TdSelf& suffix, TdSelf& result) const noexcept { if (this->EndsWith(suffix)) { result = Head(size() - suffix.size()); - return true; - } - return false; - } - + return true; + } + return false; + } + // returns true if string started with `prefix`, false otherwise inline bool SkipPrefix(const TdSelf& prefix) noexcept { return AfterPrefix(prefix, *this); diff --git a/util/generic/strbuf_ut.cpp b/util/generic/strbuf_ut.cpp index 69cde785af..195b7b1b5d 100644 --- a/util/generic/strbuf_ut.cpp +++ b/util/generic/strbuf_ut.cpp @@ -82,19 +82,19 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { } Y_UNIT_TEST(TestAfterPrefix) { - TStringBuf str("cat_dog"); - - TStringBuf r = "the_same"; - UNIT_ASSERT(!str.AfterPrefix("dog", r)); - UNIT_ASSERT_EQUAL(r, "the_same"); - UNIT_ASSERT(str.AfterPrefix("cat_", r)); - UNIT_ASSERT_EQUAL(r, "dog"); - - //example: - str = "http://ya.ru"; - if (str.AfterPrefix("http://", r)) { - UNIT_ASSERT_EQUAL(r, "ya.ru"); - } + TStringBuf str("cat_dog"); + + TStringBuf r = "the_same"; + UNIT_ASSERT(!str.AfterPrefix("dog", r)); + UNIT_ASSERT_EQUAL(r, "the_same"); + UNIT_ASSERT(str.AfterPrefix("cat_", r)); + UNIT_ASSERT_EQUAL(r, "dog"); + + //example: + str = "http://ya.ru"; + if (str.AfterPrefix("http://", r)) { + UNIT_ASSERT_EQUAL(r, "ya.ru"); + } // SkipPrefix() TStringBuf a = "abcdef"; @@ -106,22 +106,22 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { UNIT_ASSERT(a.SkipPrefix("def") && a == ""); UNIT_ASSERT(a.SkipPrefix("") && a == ""); UNIT_ASSERT(!a.SkipPrefix("def") && a == ""); - } - + } + Y_UNIT_TEST(TestBeforeSuffix) { - TStringBuf str("cat_dog"); - - TStringBuf r = "the_same"; - UNIT_ASSERT(!str.BeforeSuffix("cat", r)); - UNIT_ASSERT_EQUAL(r, "the_same"); - UNIT_ASSERT(str.BeforeSuffix("_dog", r)); - UNIT_ASSERT_EQUAL(r, "cat"); - - //example: - str = "maps.yandex.com.ua"; - if (str.BeforeSuffix(".ru", r)) { - UNIT_ASSERT_EQUAL(r, "maps.yandex"); - } + TStringBuf str("cat_dog"); + + TStringBuf r = "the_same"; + UNIT_ASSERT(!str.BeforeSuffix("cat", r)); + UNIT_ASSERT_EQUAL(r, "the_same"); + UNIT_ASSERT(str.BeforeSuffix("_dog", r)); + UNIT_ASSERT_EQUAL(r, "cat"); + + //example: + str = "maps.yandex.com.ua"; + if (str.BeforeSuffix(".ru", r)) { + UNIT_ASSERT_EQUAL(r, "maps.yandex"); + } // ChopSuffix() TStringBuf a = "abcdef"; @@ -133,8 +133,8 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { UNIT_ASSERT(a.ChopSuffix("abc") && a == ""); UNIT_ASSERT(a.ChopSuffix("") && a == ""); UNIT_ASSERT(!a.ChopSuffix("abc") && a == ""); - } - + } + Y_UNIT_TEST(TestEmpty) { UNIT_ASSERT(TStringBuf().empty()); UNIT_ASSERT(!TStringBuf("q").empty()); diff --git a/util/generic/string_ut.h b/util/generic/string_ut.h index 44bb10bdeb..5ac2cef731 100644 --- a/util/generic/string_ut.h +++ b/util/generic/string_ut.h @@ -725,20 +725,20 @@ public: void TestContains() { const TStringType s(Data._0123456_12345()); const TStringType s2(Data._0123()); - - UNIT_ASSERT(s.Contains(Data._345())); - UNIT_ASSERT(!s2.Contains(Data._345())); - - UNIT_ASSERT(s.Contains('1')); - UNIT_ASSERT(!s.Contains('*')); - + + UNIT_ASSERT(s.Contains(Data._345())); + UNIT_ASSERT(!s2.Contains(Data._345())); + + UNIT_ASSERT(s.Contains('1')); + UNIT_ASSERT(!s.Contains('*')); + TStringType empty; - UNIT_ASSERT(s.Contains(empty)); - UNIT_ASSERT(!empty.Contains(s)); - UNIT_ASSERT(empty.Contains(empty)); + UNIT_ASSERT(s.Contains(empty)); + UNIT_ASSERT(!empty.Contains(s)); + UNIT_ASSERT(empty.Contains(empty)); UNIT_ASSERT(s.Contains(empty, s.length())); - } - + } + // Operators void TestOperators() { diff --git a/util/random/entropy.cpp b/util/random/entropy.cpp index 3617edb83d..bd34c0faed 100644 --- a/util/random/entropy.cpp +++ b/util/random/entropy.cpp @@ -26,7 +26,7 @@ #include <util/generic/buffer.h> #include <util/generic/singleton.h> -#include <util/digest/murmur.h> +#include <util/digest/murmur.h> #include <util/digest/city.h> #include <util/ysaveload.h> diff --git a/util/string/ascii.h b/util/string/ascii.h index 10344384d3..5b743029a8 100644 --- a/util/string/ascii.h +++ b/util/string/ascii.h @@ -4,13 +4,13 @@ #include <util/system/compat.h> #include <util/generic/string.h> -// ctype.h-like functions, locale-independent: -// IsAscii{Upper,Lower,Digit,Alpha,Alnum,Space} and -// AsciiTo{Upper,Lower} -// -// standard functions from <ctype.h> are locale dependent, -// and cause undefined behavior when called on chars outside [0..127] range - +// ctype.h-like functions, locale-independent: +// IsAscii{Upper,Lower,Digit,Alpha,Alnum,Space} and +// AsciiTo{Upper,Lower} +// +// standard functions from <ctype.h> are locale dependent, +// and cause undefined behavior when called on chars outside [0..127] range + namespace NPrivate { enum ECharClass { CC_SPACE = 1, @@ -61,9 +61,9 @@ namespace NPrivate { } constexpr bool IsAscii(const int c) noexcept { - return !(c & ~0x7f); -} - + return !(c & ~0x7f); +} + inline bool IsAsciiSpace(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_SPACE; } @@ -71,27 +71,27 @@ inline bool IsAsciiSpace(unsigned char c) { inline bool IsAsciiUpper(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_UPPER; } - + inline bool IsAsciiLower(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_LOWER; -} - +} + inline bool IsAsciiDigit(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_DIGIT; -} - +} + inline bool IsAsciiAlpha(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_ALPHA; -} - +} + inline bool IsAsciiAlnum(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_ALNUM; -} - +} + inline bool IsAsciiHex(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_ISHEX; -} - +} + inline bool IsAsciiPunct(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_PUNCT; } @@ -101,9 +101,9 @@ inline bool IsAsciiPunct(unsigned char c) { template <class T> inline bool IsAsciiSpace(T c) { return ::NPrivate::RangeOk(c) && IsAsciiSpace(static_cast<unsigned char>(c)); -} - -template <class T> +} + +template <class T> inline bool IsAsciiUpper(T c) { return ::NPrivate::RangeOk(c) && IsAsciiUpper(static_cast<unsigned char>(c)); } @@ -150,12 +150,12 @@ inline char AsciiToLower(char c) noexcept { template <class T> inline ::NPrivate::TDereferenced<T> AsciiToLower(T c) noexcept { return (c >= 0 && c <= 127) ? (::NPrivate::TDereferenced<T>)AsciiToLower((ui8)c) : c; -} - -template <class T> +} + +template <class T> inline ::NPrivate::TDereferenced<T> AsciiToUpper(T c) noexcept { - return IsAsciiLower(c) ? (c + ('A' - 'a')) : c; -} + return IsAsciiLower(c) ? (c + ('A' - 'a')) : c; +} /** * ASCII case-insensitive string comparison (for proper UTF8 strings diff --git a/util/string/ascii_ut.cpp b/util/string/ascii_ut.cpp index 89069fee50..4108302622 100644 --- a/util/string/ascii_ut.cpp +++ b/util/string/ascii_ut.cpp @@ -1,42 +1,42 @@ -#include "ascii.h" -#include <ctype.h> - +#include "ascii.h" +#include <ctype.h> + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(TAsciiTest) { Y_UNIT_TEST(TestAscii) { - UNIT_ASSERT(IsAsciiDigit('3')); - UNIT_ASSERT(!IsAsciiDigit('x')); - - UNIT_ASSERT(IsAsciiAlpha('r')); - UNIT_ASSERT(IsAsciiAlpha('R')); - UNIT_ASSERT(!IsAsciiAlpha('3')); - - UNIT_ASSERT_EQUAL(AsciiToLower('3'), '3'); - UNIT_ASSERT_EQUAL(AsciiToLower('A'), 'a'); - UNIT_ASSERT_EQUAL(AsciiToLower('a'), 'a'); - - UNIT_ASSERT_EQUAL(AsciiToUpper('3'), '3'); - UNIT_ASSERT_EQUAL(AsciiToUpper('A'), 'A'); - UNIT_ASSERT_EQUAL(AsciiToUpper('a'), 'A'); - - UNIT_ASSERT(IsAscii('a')); - UNIT_ASSERT(!IsAscii(-100)); - UNIT_ASSERT(!IsAscii(+200)); - UNIT_ASSERT(!IsAscii(int('a') + 256)); - - for (int i = 0; i < 128; ++i) { - UNIT_ASSERT_VALUES_EQUAL((bool)isxdigit(i), IsAsciiHex(i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isspace(i), IsAsciiSpace((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isspace(i), IsAsciiSpace((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isalnum(i), IsAsciiAlnum((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isalpha(i), IsAsciiAlpha((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isupper(i), IsAsciiUpper((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)islower(i), IsAsciiLower((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isdigit(i), IsAsciiDigit((char)i)); + UNIT_ASSERT(IsAsciiDigit('3')); + UNIT_ASSERT(!IsAsciiDigit('x')); + + UNIT_ASSERT(IsAsciiAlpha('r')); + UNIT_ASSERT(IsAsciiAlpha('R')); + UNIT_ASSERT(!IsAsciiAlpha('3')); + + UNIT_ASSERT_EQUAL(AsciiToLower('3'), '3'); + UNIT_ASSERT_EQUAL(AsciiToLower('A'), 'a'); + UNIT_ASSERT_EQUAL(AsciiToLower('a'), 'a'); + + UNIT_ASSERT_EQUAL(AsciiToUpper('3'), '3'); + UNIT_ASSERT_EQUAL(AsciiToUpper('A'), 'A'); + UNIT_ASSERT_EQUAL(AsciiToUpper('a'), 'A'); + + UNIT_ASSERT(IsAscii('a')); + UNIT_ASSERT(!IsAscii(-100)); + UNIT_ASSERT(!IsAscii(+200)); + UNIT_ASSERT(!IsAscii(int('a') + 256)); + + for (int i = 0; i < 128; ++i) { + UNIT_ASSERT_VALUES_EQUAL((bool)isxdigit(i), IsAsciiHex(i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isspace(i), IsAsciiSpace((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isspace(i), IsAsciiSpace((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isalnum(i), IsAsciiAlnum((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isalpha(i), IsAsciiAlpha((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isupper(i), IsAsciiUpper((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)islower(i), IsAsciiLower((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isdigit(i), IsAsciiDigit((char)i)); UNIT_ASSERT_VALUES_EQUAL((bool)ispunct(i), IsAsciiPunct((char)i)); - } - } + } + } Y_UNIT_TEST(Test1) { for (int i = 128; i < 1000; ++i) { @@ -95,4 +95,4 @@ Y_UNIT_TEST_SUITE(TAsciiTest) { UNIT_ASSERT_EQUAL(AsciiHasSuffixIgnoreCase("qweasd", "asD"), true); UNIT_ASSERT_EQUAL(AsciiHasSuffixIgnoreCase("qweasd", "ast"), false); } -} +} diff --git a/util/string/cast.cpp b/util/string/cast.cpp index aa1e65a8e9..7f5f8c6b01 100644 --- a/util/string/cast.cpp +++ b/util/string/cast.cpp @@ -522,11 +522,11 @@ TString FromStringImpl<TString>(const char* data, size_t len) { } template <> -TStringBuf FromStringImpl<TStringBuf>(const char* data, size_t len) { - return TStringBuf(data, len); -} - -template <> +TStringBuf FromStringImpl<TStringBuf>(const char* data, size_t len) { + return TStringBuf(data, len); +} + +template <> std::string FromStringImpl<std::string>(const char* data, size_t len) { return std::string(data, len); } @@ -536,11 +536,11 @@ TUtf16String FromStringImpl<TUtf16String>(const wchar16* data, size_t len) { return TUtf16String(data, len); } -template <> -TWtringBuf FromStringImpl<TWtringBuf>(const wchar16* data, size_t len) { - return TWtringBuf(data, len); -} - +template <> +TWtringBuf FromStringImpl<TWtringBuf>(const wchar16* data, size_t len) { + return TWtringBuf(data, len); +} + // Try-versions template <> bool TryFromStringImpl<TStringBuf>(const char* data, size_t len, TStringBuf& result) { diff --git a/util/string/cast_ut.cpp b/util/string/cast_ut.cpp index 033450c38c..e0da29e1b9 100644 --- a/util/string/cast_ut.cpp +++ b/util/string/cast_ut.cpp @@ -19,7 +19,7 @@ #define EPS 10E-7 -#define HEX_MACROS_MAP(mac, type, val) mac(type, val, 2) mac(type, val, 8) mac(type, val, 10) mac(type, val, 16) +#define HEX_MACROS_MAP(mac, type, val) mac(type, val, 2) mac(type, val, 8) mac(type, val, 10) mac(type, val, 16) #define OK_HEX_CHECK(type, val, base) UNIT_ASSERT_EQUAL((IntFromStringForCheck<base>(IntToString<base>(val))), val); #define EXC_HEX_CHECK(type, val, base) UNIT_ASSERT_EXCEPTION((IntFromString<type, base>(IntToString<base>(val))), yexception); @@ -326,7 +326,7 @@ Y_UNIT_TEST_SUITE(TCastTest) { UNIT_ASSERT_VALUES_EQUAL(a, b); UNIT_ASSERT_VALUES_EQUAL((void*)a.data(), (void*)b.data()); } - + #if 0 Y_UNIT_TEST(TestBufferOverflow) { CheckConvertToBuffer<float>(1.f, 5, "1"); diff --git a/util/string/hex.cpp b/util/string/hex.cpp index 667397987f..deea4e3ba7 100644 --- a/util/string/hex.cpp +++ b/util/string/hex.cpp @@ -1,5 +1,5 @@ -#include "hex.h" - +#include "hex.h" + const char* const Char2DigitTable = ("\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" @@ -16,48 +16,48 @@ const char* const Char2DigitTable = ("\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"); - -char* HexEncode(const void* in, size_t len, char* out) { - const unsigned char* b = (const unsigned char*)in; - const unsigned char* e = b + len; - - while (b != e) { - *out++ = DigitToChar(*b / 16); - *out++ = DigitToChar(*b++ % 16); - } - - return out; -} - -void* HexDecode(const void* in, size_t len, void* ptr) { - const char* b = (const char*)in; - const char* e = b + len; + +char* HexEncode(const void* in, size_t len, char* out) { + const unsigned char* b = (const unsigned char*)in; + const unsigned char* e = b + len; + + while (b != e) { + *out++ = DigitToChar(*b / 16); + *out++ = DigitToChar(*b++ % 16); + } + + return out; +} + +void* HexDecode(const void* in, size_t len, void* ptr) { + const char* b = (const char*)in; + const char* e = b + len; Y_ENSURE(!(len & 1), TStringBuf("Odd buffer length passed to HexDecode")); - - char* out = (char*)ptr; - - while (b != e) { + + char* out = (char*)ptr; + + while (b != e) { *out++ = (char)String2Byte(b); - b += 2; - } - - return out; -} - + b += 2; + } + + return out; +} + TString HexEncode(const void* in, size_t len) { TString ret; - - ret.ReserveAndResize(len << 1); - HexEncode(in, len, ret.begin()); - - return ret; -} - + + ret.ReserveAndResize(len << 1); + HexEncode(in, len, ret.begin()); + + return ret; +} + TString HexDecode(const void* in, size_t len) { TString ret; - + ret.ReserveAndResize(len >> 1); HexDecode(in, len, ret.begin()); - - return ret; -} + + return ret; +} diff --git a/util/string/hex.h b/util/string/hex.h index af3d2d528f..5e9fdcbbbb 100644 --- a/util/string/hex.h +++ b/util/string/hex.h @@ -13,11 +13,11 @@ inline static char DigitToChar(unsigned char digit) { } extern const char* const Char2DigitTable; - + inline static int Char2Digit(char ch) { - char result = Char2DigitTable[(unsigned char)ch]; + char result = Char2DigitTable[(unsigned char)ch]; Y_ENSURE(result != '\xff', "invalid hex character " << (int)ch); - return result; + return result; } //! Convert a hex string of exactly 2 chars to int @@ -26,7 +26,7 @@ inline static int String2Byte(const char* s) { return Char2Digit(*s) * 16 + Char2Digit(*(s + 1)); } -char* HexEncode(const void* in, size_t len, char* out); +char* HexEncode(const void* in, size_t len, char* out); TString HexEncode(const void* in, size_t len); diff --git a/util/string/split.h b/util/string/split.h index bc46d9e64c..6852f0600f 100644 --- a/util/string/split.h +++ b/util/string/split.h @@ -441,7 +441,7 @@ void GetNext(TStringBuf& s, D delim, TMaybe<P>& param) { } } -// example: +// example: // Split(TStringBuf("Sherlock,2014,36.6"), ',', name, year, temperature); template <class D, class P1, class P2> void Split(TStringBuf s, D delim, P1& p1, P2& p2) { @@ -451,9 +451,9 @@ void Split(TStringBuf s, D delim, P1& p1, P2& p2) { } template <class D, class P1, class P2, class... Other> -void Split(TStringBuf s, D delim, P1& p1, P2& p2, Other&... other) { +void Split(TStringBuf s, D delim, P1& p1, P2& p2, Other&... other) { GetNext(s, delim, p1); - Split(s, delim, p2, other...); + Split(s, delim, p2, other...); } /** diff --git a/util/string/split_ut.cpp b/util/string/split_ut.cpp index 43e59f2d75..cd8b8fccdc 100644 --- a/util/string/split_ut.cpp +++ b/util/string/split_ut.cpp @@ -254,10 +254,10 @@ Y_UNIT_TEST_SUITE(SplitStringTest) { Y_UNIT_TEST(ConvenientSplitTest) { TString data("abc 22 33.5 xyz"); TString str; - int num1 = 0; - double num2 = 0; - TStringBuf strBuf; - Split(data, ' ', str, num1, num2, strBuf); + int num1 = 0; + double num2 = 0; + TStringBuf strBuf; + Split(data, ' ', str, num1, num2, strBuf); UNIT_ASSERT_VALUES_EQUAL(str, "abc"); UNIT_ASSERT_VALUES_EQUAL(num1, 22); UNIT_ASSERT_VALUES_EQUAL(num2, 33.5); diff --git a/util/system/defaults.h b/util/system/defaults.h index dcd7abea38..0a363b5949 100644 --- a/util/system/defaults.h +++ b/util/system/defaults.h @@ -151,5 +151,5 @@ constexpr bool Y_IS_DEBUG_BUILD = true; #if !defined(Y_GENERATE_UNIQUE_ID) #define Y_GENERATE_UNIQUE_ID(N) Y_CAT(N, __LINE__) #endif - -#define NPOS ((size_t)-1) + +#define NPOS ((size_t)-1) diff --git a/util/system/mutex.cpp b/util/system/mutex.cpp index 4041402db9..22fdf39a0b 100644 --- a/util/system/mutex.cpp +++ b/util/system/mutex.cpp @@ -1,7 +1,7 @@ #include "mutex.h" #include <util/generic/yexception.h> -#include <errno.h> +#include <errno.h> #if defined(_win_) #include "winint.h" diff --git a/util/system/shmat.cpp b/util/system/shmat.cpp index 07ff0d6caa..151dc5ba1b 100644 --- a/util/system/shmat.cpp +++ b/util/system/shmat.cpp @@ -89,12 +89,12 @@ namespace { } #endif -TSharedMemory::TSharedMemory() +TSharedMemory::TSharedMemory() : Handle(INVALID_FHANDLE) , Data(nullptr) - , Size(0) -{ -} + , Size(0) +{ +} #if defined(_win_) static void FormatName(char* buf, const TGUID& id) { diff --git a/util/system/shmat.h b/util/system/shmat.h index d9da3c151a..27467d1035 100644 --- a/util/system/shmat.h +++ b/util/system/shmat.h @@ -12,7 +12,7 @@ class TSharedMemory: public TThrRefBase { int Size; public: - TSharedMemory(); + TSharedMemory(); ~TSharedMemory() override; bool Create(int Size); diff --git a/util/system/tls.cpp b/util/system/tls.cpp index c2f1a04a14..09a30f6305 100644 --- a/util/system/tls.cpp +++ b/util/system/tls.cpp @@ -113,7 +113,7 @@ namespace { } virtual TPerThreadStorage* MyStorageSlow() = 0; - + virtual ~TGenericTlsBase() = default; }; } diff --git a/util/system/types.h b/util/system/types.h index 12e68a6060..d4306a4dc4 100644 --- a/util/system/types.h +++ b/util/system/types.h @@ -94,11 +94,11 @@ typedef int64_t i64; #error "Unsupported platform" #endif -// SUPERLONG -#if !defined(DONT_USE_SUPERLONG) && !defined(SUPERLONG_MAX) +// SUPERLONG +#if !defined(DONT_USE_SUPERLONG) && !defined(SUPERLONG_MAX) #define SUPERLONG_MAX ~LL(0) -typedef i64 SUPERLONG; -#endif +typedef i64 SUPERLONG; +#endif // UNICODE #ifdef __cplusplus diff --git a/util/thread/pool.h b/util/thread/pool.h index d1ea3a67cb..ad0f447cc4 100644 --- a/util/thread/pool.h +++ b/util/thread/pool.h @@ -15,22 +15,22 @@ class TDuration; struct IObjectInQueue { virtual ~IObjectInQueue() = default; - /** - * Supposed to be implemented by user, to define jobs processed - * in multiple threads. - * - * @param threadSpecificResource is nullptr by default. But if you override + /** + * Supposed to be implemented by user, to define jobs processed + * in multiple threads. + * + * @param threadSpecificResource is nullptr by default. But if you override * IThreadPool::CreateThreadSpecificResource, then result of * IThreadPool::CreateThreadSpecificResource is passed as threadSpecificResource - * parameter. - */ - virtual void Process(void* threadSpecificResource) = 0; + * parameter. + */ + virtual void Process(void* threadSpecificResource) = 0; }; -/** - * Mighty class to add 'Pool' method to derived classes. - * Useful only for creators of new queue classes. - */ +/** + * Mighty class to add 'Pool' method to derived classes. + * Useful only for creators of new queue classes. + */ class TThreadFactoryHolder { public: TThreadFactoryHolder() noexcept; @@ -133,20 +133,20 @@ struct TThreadPoolParams { } }; -/** +/** * A queue processed simultaneously by several threads - */ + */ class IThreadPool: public IThreadFactory, public TNonCopyable { public: using TParams = TThreadPoolParams; ~IThreadPool() override = default; - - /** - * Safe versions of Add*() functions. Behave exactly like as non-safe - * version of Add*(), but use exceptions instead returning false - */ - void SafeAdd(IObjectInQueue* obj); + + /** + * Safe versions of Add*() functions. Behave exactly like as non-safe + * version of Add*(), but use exceptions instead returning false + */ + void SafeAdd(IObjectInQueue* obj); template <class T> void SafeAddFunc(T&& func) { @@ -154,13 +154,13 @@ public: } void SafeAddAndOwn(THolder<IObjectInQueue> obj); - - /** - * Add object to queue, run ojb->Proccess in other threads. - * Obj is not deleted after execution - * @return true of obj is successfully added to queue - * @return false if queue is full or shutting down - */ + + /** + * Add object to queue, run ojb->Proccess in other threads. + * Obj is not deleted after execution + * @return true of obj is successfully added to queue + * @return false if queue is full or shutting down + */ virtual bool Add(IObjectInQueue* obj) Y_WARN_UNUSED_RESULT = 0; template <class T> @@ -174,17 +174,17 @@ public: } bool AddAndOwn(THolder<IObjectInQueue> obj) Y_WARN_UNUSED_RESULT; - virtual void Start(size_t threadCount, size_t queueSizeLimit = 0) = 0; + virtual void Start(size_t threadCount, size_t queueSizeLimit = 0) = 0; /** Wait for completion of all scheduled objects, and then exit */ virtual void Stop() noexcept = 0; - /** Number of tasks currently in queue */ + /** Number of tasks currently in queue */ virtual size_t Size() const noexcept = 0; - -public: - /** - * RAII wrapper for Create/DestroyThreadSpecificResource. + +public: + /** + * RAII wrapper for Create/DestroyThreadSpecificResource. * Useful only for implementers of new IThreadPool queues. - */ + */ class TTsr { public: inline TTsr(IThreadPool* q) @@ -210,12 +210,12 @@ public: void* Data_; }; - /** - * CreateThreadSpecificResource and DestroyThreadSpecificResource + /** + * CreateThreadSpecificResource and DestroyThreadSpecificResource * called from internals of (TAdaptiveThreadPool, TThreadPool, ...) implementation, * not by user of IThreadPool interface. - * Created resource is passed to IObjectInQueue::Proccess function. - */ + * Created resource is passed to IObjectInQueue::Proccess function. + */ virtual void* CreateThreadSpecificResource() { return nullptr; } @@ -230,11 +230,11 @@ private: IThread* DoCreate() override; }; -/** +/** * Single-threaded implementation of IThreadPool, process tasks in same thread when - * added. - * Can be used to remove multithreading. - */ + * added. + * Can be used to remove multithreading. + */ class TFakeThreadPool: public IThreadPool { public: bool Add(IObjectInQueue* pObj) override Y_WARN_UNUSED_RESULT { @@ -263,17 +263,17 @@ protected: TParams Params; }; -/** queue processed by fixed size thread pool */ +/** queue processed by fixed size thread pool */ class TThreadPool: public TThreadPoolBase { public: TThreadPool(const TParams& params = {}); ~TThreadPool() override; bool Add(IObjectInQueue* obj) override Y_WARN_UNUSED_RESULT; - /** - * @param queueSizeLimit means "unlimited" when = 0 - * @param threadCount means "single thread" when = 0 - */ + /** + * @param queueSizeLimit means "unlimited" when = 0 + * @param threadCount means "single thread" when = 0 + */ void Start(size_t threadCount, size_t queueSizeLimit = 0) override; void Stop() noexcept override; size_t Size() const noexcept override; @@ -286,24 +286,24 @@ private: THolder<TImpl> Impl_; }; -/** - * Always create new thread for new task, when all existing threads are busy. - * Maybe dangerous, number of threads is not limited. - */ +/** + * Always create new thread for new task, when all existing threads are busy. + * Maybe dangerous, number of threads is not limited. + */ class TAdaptiveThreadPool: public TThreadPoolBase { public: TAdaptiveThreadPool(const TParams& params = {}); ~TAdaptiveThreadPool() override; - /** - * If working thread waits task too long (more then interval parameter), - * then the thread would be killed. Default value - infinity, all created threads - * waits for new task forever, before Stop. - */ + /** + * If working thread waits task too long (more then interval parameter), + * then the thread would be killed. Default value - infinity, all created threads + * waits for new task forever, before Stop. + */ void SetMaxIdleTime(TDuration interval); bool Add(IObjectInQueue* obj) override Y_WARN_UNUSED_RESULT; - /** @param thrnum, @param maxque are ignored */ + /** @param thrnum, @param maxque are ignored */ void Start(size_t thrnum = 0, size_t maxque = 0) override; void Stop() noexcept override; size_t Size() const noexcept override; @@ -320,10 +320,10 @@ public: ~TSimpleThreadPool() override; bool Add(IObjectInQueue* obj) override Y_WARN_UNUSED_RESULT; - /** + /** * @parameter thrnum. If thrnum is 0, use TAdaptiveThreadPool with small * SetMaxIdleTime interval parameter. if thrnum is not 0, use non-blocking TThreadPool - */ + */ void Start(size_t thrnum, size_t maxque = 0) override; void Stop() noexcept override; size_t Size() const noexcept override; @@ -332,11 +332,11 @@ private: THolder<IThreadPool> Slave_; }; -/** - * Helper to override virtual functions Create/DestroyThreadSpecificResource +/** + * Helper to override virtual functions Create/DestroyThreadSpecificResource * from IThreadPool and implement them using functions with same name from - * pointer to TSlave. - */ + * pointer to TSlave. + */ template <class TQueueType, class TSlave> class TThreadPoolBinder: public TQueueType { public: |