diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
commit | 718c552901d703c502ccbefdfc3c9028d608b947 (patch) | |
tree | 46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /util/generic | |
parent | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff) | |
download | ydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic')
-rw-r--r-- | util/generic/array_ref_ut.cpp | 8 | ||||
-rw-r--r-- | util/generic/flags_ut.cpp | 2 | ||||
-rw-r--r-- | util/generic/fwd.h | 4 | ||||
-rw-r--r-- | util/generic/strbase.h | 82 | ||||
-rw-r--r-- | util/generic/string.cpp | 32 | ||||
-rw-r--r-- | util/generic/string_ut.cpp | 8 | ||||
-rw-r--r-- | util/generic/vector.pxd | 36 | ||||
-rw-r--r-- | util/generic/ylimits.h | 102 | ||||
-rw-r--r-- | util/generic/ylimits_ut.cpp | 30 |
9 files changed, 152 insertions, 152 deletions
diff --git a/util/generic/array_ref_ut.cpp b/util/generic/array_ref_ut.cpp index 4c8eaf7135..1fcae731e7 100644 --- a/util/generic/array_ref_ut.cpp +++ b/util/generic/array_ref_ut.cpp @@ -196,15 +196,15 @@ Y_UNIT_TEST_SUITE(TestArrayRef) { } Y_UNIT_TEST(TestSlice) { - const int a0[] = {1, 2, 3}; - TArrayRef<const int> r0(a0); + const int a0[] = {1, 2, 3}; + TArrayRef<const int> r0(a0); TArrayRef<const int> s0 = r0.Slice(2); UNIT_ASSERT_VALUES_EQUAL(s0.size(), 1); UNIT_ASSERT_VALUES_EQUAL(s0[0], 3); - const int a1[] = {1, 2, 3, 4}; - TArrayRef<const int> r1(a1); + const int a1[] = {1, 2, 3, 4}; + TArrayRef<const int> r1(a1); TArrayRef<const int> s1 = r1.Slice(2, 1); UNIT_ASSERT_VALUES_EQUAL(s1.size(), 1); diff --git a/util/generic/flags_ut.cpp b/util/generic/flags_ut.cpp index 5377c6a058..4ce32e1cc9 100644 --- a/util/generic/flags_ut.cpp +++ b/util/generic/flags_ut.cpp @@ -79,7 +79,7 @@ Y_UNIT_TEST_SUITE(TFlagsTest) { f = ETest1(0); ETest1 ff(0); - ff = 0; + ff = 0; } Y_UNIT_TEST(TestOutput) { diff --git a/util/generic/fwd.h b/util/generic/fwd.h index 5cc2da40e5..08dc6325e0 100644 --- a/util/generic/fwd.h +++ b/util/generic/fwd.h @@ -4,14 +4,14 @@ #include <stlfwd> -template <typename TCharType, typename TTraits = std::char_traits<TCharType>> +template <typename TCharType, typename TTraits = std::char_traits<TCharType>> class TBasicString; using TString = TBasicString<char>; using TUtf16String = TBasicString<wchar16>; using TUtf32String = TBasicString<wchar32>; -template <typename TCharType, typename TTraits = std::char_traits<TCharType>> +template <typename TCharType, typename TTraits = std::char_traits<TCharType>> class TBasicStringBuf; using TStringBuf = TBasicStringBuf<char>; diff --git a/util/generic/strbase.h b/util/generic/strbase.h index ab39fc7537..5cdc89fbbc 100644 --- a/util/generic/strbase.h +++ b/util/generic/strbase.h @@ -1,40 +1,40 @@ #pragma once -// Some of these includes are just a legacy from previous implementation. -// We don't need them here, but removing them is tricky because it breaks all -// kinds of builds downstream -#include "mem_copy.h" -#include "ptr.h" -#include "utility.h" - -#include <util/charset/unidata.h> -#include <util/system/platform.h> +// Some of these includes are just a legacy from previous implementation. +// We don't need them here, but removing them is tricky because it breaks all +// kinds of builds downstream +#include "mem_copy.h" +#include "ptr.h" +#include "utility.h" + +#include <util/charset/unidata.h> +#include <util/system/platform.h> #include <util/system/yassert.h> -#include <contrib/libs/libc_compat/string.h> - -#include <cctype> -#include <cstring> -#include <string> -#include <string_view> - -namespace NStringPrivate { - template <class TCharType> - size_t GetStringLengthWithLimit(const TCharType* s, size_t maxlen) { - Y_ASSERT(s); - size_t i = 0; - for (; i != maxlen && s[i]; ++i) - ; - return i; - } - - inline size_t GetStringLengthWithLimit(const char* s, size_t maxlen) { - Y_ASSERT(s); - return strnlen(s, maxlen); - } -} - -template <typename TDerived, typename TCharType, typename TTraitsType = std::char_traits<TCharType>> +#include <contrib/libs/libc_compat/string.h> + +#include <cctype> +#include <cstring> +#include <string> +#include <string_view> + +namespace NStringPrivate { + template <class TCharType> + size_t GetStringLengthWithLimit(const TCharType* s, size_t maxlen) { + Y_ASSERT(s); + size_t i = 0; + for (; i != maxlen && s[i]; ++i) + ; + return i; + } + + inline size_t GetStringLengthWithLimit(const char* s, size_t maxlen) { + Y_ASSERT(s); + return strnlen(s, maxlen); + } +} + +template <typename TDerived, typename TCharType, typename TTraitsType = std::char_traits<TCharType>> class TStringBase { using TStringView = std::basic_string_view<TCharType>; using TStringViewWithTraits = std::basic_string_view<TCharType, TTraitsType>; @@ -536,18 +536,18 @@ public: return AsStringView().find_last_of(set, pos, n); } - inline size_t find_last_not_of(TCharType c, size_t pos = npos) const noexcept { + inline size_t find_last_not_of(TCharType c, size_t pos = npos) const noexcept { return AsStringView().find_last_not_of(c, pos); - } - + } + inline size_t find_last_not_of(const TStringView set, size_t pos = npos) const noexcept { return find_last_not_of(set.data(), pos, set.length()); - } - - inline size_t find_last_not_of(const TCharType* set, size_t pos, size_t n) const noexcept { + } + + inline size_t find_last_not_of(const TCharType* set, size_t pos, size_t n) const noexcept { return AsStringView().find_last_not_of(set, pos, n); - } - + } + inline size_t copy(TCharType* pc, size_t n, size_t pos) const { if (pos > Len()) { throw std::out_of_range("TStringBase::copy"); diff --git a/util/generic/string.cpp b/util/generic/string.cpp index 3c655f1f66..1dc9a8b445 100644 --- a/util/generic/string.cpp +++ b/util/generic/string.cpp @@ -19,17 +19,17 @@ std::istream& operator>>(std::istream& is, TString& s) { } template <> -bool TBasicString<char, std::char_traits<char>>::to_lower(size_t pos, size_t n) { +bool TBasicString<char, std::char_traits<char>>::to_lower(size_t pos, size_t n) { return Transform([](size_t, char c) { return AsciiToLower(c); }, pos, n); } template <> -bool TBasicString<char, std::char_traits<char>>::to_upper(size_t pos, size_t n) { +bool TBasicString<char, std::char_traits<char>>::to_upper(size_t pos, size_t n) { return Transform([](size_t, char c) { return AsciiToUpper(c); }, pos, n); } template <> -bool TBasicString<char, std::char_traits<char>>::to_title(size_t pos, size_t n) { +bool TBasicString<char, std::char_traits<char>>::to_title(size_t pos, size_t n) { if (n == 0) { return false; } @@ -39,7 +39,7 @@ bool TBasicString<char, std::char_traits<char>>::to_title(size_t pos, size_t n) template <> TUtf16String& -TBasicString<wchar16, std::char_traits<wchar16>>::AppendAscii(const ::TStringBuf& s) { +TBasicString<wchar16, std::char_traits<wchar16>>::AppendAscii(const ::TStringBuf& s) { ReserveAndResize(size() + s.size()); auto dst = begin() + size() - s.size(); @@ -53,7 +53,7 @@ TBasicString<wchar16, std::char_traits<wchar16>>::AppendAscii(const ::TStringBuf template <> TUtf16String& -TBasicString<wchar16, std::char_traits<wchar16>>::AppendUtf8(const ::TStringBuf& s) { +TBasicString<wchar16, std::char_traits<wchar16>>::AppendUtf8(const ::TStringBuf& s) { size_t oldSize = size(); ReserveAndResize(size() + s.size() * 4); size_t written = 0; @@ -67,23 +67,23 @@ TBasicString<wchar16, std::char_traits<wchar16>>::AppendUtf8(const ::TStringBuf& } template <> -bool TBasicString<wchar16, std::char_traits<wchar16>>::to_lower(size_t pos, size_t n) { +bool TBasicString<wchar16, std::char_traits<wchar16>>::to_lower(size_t pos, size_t n) { return ToLower(*this, pos, n); } template <> -bool TBasicString<wchar16, std::char_traits<wchar16>>::to_upper(size_t pos, size_t n) { +bool TBasicString<wchar16, std::char_traits<wchar16>>::to_upper(size_t pos, size_t n) { return ToUpper(*this, pos, n); } template <> -bool TBasicString<wchar16, std::char_traits<wchar16>>::to_title(size_t pos, size_t n) { +bool TBasicString<wchar16, std::char_traits<wchar16>>::to_title(size_t pos, size_t n) { return ToTitle(*this, pos, n); } template <> TUtf32String& -TBasicString<wchar32, std::char_traits<wchar32>>::AppendAscii(const ::TStringBuf& s) { +TBasicString<wchar32, std::char_traits<wchar32>>::AppendAscii(const ::TStringBuf& s) { ReserveAndResize(size() + s.size()); auto dst = begin() + size() - s.size(); @@ -96,8 +96,8 @@ TBasicString<wchar32, std::char_traits<wchar32>>::AppendAscii(const ::TStringBuf } template <> -TBasicString<char, std::char_traits<char>>& -TBasicString<char, std::char_traits<char>>::AppendUtf16(const ::TWtringBuf& s) { +TBasicString<char, std::char_traits<char>>& +TBasicString<char, std::char_traits<char>>::AppendUtf16(const ::TWtringBuf& s) { const size_t oldSize = size(); ReserveAndResize(size() + WideToUTF8BufferSize(s.size())); @@ -111,7 +111,7 @@ TBasicString<char, std::char_traits<char>>::AppendUtf16(const ::TWtringBuf& s) { template <> TUtf32String& -TBasicString<wchar32, std::char_traits<wchar32>>::AppendUtf8(const ::TStringBuf& s) { +TBasicString<wchar32, std::char_traits<wchar32>>::AppendUtf8(const ::TStringBuf& s) { size_t oldSize = size(); ReserveAndResize(size() + s.size() * 4); size_t written = 0; @@ -126,7 +126,7 @@ TBasicString<wchar32, std::char_traits<wchar32>>::AppendUtf8(const ::TStringBuf& template <> TUtf32String& -TBasicString<wchar32, std::char_traits<wchar32>>::AppendUtf16(const ::TWtringBuf& s) { +TBasicString<wchar32, std::char_traits<wchar32>>::AppendUtf16(const ::TWtringBuf& s) { size_t oldSize = size(); ReserveAndResize(size() + s.size() * 2); @@ -141,16 +141,16 @@ TBasicString<wchar32, std::char_traits<wchar32>>::AppendUtf16(const ::TWtringBuf } template <> -bool TBasicString<wchar32, std::char_traits<wchar32>>::to_lower(size_t pos, size_t n) { +bool TBasicString<wchar32, std::char_traits<wchar32>>::to_lower(size_t pos, size_t n) { return ToLower(*this, pos, n); } template <> -bool TBasicString<wchar32, std::char_traits<wchar32>>::to_upper(size_t pos, size_t n) { +bool TBasicString<wchar32, std::char_traits<wchar32>>::to_upper(size_t pos, size_t n) { return ToUpper(*this, pos, n); } template <> -bool TBasicString<wchar32, std::char_traits<wchar32>>::to_title(size_t pos, size_t n) { +bool TBasicString<wchar32, std::char_traits<wchar32>>::to_title(size_t pos, size_t n) { return ToTitle(*this, pos, n); } diff --git a/util/generic/string_ut.cpp b/util/generic/string_ut.cpp index ac82e9091d..4d83037c06 100644 --- a/util/generic/string_ut.cpp +++ b/util/generic/string_ut.cpp @@ -618,7 +618,7 @@ protected: UNIT_ASSERT(test.rfind(*Data.a(), 1) == 0); UNIT_ASSERT(test.rfind(*Data.a(), 0) == 0); } -#endif +#endif void find_last_not_of() { // 21.3.6.6 TStringType s(Data_.one_two_three_one_two_three()); @@ -641,7 +641,7 @@ protected: UNIT_ASSERT(test.find_last_not_of(*Data_.a(), 0) == TStringType::npos); UNIT_ASSERT(test.find_last_not_of(*Data_.b(), 0) == 0); } -#if 0 +#if 0 void replace() { // This test case is for the non template basic_TString::replace method, // this is why we play with the const iterators and reference to guaranty @@ -1135,7 +1135,7 @@ public: UNIT_TEST(rfind); UNIT_TEST(replace); #endif - UNIT_TEST(find_last_not_of); + UNIT_TEST(find_last_not_of); UNIT_TEST_SUITE_END(); }; @@ -1171,7 +1171,7 @@ public: UNIT_TEST(rfind); UNIT_TEST(replace); #endif - UNIT_TEST(find_last_not_of); + UNIT_TEST(find_last_not_of); UNIT_TEST_SUITE_END(); }; diff --git a/util/generic/vector.pxd b/util/generic/vector.pxd index 99dde95d48..aa686bccc6 100644 --- a/util/generic/vector.pxd +++ b/util/generic/vector.pxd @@ -26,11 +26,11 @@ cdef extern from "<util/generic/vector.h>" nogil: bint operator<=(reverse_iterator) bint operator>=(reverse_iterator) - cppclass const_iterator(iterator): - pass + cppclass const_iterator(iterator): + pass - cppclass const_reverse_iterator(reverse_iterator): - pass + cppclass const_reverse_iterator(reverse_iterator): + pass TVector() except + TVector(TVector&) except + @@ -45,39 +45,39 @@ cdef extern from "<util/generic/vector.h>" nogil: bint operator>=(TVector&) void assign(size_t, const T&) except + - void assign[input_iterator](input_iterator, input_iterator) except + + void assign[input_iterator](input_iterator, input_iterator) except + - T& at(size_t) except + + T& at(size_t) except + T& operator[](size_t) T& back() iterator begin() - const_iterator const_begin "begin"() + const_iterator const_begin "begin"() size_t capacity() void clear() except + bint empty() iterator end() - const_iterator const_end "end"() + const_iterator const_end "end"() iterator erase(iterator) except + iterator erase(iterator, iterator) except + T& front() - iterator insert(iterator, const T&) except + - void insert(iterator, size_t, const T&) except + - void insert[Iter](iterator, Iter, Iter) except + + iterator insert(iterator, const T&) except + + void insert(iterator, size_t, const T&) except + + void insert[Iter](iterator, Iter, Iter) except + size_t max_size() void pop_back() except + - void push_back(T&) except + + void push_back(T&) except + void emplace_back(...) except + reverse_iterator rbegin() - const_reverse_iterator const_rbegin "rbegin"() + const_reverse_iterator const_rbegin "rbegin"() reverse_iterator rend() - const_reverse_iterator const_rend "rend"() + const_reverse_iterator const_rend "rend"() void reserve(size_t) except + - void resize(size_t) except + - void resize(size_t, T&) except + + void resize(size_t) except + + void resize(size_t, T&) except + size_t size() void swap(TVector&) except + - - # C++11 methods + + # C++11 methods T* data() void shrink_to_fit() except + diff --git a/util/generic/ylimits.h b/util/generic/ylimits.h index fe42b4dfc0..9bc5f4e162 100644 --- a/util/generic/ylimits.h +++ b/util/generic/ylimits.h @@ -39,54 +39,54 @@ static constexpr ::NPrivate::TMax Max() noexcept { static constexpr ::NPrivate::TMin Min() noexcept { return {}; } - -namespace NPrivate { - template <unsigned long long N> - static constexpr double MaxFloorValue() { - return N; - } - template <unsigned long long N> - static constexpr double MaxCeilValue() { - return N; - } - template <> - constexpr double MaxFloorValue<0x7FFF'FFFF'FFFF'FFFFull>() { - return 9223372036854774784.0; // 0x7FFFFFFFFFFFFC00p0 - } - template <> - constexpr double MaxCeilValue<0x7FFF'FFFF'FFFF'FFFFull>() { - return 9223372036854775808.0; // 0x8000000000000000p0 - } - template <> - constexpr double MaxFloorValue<0xFFFF'FFFF'FFFF'FFFFull>() { - return 18446744073709549568.0; // 0xFFFFFFFFFFFFF800p0 - } - template <> - constexpr double MaxCeilValue<0xFFFF'FFFF'FFFF'FFFFull>() { - return 18446744073709551616.0; // 0x10000000000000000p0 - } -} - -// MaxFloor<T> is the greatest double within the range of T. -// -// 1. If Max<T> is an exact double, MaxFloor<T> = Max<T> = MaxCeil<T>. -// In this case some doubles above MaxFloor<T> cast to T may round -// to Max<T> depending on the rounding mode. -// -// 2. Otherwise Max<T> is between MaxFloor<T> and MaxCeil<T>, and -// MaxFloor<T> is the largest double that does not overflow T. -template <class T> -static constexpr double MaxFloor() noexcept { - return ::NPrivate::MaxFloorValue<Max<T>()>(); -} - -// MaxCeil<T> is the smallest double not lesser than Max<T>. -// -// 1. If Max<T> is an exact double, MaxCeil<T> = Max<T> = MaxFloor<T>. -// -// 2. Otherwise Max<T> is between MaxFloor<T> and MaxCeil<T>, and -// MaxCeil<T> is the smallest double that overflows T. -template <class T> -static constexpr double MaxCeil() noexcept { - return ::NPrivate::MaxCeilValue<Max<T>()>(); -} + +namespace NPrivate { + template <unsigned long long N> + static constexpr double MaxFloorValue() { + return N; + } + template <unsigned long long N> + static constexpr double MaxCeilValue() { + return N; + } + template <> + constexpr double MaxFloorValue<0x7FFF'FFFF'FFFF'FFFFull>() { + return 9223372036854774784.0; // 0x7FFFFFFFFFFFFC00p0 + } + template <> + constexpr double MaxCeilValue<0x7FFF'FFFF'FFFF'FFFFull>() { + return 9223372036854775808.0; // 0x8000000000000000p0 + } + template <> + constexpr double MaxFloorValue<0xFFFF'FFFF'FFFF'FFFFull>() { + return 18446744073709549568.0; // 0xFFFFFFFFFFFFF800p0 + } + template <> + constexpr double MaxCeilValue<0xFFFF'FFFF'FFFF'FFFFull>() { + return 18446744073709551616.0; // 0x10000000000000000p0 + } +} + +// MaxFloor<T> is the greatest double within the range of T. +// +// 1. If Max<T> is an exact double, MaxFloor<T> = Max<T> = MaxCeil<T>. +// In this case some doubles above MaxFloor<T> cast to T may round +// to Max<T> depending on the rounding mode. +// +// 2. Otherwise Max<T> is between MaxFloor<T> and MaxCeil<T>, and +// MaxFloor<T> is the largest double that does not overflow T. +template <class T> +static constexpr double MaxFloor() noexcept { + return ::NPrivate::MaxFloorValue<Max<T>()>(); +} + +// MaxCeil<T> is the smallest double not lesser than Max<T>. +// +// 1. If Max<T> is an exact double, MaxCeil<T> = Max<T> = MaxFloor<T>. +// +// 2. Otherwise Max<T> is between MaxFloor<T> and MaxCeil<T>, and +// MaxCeil<T> is the smallest double that overflows T. +template <class T> +static constexpr double MaxCeil() noexcept { + return ::NPrivate::MaxCeilValue<Max<T>()>(); +} diff --git a/util/generic/ylimits_ut.cpp b/util/generic/ylimits_ut.cpp index f1b3c6858c..029905ed55 100644 --- a/util/generic/ylimits_ut.cpp +++ b/util/generic/ylimits_ut.cpp @@ -10,13 +10,13 @@ class TLimitTest: public TTestBase { UNIT_TEST_SUITE(TLimitTest); UNIT_TEST(TestLimits); UNIT_TEST(TestNan); - UNIT_TEST(TestMaxDouble); + UNIT_TEST(TestMaxDouble); UNIT_TEST_SUITE_END(); protected: void TestLimits(); void TestNan(); - void TestMaxDouble(); + void TestMaxDouble(); }; UNIT_TEST_SUITE_REGISTRATION(TLimitTest); @@ -142,16 +142,16 @@ void TLimitTest::TestNan() { using long_double = long double; UNIT_ASSERT(::TestNan(long_double())); } - -void TLimitTest::TestMaxDouble() { - UNIT_ASSERT_VALUES_EQUAL(MaxCeil<i8>(), 127.0); - UNIT_ASSERT_VALUES_EQUAL(MaxFloor<i8>(), 127.0); - UNIT_ASSERT_VALUES_EQUAL(MaxCeil<ui8>(), 255.0); - UNIT_ASSERT_VALUES_EQUAL(MaxFloor<ui8>(), 255.0); - double d = 1ull << 63; - UNIT_ASSERT_VALUES_EQUAL(MaxCeil<i64>(), d); - UNIT_ASSERT_VALUES_EQUAL(MaxFloor<i64>(), nextafter(d, 0)); - d *= 2; - UNIT_ASSERT_VALUES_EQUAL(MaxCeil<ui64>(), d); - UNIT_ASSERT_VALUES_EQUAL(MaxFloor<ui64>(), nextafter(d, 0)); -} + +void TLimitTest::TestMaxDouble() { + UNIT_ASSERT_VALUES_EQUAL(MaxCeil<i8>(), 127.0); + UNIT_ASSERT_VALUES_EQUAL(MaxFloor<i8>(), 127.0); + UNIT_ASSERT_VALUES_EQUAL(MaxCeil<ui8>(), 255.0); + UNIT_ASSERT_VALUES_EQUAL(MaxFloor<ui8>(), 255.0); + double d = 1ull << 63; + UNIT_ASSERT_VALUES_EQUAL(MaxCeil<i64>(), d); + UNIT_ASSERT_VALUES_EQUAL(MaxFloor<i64>(), nextafter(d, 0)); + d *= 2; + UNIT_ASSERT_VALUES_EQUAL(MaxCeil<ui64>(), d); + UNIT_ASSERT_VALUES_EQUAL(MaxFloor<ui64>(), nextafter(d, 0)); +} |