diff options
author | Mikhail Borisov <borisov.mikhail@gmail.com> | 2022-02-10 16:45:40 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:40 +0300 |
commit | 5d50718e66d9c037dc587a0211110b7d25a66185 (patch) | |
tree | e98df59de24d2ef7c77baed9f41e4875a2fef972 /util | |
parent | a6a92afe03e02795227d2641b49819b687f088f8 (diff) | |
download | ydb-5d50718e66d9c037dc587a0211110b7d25a66185.tar.gz |
Restoring authorship annotation for Mikhail Borisov <borisov.mikhail@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'util')
57 files changed, 1556 insertions, 1556 deletions
diff --git a/util/README.md b/util/README.md index 22d6f356d4..496efa633c 100644 --- a/util/README.md +++ b/util/README.md @@ -55,16 +55,16 @@ Certain exceptions apply. The following trivial changes do not need to be review * renaming of an internal variable to match the styleguide. Whenever a breaking change happens to accidentally land into trunk, reverting it does not need to be reviewed. - -## Stale/abandoned review request policy - -Sometimes review requests are neither merged nor discarded, and stay in review request queue forever. -To limit the incoming review request queue size, util reviewers follow these rules: - -- A review request is considered stale if it is not updated by its author for at least 3 months, or if its author has left Yandex. -- A stale review request may be marked as discarded by util reviewers. - -Review requests discarded as stale may be reopened or resubmitted by any committer willing to push them to completion. - -**Note:** It's an author's duty to push the review request to completion. -If util reviewers stop responding to updates, they should be politely pinged via appropriate means of communication. + +## Stale/abandoned review request policy + +Sometimes review requests are neither merged nor discarded, and stay in review request queue forever. +To limit the incoming review request queue size, util reviewers follow these rules: + +- A review request is considered stale if it is not updated by its author for at least 3 months, or if its author has left Yandex. +- A stale review request may be marked as discarded by util reviewers. + +Review requests discarded as stale may be reopened or resubmitted by any committer willing to push them to completion. + +**Note:** It's an author's duty to push the review request to completion. +If util reviewers stop responding to updates, they should be politely pinged via appropriate means of communication. diff --git a/util/a.yaml b/util/a.yaml index c9c8f50a24..e658783472 100644 --- a/util/a.yaml +++ b/util/a.yaml @@ -1,38 +1,38 @@ -service: cpputil -title: "Yandex C++ util base library" -arcanum: - auto_merge: - requirements: - - system: arcanum - type: comment_issues_closed -ci: - secret: sec-01fgmqmem182tz4zjsmgd6nxxw - runtime: - sandbox-owner: CPPUTIL - autocheck: - fast-targets: - - util - actions: - util-style-test: - flow: util-style-test - triggers: - - on: pr - filters: - - sub-paths: [ '**.h', '**.cpp', '**.c' ] - - on: commit - filters: - - sub-paths: [ '**.h', '**.cpp', '**.c' ] - - discovery: graph - abs-paths: [ 'util/tests/style/ya.make' ] - flows: - util-style-test: - title: "C++ style" - jobs: - yamake-util-tests-style: - title: "Ya Make: util/tests/style" - task: common/arcadia/ya_make - input: - targets: util/tests/style - test: true - keep_on: true - check_return_code: true +service: cpputil +title: "Yandex C++ util base library" +arcanum: + auto_merge: + requirements: + - system: arcanum + type: comment_issues_closed +ci: + secret: sec-01fgmqmem182tz4zjsmgd6nxxw + runtime: + sandbox-owner: CPPUTIL + autocheck: + fast-targets: + - util + actions: + util-style-test: + flow: util-style-test + triggers: + - on: pr + filters: + - sub-paths: [ '**.h', '**.cpp', '**.c' ] + - on: commit + filters: + - sub-paths: [ '**.h', '**.cpp', '**.c' ] + - discovery: graph + abs-paths: [ 'util/tests/style/ya.make' ] + flows: + util-style-test: + title: "C++ style" + jobs: + yamake-util-tests-style: + title: "Ya Make: util/tests/style" + task: common/arcadia/ya_make + input: + targets: util/tests/style + test: true + keep_on: true + check_return_code: true diff --git a/util/digest/multi_ut.pyx b/util/digest/multi_ut.pyx index 6b032f5f86..26faa0069b 100644 --- a/util/digest/multi_ut.pyx +++ b/util/digest/multi_ut.pyx @@ -8,11 +8,11 @@ import unittest class TestMultiHash(unittest.TestCase): def test_str_int(self): - value = MultiHash(TString(b"1234567"), 123) + value = MultiHash(TString(b"1234567"), 123) self.assertEquals(value, 17038203285960021630) def test_int_str(self): - value = MultiHash(123, TString(b"1234567")) + value = MultiHash(123, TString(b"1234567")) self.assertEquals(value, 9973288649881090712) def test_collision(self): diff --git a/util/digest/murmur.cpp b/util/digest/murmur.cpp index 84df22304d..b041d3e5f2 100644 --- a/util/digest/murmur.cpp +++ b/util/digest/murmur.cpp @@ -2,130 +2,130 @@ #include <util/system/unaligned_mem.h> -namespace NMurmurPrivate { - //----------------------------------------------------------------------------- - // MurmurHash2, by Austin Appleby - - // Note - This code makes a few assumptions about how your machine behaves - - - // 1. We can read a 4-byte value from any address without crashing - // 2. sizeof(int) == 4 - - // And it has a few limitations - - - // 1. It will not work incrementally. - // 2. It will not produce the same results on little-endian and big-endian - // machines. - - Y_NO_INLINE ui32 MurmurHash32(const void* key, size_t len, ui32 seed) noexcept { - const ui32 m = 0x5bd1e995; - const int r = 24; - ui32 h = ui32(seed ^ len); - - TUnalignedMemoryIterator<ui32> iter(key, len); - - while (!iter.AtEnd()) { - ui32 k = iter.Next(); - - k *= m; - k ^= k >> r; - k *= m; - - h *= m; - h ^= k; - } - - const unsigned char* data = iter.Last(); - - switch (iter.Left()) { - case 3: - h ^= data[2] << 16; +namespace NMurmurPrivate { + //----------------------------------------------------------------------------- + // MurmurHash2, by Austin Appleby + + // Note - This code makes a few assumptions about how your machine behaves - + + // 1. We can read a 4-byte value from any address without crashing + // 2. sizeof(int) == 4 + + // And it has a few limitations - + + // 1. It will not work incrementally. + // 2. It will not produce the same results on little-endian and big-endian + // machines. + + Y_NO_INLINE ui32 MurmurHash32(const void* key, size_t len, ui32 seed) noexcept { + const ui32 m = 0x5bd1e995; + const int r = 24; + ui32 h = ui32(seed ^ len); + + TUnalignedMemoryIterator<ui32> iter(key, len); + + while (!iter.AtEnd()) { + ui32 k = iter.Next(); + + k *= m; + k ^= k >> r; + k *= m; + + h *= m; + h ^= k; + } + + const unsigned char* data = iter.Last(); + + switch (iter.Left()) { + case 3: + h ^= data[2] << 16; [[fallthrough]]; - - case 2: - h ^= data[1] << 8; + + case 2: + h ^= data[1] << 8; [[fallthrough]]; - - case 1: - h ^= data[0]; - h *= m; + + case 1: + h ^= data[0]; + h *= m; break; - }; - - h ^= h >> 13; - h *= m; - h ^= h >> 15; - - return h; - } - - //----------------------------------------------------------------------------- - // MurmurHash2, 64-bit versions, by Austin Appleby - - // The same caveats as 32-bit MurmurHash2 apply here - beware of alignment - // and endian-ness issues if used across multiple platforms. - - // 64-bit hash for 64-bit platforms - - Y_NO_INLINE ui64 MurmurHash64(const void* key, size_t len, ui64 seed) noexcept { - const ui64 m = ULL(0xc6a4a7935bd1e995); - const int r = 47; - - ui64 h = seed ^ (len * m); - TUnalignedMemoryIterator<ui64> iter(key, len); - - while (!iter.AtEnd()) { - ui64 k = iter.Next(); - - k *= m; - k ^= k >> r; - k *= m; - - h ^= k; - h *= m; - } - - const unsigned char* data2 = iter.Last(); - - switch (iter.Left()) { - case 7: - h ^= ui64(data2[6]) << 48; + }; + + h ^= h >> 13; + h *= m; + h ^= h >> 15; + + return h; + } + + //----------------------------------------------------------------------------- + // MurmurHash2, 64-bit versions, by Austin Appleby + + // The same caveats as 32-bit MurmurHash2 apply here - beware of alignment + // and endian-ness issues if used across multiple platforms. + + // 64-bit hash for 64-bit platforms + + Y_NO_INLINE ui64 MurmurHash64(const void* key, size_t len, ui64 seed) noexcept { + const ui64 m = ULL(0xc6a4a7935bd1e995); + const int r = 47; + + ui64 h = seed ^ (len * m); + TUnalignedMemoryIterator<ui64> iter(key, len); + + while (!iter.AtEnd()) { + ui64 k = iter.Next(); + + k *= m; + k ^= k >> r; + k *= m; + + h ^= k; + h *= m; + } + + const unsigned char* data2 = iter.Last(); + + switch (iter.Left()) { + case 7: + h ^= ui64(data2[6]) << 48; [[fallthrough]]; - - case 6: - h ^= ui64(data2[5]) << 40; + + case 6: + h ^= ui64(data2[5]) << 40; [[fallthrough]]; - - case 5: - h ^= ui64(data2[4]) << 32; + + case 5: + h ^= ui64(data2[4]) << 32; [[fallthrough]]; - - case 4: - h ^= ui64(data2[3]) << 24; + + case 4: + h ^= ui64(data2[3]) << 24; [[fallthrough]]; - - case 3: - h ^= ui64(data2[2]) << 16; + + case 3: + h ^= ui64(data2[2]) << 16; [[fallthrough]]; - - case 2: - h ^= ui64(data2[1]) << 8; + + case 2: + h ^= ui64(data2[1]) << 8; [[fallthrough]]; - - case 1: - h ^= ui64(data2[0]); - h *= m; + + case 1: + h ^= ui64(data2[0]); + h *= m; break; - } - - h ^= h >> r; - h *= m; - h ^= h >> r; - - return h; - } -} - + } + + h ^= h >> r; + h *= m; + h ^= h >> r; + + return h; + } +} + size_t MurmurHashSizeT(const char* buf, size_t len) noexcept { return MurmurHash<size_t>(buf, len); } diff --git a/util/digest/murmur.h b/util/digest/murmur.h index eec9bcc171..6b519b430a 100644 --- a/util/digest/murmur.h +++ b/util/digest/murmur.h @@ -3,35 +3,35 @@ #include <util/system/defaults.h> #include <util/generic/array_ref.h> -/* - * murmur2 from http://murmurhash.googlepages.com/ - * +/* + * murmur2 from http://murmurhash.googlepages.com/ + * */ -namespace NMurmurPrivate { +namespace NMurmurPrivate { Y_PURE_FUNCTION ui32 MurmurHash32(const void* key, size_t len, ui32 seed) noexcept; Y_PURE_FUNCTION ui64 MurmurHash64(const void* key, size_t len, ui64 seed) noexcept; - template <unsigned N> - struct TMurHelper; - -#define DEF_MUR(t) \ - template <> \ - struct TMurHelper<t> { \ - static inline ui##t MurmurHash(const void* buf, size_t len, ui##t init) noexcept { \ - return MurmurHash##t(buf, len, init); \ - } \ - }; - - DEF_MUR(32) - DEF_MUR(64) - -#undef DEF_MUR + template <unsigned N> + struct TMurHelper; + +#define DEF_MUR(t) \ + template <> \ + struct TMurHelper<t> { \ + static inline ui##t MurmurHash(const void* buf, size_t len, ui##t init) noexcept { \ + return MurmurHash##t(buf, len, init); \ + } \ + }; + + DEF_MUR(32) + DEF_MUR(64) + +#undef DEF_MUR } template <class T> -static inline T MurmurHash(const void* buf, size_t len, T init) noexcept { - return (T)NMurmurPrivate::TMurHelper<8 * sizeof(T)>::MurmurHash(buf, len, init); +static inline T MurmurHash(const void* buf, size_t len, T init) noexcept { + return (T)NMurmurPrivate::TMurHelper<8 * sizeof(T)>::MurmurHash(buf, len, init); } template <class T> diff --git a/util/folder/path_ut.cpp b/util/folder/path_ut.cpp index e170817368..e6a3451016 100644 --- a/util/folder/path_ut.cpp +++ b/util/folder/path_ut.cpp @@ -65,7 +65,7 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { ++checksCounter; current = current.Parent(); } - UNIT_ASSERT_VALUES_EQUAL(checksCounter, 6); + UNIT_ASSERT_VALUES_EQUAL(checksCounter, 6); path.MkDirs(); UNIT_ASSERT(path.Exists()); @@ -88,32 +88,32 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { Y_UNIT_TEST(Parent) { #ifdef _win_ - UNIT_ASSERT_VALUES_EQUAL(TFsPath("\\etc/passwd").Parent(), TFsPath("\\etc")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("\\etc").Parent(), TFsPath("\\")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("\\").Parent(), TFsPath("\\")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("\\etc/passwd").Parent(), TFsPath("\\etc")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("\\etc").Parent(), TFsPath("\\")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("\\").Parent(), TFsPath("\\")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("etc\\passwd").Parent(), TFsPath("etc")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("etc").Parent(), TFsPath(".")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath(".\\etc").Parent(), TFsPath(".")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("etc\\passwd").Parent(), TFsPath("etc")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("etc").Parent(), TFsPath(".")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath(".\\etc").Parent(), TFsPath(".")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("C:\\etc/passwd").Parent(), TFsPath("C:\\etc")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("C:\\etc").Parent(), TFsPath("C:\\")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("C:\\").Parent(), TFsPath("C:\\")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("C:\\etc/passwd").Parent(), TFsPath("C:\\etc")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("C:\\etc").Parent(), TFsPath("C:\\")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("C:\\").Parent(), TFsPath("C:\\")); #else - UNIT_ASSERT_VALUES_EQUAL(TFsPath("/etc/passwd").Parent(), TFsPath("/etc")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("/etc").Parent(), TFsPath("/")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("/").Parent(), TFsPath("/")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("/etc/passwd").Parent(), TFsPath("/etc")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("/etc").Parent(), TFsPath("/")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("/").Parent(), TFsPath("/")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("etc/passwd").Parent(), TFsPath("etc")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("etc").Parent(), TFsPath(".")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("./etc").Parent(), TFsPath(".")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("etc/passwd").Parent(), TFsPath("etc")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("etc").Parent(), TFsPath(".")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("./etc").Parent(), TFsPath(".")); #endif #if 0 - UNIT_ASSERT_VALUES_EQUAL(TFsPath("./etc/passwd").Parent(), TFsPath("./etc")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("./").Parent(), TFsPath("..")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath(".").Parent(), TFsPath("..")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("..").Parent(), TFsPath("../..")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("./etc/passwd").Parent(), TFsPath("./etc")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("./").Parent(), TFsPath("..")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath(".").Parent(), TFsPath("..")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("..").Parent(), TFsPath("../..")); #endif } @@ -131,11 +131,11 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { Y_UNIT_TEST(GetExtension) { TTestDirectory d("GetExtension"); - UNIT_ASSERT_VALUES_EQUAL("", d.Child("a").GetExtension()); - UNIT_ASSERT_VALUES_EQUAL("", d.Child(".a").GetExtension()); - UNIT_ASSERT_VALUES_EQUAL("", d.Child("zlib").GetExtension()); - UNIT_ASSERT_VALUES_EQUAL("zlib", d.Child("file.zlib").GetExtension()); - UNIT_ASSERT_VALUES_EQUAL("zlib", d.Child("file.ylib.zlib").GetExtension()); + UNIT_ASSERT_VALUES_EQUAL("", d.Child("a").GetExtension()); + UNIT_ASSERT_VALUES_EQUAL("", d.Child(".a").GetExtension()); + UNIT_ASSERT_VALUES_EQUAL("", d.Child("zlib").GetExtension()); + UNIT_ASSERT_VALUES_EQUAL("zlib", d.Child("file.zlib").GetExtension()); + UNIT_ASSERT_VALUES_EQUAL("zlib", d.Child("file.ylib.zlib").GetExtension()); } Y_UNIT_TEST(TestRename) { @@ -183,21 +183,21 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { TFsPath target2 = td.Child("target2"); target2.Touch(); UNIT_ASSERT(NFs::SymLink(target1.RealPath(), link.GetPath())); - UNIT_ASSERT_VALUES_EQUAL(link.RealPath(), target1.RealPath()); + UNIT_ASSERT_VALUES_EQUAL(link.RealPath(), target1.RealPath()); UNIT_ASSERT(NFs::Remove(link.GetPath())); UNIT_ASSERT(NFs::SymLink(target2.RealPath(), link.GetPath())); - UNIT_ASSERT_VALUES_EQUAL(link.RealPath(), target2.RealPath()); // must not cache old value + UNIT_ASSERT_VALUES_EQUAL(link.RealPath(), target2.RealPath()); // must not cache old value } #endif Y_UNIT_TEST(TestSlashesAndBasename) { TFsPath p("/db/BASE/primus121-025-1380131338//"); - UNIT_ASSERT_VALUES_EQUAL(p.Basename(), TString("primus121-025-1380131338")); + UNIT_ASSERT_VALUES_EQUAL(p.Basename(), TString("primus121-025-1380131338")); TFsPath testP = p / "test"; #ifdef _win_ - UNIT_ASSERT_VALUES_EQUAL(testP.GetPath(), "\\db\\BASE\\primus121-025-1380131338\\test"); + UNIT_ASSERT_VALUES_EQUAL(testP.GetPath(), "\\db\\BASE\\primus121-025-1380131338\\test"); #else - UNIT_ASSERT_VALUES_EQUAL(testP.GetPath(), "/db/BASE/primus121-025-1380131338/test"); + UNIT_ASSERT_VALUES_EQUAL(testP.GetPath(), "/db/BASE/primus121-025-1380131338/test"); #endif } @@ -205,11 +205,11 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { TFsPath p("\\db\\BASE\\primus121-025-1380131338\\\\"); TFsPath testP = p / "test"; #ifdef _win_ - UNIT_ASSERT_VALUES_EQUAL(p.Basename(), TString("primus121-025-1380131338")); - UNIT_ASSERT_VALUES_EQUAL(testP.GetPath(), "\\db\\BASE\\primus121-025-1380131338\\test"); + UNIT_ASSERT_VALUES_EQUAL(p.Basename(), TString("primus121-025-1380131338")); + UNIT_ASSERT_VALUES_EQUAL(testP.GetPath(), "\\db\\BASE\\primus121-025-1380131338\\test"); #else - UNIT_ASSERT_VALUES_EQUAL(p.Basename(), TString("\\db\\BASE\\primus121-025-1380131338\\\\")); - UNIT_ASSERT_VALUES_EQUAL(testP.GetPath(), "\\db\\BASE\\primus121-025-1380131338\\\\/test"); + UNIT_ASSERT_VALUES_EQUAL(p.Basename(), TString("\\db\\BASE\\primus121-025-1380131338\\\\")); + UNIT_ASSERT_VALUES_EQUAL(testP.GetPath(), "\\db\\BASE\\primus121-025-1380131338\\\\/test"); #endif } @@ -217,11 +217,11 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { TFsPath p("C:\\db\\BASE\\primus121-025-1380131338\\\\"); TFsPath testP = p / "test"; #ifdef _win_ - UNIT_ASSERT_VALUES_EQUAL(p.Basename(), TString("primus121-025-1380131338")); - UNIT_ASSERT_VALUES_EQUAL(testP.GetPath(), "C:\\db\\BASE\\primus121-025-1380131338\\test"); + UNIT_ASSERT_VALUES_EQUAL(p.Basename(), TString("primus121-025-1380131338")); + UNIT_ASSERT_VALUES_EQUAL(testP.GetPath(), "C:\\db\\BASE\\primus121-025-1380131338\\test"); #else - UNIT_ASSERT_VALUES_EQUAL(p.Basename(), TString("C:\\db\\BASE\\primus121-025-1380131338\\\\")); - UNIT_ASSERT_VALUES_EQUAL(testP.GetPath(), "C:\\db\\BASE\\primus121-025-1380131338\\\\/test"); + UNIT_ASSERT_VALUES_EQUAL(p.Basename(), TString("C:\\db\\BASE\\primus121-025-1380131338\\\\")); + UNIT_ASSERT_VALUES_EQUAL(testP.GetPath(), "C:\\db\\BASE\\primus121-025-1380131338\\\\/test"); #endif } @@ -245,7 +245,7 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { expected.push_back("c"); expected.push_back("d"); - UNIT_ASSERT_VALUES_EQUAL(expected, children); + UNIT_ASSERT_VALUES_EQUAL(expected, children); } #ifdef _unix_ @@ -264,7 +264,7 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { #endif Y_UNIT_TEST(Cwd) { - UNIT_ASSERT_VALUES_EQUAL(TFsPath::Cwd().RealPath(), TFsPath(".").RealPath()); + UNIT_ASSERT_VALUES_EQUAL(TFsPath::Cwd().RealPath(), TFsPath(".").RealPath()); } Y_UNIT_TEST(TestSubpathOf) { @@ -335,55 +335,55 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { } Y_UNIT_TEST(TestRelativePath) { - UNIT_ASSERT_VALUES_EQUAL(TFsPath("/a/b/c/d").RelativePath(TFsPath("/a/b")), TFsPath("c/d")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("/a/b/c/d").RelativePath(TFsPath("/a/b/e/f")), TFsPath("../../c/d")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("/").RelativePath(TFsPath("/")), TFsPath()); - UNIT_ASSERT_VALUES_EQUAL(TFsPath(".").RelativePath(TFsPath(".")), TFsPath()); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("/a/c").RelativePath(TFsPath("/a/b/../c")), TFsPath()); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("a/.././b").RelativePath(TFsPath("b/c")), TFsPath("..")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("/a/b/c/d").RelativePath(TFsPath("/a/b")), TFsPath("c/d")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("/a/b/c/d").RelativePath(TFsPath("/a/b/e/f")), TFsPath("../../c/d")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("/").RelativePath(TFsPath("/")), TFsPath()); + UNIT_ASSERT_VALUES_EQUAL(TFsPath(".").RelativePath(TFsPath(".")), TFsPath()); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("/a/c").RelativePath(TFsPath("/a/b/../c")), TFsPath()); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("a/.././b").RelativePath(TFsPath("b/c")), TFsPath("..")); UNIT_ASSERT_EXCEPTION(TFsPath("a/b/c").RelativePath(TFsPath("d/e")), TIoException); } Y_UNIT_TEST(TestUndefined) { - UNIT_ASSERT_VALUES_EQUAL(TFsPath(), TFsPath("")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath(), TFsPath().Fix()); + UNIT_ASSERT_VALUES_EQUAL(TFsPath(), TFsPath("")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath(), TFsPath().Fix()); - UNIT_ASSERT_VALUES_EQUAL(TFsPath() / TFsPath(), TFsPath()); + UNIT_ASSERT_VALUES_EQUAL(TFsPath() / TFsPath(), TFsPath()); #ifdef _win_ - UNIT_ASSERT_VALUES_EQUAL(TFsPath("a\\b"), TFsPath() / TString("a\\b")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("a\\b"), "a\\b" / TFsPath()); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("\\a\\b"), TFsPath() / "\\a\\b"); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("\\a\\b"), "\\a\\b" / TFsPath()); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("a\\b"), TFsPath() / TString("a\\b")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("a\\b"), "a\\b" / TFsPath()); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("\\a\\b"), TFsPath() / "\\a\\b"); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("\\a\\b"), "\\a\\b" / TFsPath()); #else - UNIT_ASSERT_VALUES_EQUAL(TFsPath("a/b"), TFsPath() / TString("a/b")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("a/b"), "a/b" / TFsPath()); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("/a/b"), TFsPath() / "/a/b"); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("/a/b"), "/a/b" / TFsPath()); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("a/b"), TFsPath() / TString("a/b")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("a/b"), "a/b" / TFsPath()); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("/a/b"), TFsPath() / "/a/b"); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("/a/b"), "/a/b" / TFsPath()); #endif - UNIT_ASSERT_VALUES_EQUAL(TFsPath("."), TFsPath() / "."); - UNIT_ASSERT_VALUES_EQUAL(TFsPath("."), "." / TFsPath()); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("."), TFsPath() / "."); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("."), "." / TFsPath()); UNIT_ASSERT(TFsPath().PathSplit().empty()); UNIT_ASSERT(!TFsPath().PathSplit().IsAbsolute); UNIT_ASSERT(TFsPath().IsRelative()); // undefined path is relative - UNIT_ASSERT_VALUES_EQUAL(TFsPath().GetPath(), ""); - UNIT_ASSERT_VALUES_EQUAL(TFsPath().GetName(), ""); - UNIT_ASSERT_VALUES_EQUAL(TFsPath().GetExtension(), ""); + UNIT_ASSERT_VALUES_EQUAL(TFsPath().GetPath(), ""); + UNIT_ASSERT_VALUES_EQUAL(TFsPath().GetName(), ""); + UNIT_ASSERT_VALUES_EQUAL(TFsPath().GetExtension(), ""); - UNIT_ASSERT_VALUES_EQUAL(TFsPath().Parent(), TFsPath()); - UNIT_ASSERT_VALUES_EQUAL(TFsPath().Child("a"), TFsPath("a")); - UNIT_ASSERT_VALUES_EQUAL(TFsPath().Basename(), ""); - UNIT_ASSERT_VALUES_EQUAL(TFsPath().Dirname(), ""); + UNIT_ASSERT_VALUES_EQUAL(TFsPath().Parent(), TFsPath()); + UNIT_ASSERT_VALUES_EQUAL(TFsPath().Child("a"), TFsPath("a")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath().Basename(), ""); + UNIT_ASSERT_VALUES_EQUAL(TFsPath().Dirname(), ""); UNIT_ASSERT(!TFsPath().IsSubpathOf("a/b")); UNIT_ASSERT(TFsPath().IsContainerOf("a/b")); UNIT_ASSERT(!TFsPath().IsContainerOf("/a/b")); #ifdef _win_ - UNIT_ASSERT_VALUES_EQUAL(TFsPath("a\\b").RelativeTo(TFsPath()), TFsPath("a\\b")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("a\\b").RelativeTo(TFsPath()), TFsPath("a\\b")); #else - UNIT_ASSERT_VALUES_EQUAL(TFsPath("a/b").RelativeTo(TFsPath()), TFsPath("a/b")); + UNIT_ASSERT_VALUES_EQUAL(TFsPath("a/b").RelativeTo(TFsPath()), TFsPath("a/b")); #endif UNIT_ASSERT(!TFsPath().Exists()); diff --git a/util/generic/algorithm.h b/util/generic/algorithm.h index 821ba709d0..badfb88993 100644 --- a/util/generic/algorithm.h +++ b/util/generic/algorithm.h @@ -73,16 +73,16 @@ static inline void StableSort(T f, T l, C c) { std::stable_sort(f, l, c); } -template <class TContainer> -static inline void StableSort(TContainer& container) { - StableSort(container.begin(), container.end()); -} - -template <class TContainer, typename TCompare> -static inline void StableSort(TContainer& container, TCompare compare) { - StableSort(container.begin(), container.end(), compare); -} - +template <class TContainer> +static inline void StableSort(TContainer& container) { + StableSort(container.begin(), container.end()); +} + +template <class TContainer, typename TCompare> +static inline void StableSort(TContainer& container, TCompare compare) { + StableSort(container.begin(), container.end(), compare); +} + template <class TIterator, typename TGetKey> static inline void StableSortBy(TIterator begin, TIterator end, const TGetKey& getKey) { StableSort(begin, end, [&](auto&& left, auto&& right) { return getKey(left) < getKey(right); }); @@ -278,11 +278,11 @@ static inline I LowerBound(I f, I l, const T& v, C c) { return std::lower_bound(f, l, v, c); } -template <class I, class T, class TGetKey> -static inline I LowerBoundBy(I f, I l, const T& v, const TGetKey& getKey) { - return std::lower_bound(f, l, v, [&](auto&& left, auto&& right) { return getKey(left) < right; }); -} - +template <class I, class T, class TGetKey> +static inline I LowerBoundBy(I f, I l, const T& v, const TGetKey& getKey) { + return std::lower_bound(f, l, v, [&](auto&& left, auto&& right) { return getKey(left) < right; }); +} + template <class I, class T> static inline I UpperBound(I f, I l, const T& v) { return std::upper_bound(f, l, v); @@ -293,11 +293,11 @@ static inline I UpperBound(I f, I l, const T& v, C c) { return std::upper_bound(f, l, v, c); } -template <class I, class T, class TGetKey> -static inline I UpperBoundBy(I f, I l, const T& v, const TGetKey& getKey) { - return std::upper_bound(f, l, v, [&](auto&& left, auto&& right) { return left < getKey(right); }); -} - +template <class I, class T, class TGetKey> +static inline I UpperBoundBy(I f, I l, const T& v, const TGetKey& getKey) { + return std::upper_bound(f, l, v, [&](auto&& left, auto&& right) { return left < getKey(right); }); +} + template <class T> static inline T Unique(T f, T l) { return std::unique(f, l); diff --git a/util/generic/algorithm_ut.cpp b/util/generic/algorithm_ut.cpp index 58a3b56956..8d732fcc0c 100644 --- a/util/generic/algorithm_ut.cpp +++ b/util/generic/algorithm_ut.cpp @@ -446,61 +446,61 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } Y_UNIT_TEST(SortTestTwoIterators) { - TVector<int> collection = {10, 2, 7}; - Sort(collection.begin(), collection.end()); - TVector<int> expected = {2, 7, 10}; - UNIT_ASSERT_VALUES_EQUAL(collection, expected); - } - + TVector<int> collection = {10, 2, 7}; + Sort(collection.begin(), collection.end()); + TVector<int> expected = {2, 7, 10}; + UNIT_ASSERT_VALUES_EQUAL(collection, expected); + } + Y_UNIT_TEST(SortTestTwoIteratorsAndComparator) { - TVector<int> collection = {10, 2, 7}; - Sort(collection.begin(), collection.end(), [](int l, int r) { return l > r; }); - TVector<int> expected = {10, 7, 2}; - UNIT_ASSERT_VALUES_EQUAL(collection, expected); - } - + TVector<int> collection = {10, 2, 7}; + Sort(collection.begin(), collection.end(), [](int l, int r) { return l > r; }); + TVector<int> expected = {10, 7, 2}; + UNIT_ASSERT_VALUES_EQUAL(collection, expected); + } + Y_UNIT_TEST(SortTestContainer) { - TVector<int> collection = {10, 2, 7}; - Sort(collection); - TVector<int> expected = {2, 7, 10}; - UNIT_ASSERT_VALUES_EQUAL(collection, expected); - } - + TVector<int> collection = {10, 2, 7}; + Sort(collection); + TVector<int> expected = {2, 7, 10}; + UNIT_ASSERT_VALUES_EQUAL(collection, expected); + } + Y_UNIT_TEST(SortTestContainerAndComparator) { - TVector<int> collection = {10, 2, 7}; - Sort(collection, [](int l, int r) { return l > r; }); - TVector<int> expected = {10, 7, 2}; - UNIT_ASSERT_VALUES_EQUAL(collection, expected); - } - + TVector<int> collection = {10, 2, 7}; + Sort(collection, [](int l, int r) { return l > r; }); + TVector<int> expected = {10, 7, 2}; + UNIT_ASSERT_VALUES_EQUAL(collection, expected); + } + Y_UNIT_TEST(StableSortTestTwoIterators) { - TVector<int> collection = {10, 2, 7}; - StableSort(collection.begin(), collection.end()); - TVector<int> expected = {2, 7, 10}; - UNIT_ASSERT_VALUES_EQUAL(collection, expected); - } - + TVector<int> collection = {10, 2, 7}; + StableSort(collection.begin(), collection.end()); + TVector<int> expected = {2, 7, 10}; + UNIT_ASSERT_VALUES_EQUAL(collection, expected); + } + Y_UNIT_TEST(StableSortTestTwoIteratorsAndComparator) { - TVector<int> collection = {404, 101, 106, 203, 102, 205, 401}; - StableSort(collection.begin(), collection.end(), [](int l, int r) { return (l / 100) < (r / 100); }); - TVector<int> expected = {101, 106, 102, 203, 205, 404, 401}; - UNIT_ASSERT_VALUES_EQUAL(collection, expected); - } - + TVector<int> collection = {404, 101, 106, 203, 102, 205, 401}; + StableSort(collection.begin(), collection.end(), [](int l, int r) { return (l / 100) < (r / 100); }); + TVector<int> expected = {101, 106, 102, 203, 205, 404, 401}; + UNIT_ASSERT_VALUES_EQUAL(collection, expected); + } + Y_UNIT_TEST(StableSortTestContainer) { - TVector<int> collection = {10, 2, 7}; - StableSort(collection); - TVector<int> expected = {2, 7, 10}; - UNIT_ASSERT_VALUES_EQUAL(collection, expected); - } - + TVector<int> collection = {10, 2, 7}; + StableSort(collection); + TVector<int> expected = {2, 7, 10}; + UNIT_ASSERT_VALUES_EQUAL(collection, expected); + } + Y_UNIT_TEST(StableSortTestContainerAndComparator) { - TVector<int> collection = {404, 101, 106, 203, 102, 205, 401}; - StableSort(collection, [](int l, int r) { return (l / 100) < (r / 100); }); - TVector<int> expected = {101, 106, 102, 203, 205, 404, 401}; - UNIT_ASSERT_VALUES_EQUAL(collection, expected); - } - + TVector<int> collection = {404, 101, 106, 203, 102, 205, 401}; + StableSort(collection, [](int l, int r) { return (l / 100) < (r / 100); }); + TVector<int> expected = {101, 106, 102, 203, 205, 404, 401}; + UNIT_ASSERT_VALUES_EQUAL(collection, expected); + } + Y_UNIT_TEST(SortByTest) { TVector<int> collection = {10, 2, 7}; SortBy(collection, [](int x) { return -x; }); @@ -796,45 +796,45 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { auto i = FindIf(range, [](auto) { return false; }); Y_UNUSED(i); } - + Y_UNIT_TEST(TestLowerBoundBy) { using TIntPairs = TVector<std::pair<i32, i32>>; - - auto data = TIntPairs{{1, 5}, {3, 2}, {3, 4}, {8, 0}, {5, 4}}; - auto getKey = [](const auto& x) { return x.second; }; - - StableSortBy(data, getKey); - - auto it = LowerBoundBy(data.begin(), data.end(), 4, getKey); - UNIT_ASSERT(it != data.end()); - UNIT_ASSERT_EQUAL(it->second, 4); - UNIT_ASSERT_EQUAL(it->first, 3); - - UNIT_ASSERT(it > data.begin()); - UNIT_ASSERT_EQUAL((it - 1)->second, 2); - - UNIT_ASSERT((it + 1) < data.end()); - UNIT_ASSERT_EQUAL((it + 1)->second, 4); - } - + + auto data = TIntPairs{{1, 5}, {3, 2}, {3, 4}, {8, 0}, {5, 4}}; + auto getKey = [](const auto& x) { return x.second; }; + + StableSortBy(data, getKey); + + auto it = LowerBoundBy(data.begin(), data.end(), 4, getKey); + UNIT_ASSERT(it != data.end()); + UNIT_ASSERT_EQUAL(it->second, 4); + UNIT_ASSERT_EQUAL(it->first, 3); + + UNIT_ASSERT(it > data.begin()); + UNIT_ASSERT_EQUAL((it - 1)->second, 2); + + UNIT_ASSERT((it + 1) < data.end()); + UNIT_ASSERT_EQUAL((it + 1)->second, 4); + } + Y_UNIT_TEST(TestUpperBoundBy) { using TIntPairs = TVector<std::pair<i32, i32>>; - - auto data = TIntPairs{{1, 5}, {3, 2}, {3, 4}, {8, 0}, {5, 4}}; - auto getKey = [](const auto& x) { return x.second; }; - - StableSortBy(data, getKey); - - auto it = UpperBoundBy(data.begin(), data.end(), 4, getKey); - UNIT_ASSERT(it != data.end()); - UNIT_ASSERT_EQUAL(it->second, 5); - UNIT_ASSERT_EQUAL(it->first, 1); - - UNIT_ASSERT(it > data.begin()); - UNIT_ASSERT_EQUAL((it - 1)->second, 4); - - UNIT_ASSERT((it + 1) == data.end()); - } + + auto data = TIntPairs{{1, 5}, {3, 2}, {3, 4}, {8, 0}, {5, 4}}; + auto getKey = [](const auto& x) { return x.second; }; + + StableSortBy(data, getKey); + + auto it = UpperBoundBy(data.begin(), data.end(), 4, getKey); + UNIT_ASSERT(it != data.end()); + UNIT_ASSERT_EQUAL(it->second, 5); + UNIT_ASSERT_EQUAL(it->first, 1); + + UNIT_ASSERT(it > data.begin()); + UNIT_ASSERT_EQUAL((it - 1)->second, 4); + + UNIT_ASSERT((it + 1) == data.end()); + } Y_UNIT_TEST(TestFindInContainer) { std::vector<int> v = {1, 2, 1000, 15, 100}; diff --git a/util/generic/benchmark/fastclp2/metrics/main.py b/util/generic/benchmark/fastclp2/metrics/main.py index 9e260653e2..5573c6a5d7 100644 --- a/util/generic/benchmark/fastclp2/metrics/main.py +++ b/util/generic/benchmark/fastclp2/metrics/main.py @@ -2,4 +2,4 @@ import yatest.common as yc def test_export_metrics(metrics): - metrics.set_benchmark(yc.execute_benchmark('util/generic/benchmark/fastclp2/fastclp2', threads=8)) + metrics.set_benchmark(yc.execute_benchmark('util/generic/benchmark/fastclp2/fastclp2', threads=8)) diff --git a/util/generic/benchmark/log2/metrics/main.py b/util/generic/benchmark/log2/metrics/main.py index 3ce98f91d0..26f6b57812 100644 --- a/util/generic/benchmark/log2/metrics/main.py +++ b/util/generic/benchmark/log2/metrics/main.py @@ -2,4 +2,4 @@ import yatest.common as yc def test_export_metrics(metrics): - metrics.set_benchmark(yc.execute_benchmark('util/generic/benchmark/log2/log2', threads=8)) + metrics.set_benchmark(yc.execute_benchmark('util/generic/benchmark/log2/log2', threads=8)) diff --git a/util/generic/benchmark/rotate_bits/metrics/main.py b/util/generic/benchmark/rotate_bits/metrics/main.py index 599825423a..b30555775f 100644 --- a/util/generic/benchmark/rotate_bits/metrics/main.py +++ b/util/generic/benchmark/rotate_bits/metrics/main.py @@ -2,4 +2,4 @@ import yatest.common as yc def test_export_metrics(metrics): - metrics.set_benchmark(yc.execute_benchmark('util/generic/benchmark/rotate_bits/rotate_bits', threads=8)) + metrics.set_benchmark(yc.execute_benchmark('util/generic/benchmark/rotate_bits/rotate_bits', threads=8)) diff --git a/util/generic/benchmark/string/benchmarks.h b/util/generic/benchmark/string/benchmarks.h index 8bd6ec9e7f..e347d7ff47 100644 --- a/util/generic/benchmark/string/benchmarks.h +++ b/util/generic/benchmark/string/benchmarks.h @@ -1,5 +1,5 @@ -#pragma once - +#pragma once + // Define BENCHMARK_PREFIX and BENCHMARKED_CLASS before including this file. #include <util/generic/xrange.h> diff --git a/util/generic/benchmark/vector_count_ctor/metrics/main.py b/util/generic/benchmark/vector_count_ctor/metrics/main.py index d84e229110..835b44fe5f 100644 --- a/util/generic/benchmark/vector_count_ctor/metrics/main.py +++ b/util/generic/benchmark/vector_count_ctor/metrics/main.py @@ -2,4 +2,4 @@ import yatest.common as yc def test_export_metrics(metrics): - metrics.set_benchmark(yc.execute_benchmark('util/generic/benchmark/vector_count_ctor/vector_count_ctor', threads=8)) + metrics.set_benchmark(yc.execute_benchmark('util/generic/benchmark/vector_count_ctor/vector_count_ctor', threads=8)) diff --git a/util/generic/flags.h b/util/generic/flags.h index 5898195d7c..a1f5921d42 100644 --- a/util/generic/flags.h +++ b/util/generic/flags.h @@ -59,10 +59,10 @@ public: return Value_; } - constexpr static TFlags FromBaseType(TInt value) { + constexpr static TFlags FromBaseType(TInt value) { return TFlags(TFlag(value)); - } - + } + constexpr friend TFlags operator|(TFlags l, TFlags r) { return TFlags(TFlag(l.Value_ | r.Value_)); } diff --git a/util/generic/flags_ut.cpp b/util/generic/flags_ut.cpp index ff11d07f31..5377c6a058 100644 --- a/util/generic/flags_ut.cpp +++ b/util/generic/flags_ut.cpp @@ -100,18 +100,18 @@ Y_UNIT_TEST_SUITE(TFlagsTest) { UNIT_ASSERT_VALUES_EQUAL(hash[value0], 0); UNIT_ASSERT_VALUES_EQUAL(hash[value1], 1); } - + Y_UNIT_TEST(TestBaseType) { - ui16 goodValue = 7; - auto goodFlags = ETest1::FromBaseType(goodValue); + ui16 goodValue = 7; + auto goodFlags = ETest1::FromBaseType(goodValue); UNIT_ASSERT(goodFlags& ETestFlag1::Test1); UNIT_ASSERT(goodFlags& ETestFlag1::Test2); UNIT_ASSERT(goodFlags& ETestFlag1::Test4); - UNIT_ASSERT_VALUES_EQUAL(goodValue, goodFlags.ToBaseType()); - - // Passed value is not checked, but preserved as is - ui16 badValue = 1024; - auto badFlags = ETest1::FromBaseType(badValue); - UNIT_ASSERT_VALUES_EQUAL(badValue, badFlags.ToBaseType()); - } + UNIT_ASSERT_VALUES_EQUAL(goodValue, goodFlags.ToBaseType()); + + // Passed value is not checked, but preserved as is + ui16 badValue = 1024; + auto badFlags = ETest1::FromBaseType(badValue); + UNIT_ASSERT_VALUES_EQUAL(badValue, badFlags.ToBaseType()); + } } diff --git a/util/generic/hash_ut.pyx b/util/generic/hash_ut.pyx index 172b5d1252..ecf6dac2e6 100644 --- a/util/generic/hash_ut.pyx +++ b/util/generic/hash_ut.pyx @@ -11,9 +11,9 @@ from cython.operator cimport dereference as deref def _check_convert(THashMap[TString, int] x): - return x - - + return x + + class TestHash(unittest.TestCase): def test_constructors_and_assignments(self): @@ -75,10 +75,10 @@ class TestHash(unittest.TestCase): self.assertTrue(it != tmp.end()) self.assertEqual(deref(it).second, 1) - def test_convert(self): - src = {'foo': 1, 'bar': 42} - self.assertEqual(_check_convert(src), src) - - bad_src = {'foo': 1, 'bar': 'baz'} - with self.assertRaises(TypeError): - _check_convert(bad_src) + def test_convert(self): + src = {'foo': 1, 'bar': 42} + self.assertEqual(_check_convert(src), src) + + bad_src = {'foo': 1, 'bar': 'baz'} + with self.assertRaises(TypeError): + _check_convert(bad_src) diff --git a/util/generic/iterator.h b/util/generic/iterator.h index b34be9c28c..19e9d20976 100644 --- a/util/generic/iterator.h +++ b/util/generic/iterator.h @@ -1,8 +1,8 @@ #pragma once #include <iterator> -#include <utility> - +#include <utility> + namespace NStlIterator { template <class T> class TProxy { @@ -68,31 +68,31 @@ class TInputRangeAdaptor { public: // TODO: private class TIterator { public: - static constexpr bool IsNoexceptNext = noexcept(std::declval<TSlave>().Next()); - + static constexpr bool IsNoexceptNext = noexcept(std::declval<TSlave>().Next()); + using difference_type = std::ptrdiff_t; using pointer = decltype(std::declval<TSlave>().Next()); using reference = decltype(*std::declval<TSlave>().Next()); using value_type = std::remove_cv_t<std::remove_reference_t<reference>>; using iterator_category = std::input_iterator_tag; - inline TIterator() noexcept + inline TIterator() noexcept : Slave_(nullptr) , Cur_() { } - inline TIterator(TSlave* slave) noexcept(IsNoexceptNext) + inline TIterator(TSlave* slave) noexcept(IsNoexceptNext) : Slave_(slave) , Cur_(Slave_->Next()) { } - inline bool operator==(const TIterator& it) const noexcept { + inline bool operator==(const TIterator& it) const noexcept { return Cur_ == it.Cur_; } - inline bool operator!=(const TIterator& it) const noexcept { + inline bool operator!=(const TIterator& it) const noexcept { return !(*this == it); } @@ -104,7 +104,7 @@ public: // TODO: private return *Cur_; } - inline TIterator& operator++() noexcept(IsNoexceptNext) { + inline TIterator& operator++() noexcept(IsNoexceptNext) { Cur_ = Slave_->Next(); return *this; diff --git a/util/generic/list_ut.pyx b/util/generic/list_ut.pyx index 9ae44c5ffd..129e5bc9b6 100644 --- a/util/generic/list_ut.pyx +++ b/util/generic/list_ut.pyx @@ -1,158 +1,158 @@ from util.generic.list cimport TList - -import unittest + +import unittest from cython.operator cimport preincrement - - + + class TestList(unittest.TestCase): - - def test_ctor1(self): + + def test_ctor1(self): cdef TList[int] tmp = TList[int]() - self.assertEqual(tmp.size(), 0) - - def test_ctor2(self): + self.assertEqual(tmp.size(), 0) + + def test_ctor2(self): cdef TList[int] tmp = TList[int](10, 42) - self.assertEqual(tmp.size(), 10) + self.assertEqual(tmp.size(), 10) self.assertEqual(tmp.front(), 42) - - def test_ctor3(self): + + def test_ctor3(self): cdef TList[int] tmp = TList[int](10, 42) cdef TList[int] tmp2 = TList[int](tmp) - self.assertEqual(tmp2.size(), 10) + self.assertEqual(tmp2.size(), 10) self.assertEqual(tmp2.front(), 42) - - def test_operator_assign(self): + + def test_operator_assign(self): cdef TList[int] tmp2 - tmp2.push_back(1) - tmp2.push_back(2) - + tmp2.push_back(1) + tmp2.push_back(2) + cdef TList[int] tmp3 - tmp3.push_back(1) - tmp3.push_back(3) - - tmp3 = tmp2 - - def test_compare(self): + tmp3.push_back(1) + tmp3.push_back(3) + + tmp3 = tmp2 + + def test_compare(self): cdef TList[int] tmp1 - tmp1.push_back(1) - tmp1.push_back(2) - + tmp1.push_back(1) + tmp1.push_back(2) + cdef TList[int] tmp2 - tmp2.push_back(1) - tmp2.push_back(2) - + tmp2.push_back(1) + tmp2.push_back(2) + cdef TList[int] tmp3 - tmp3.push_back(1) - tmp3.push_back(3) - - self.assertTrue(tmp1 == tmp2) - self.assertTrue(tmp1 != tmp3) - - self.assertTrue(tmp1 < tmp3) - self.assertTrue(tmp1 <= tmp3) - - self.assertTrue(tmp3 > tmp1) - self.assertTrue(tmp3 >= tmp1) - - def test_push_pop_back(self): + tmp3.push_back(1) + tmp3.push_back(3) + + self.assertTrue(tmp1 == tmp2) + self.assertTrue(tmp1 != tmp3) + + self.assertTrue(tmp1 < tmp3) + self.assertTrue(tmp1 <= tmp3) + + self.assertTrue(tmp3 > tmp1) + self.assertTrue(tmp3 >= tmp1) + + def test_push_pop_back(self): cdef TList[int] tmp - self.assertEqual(tmp.size(), 0) - - tmp.push_back(42) - self.assertEqual(tmp.size(), 1) - self.assertEqual(tmp.back(), 42) - - tmp.push_back(77) - self.assertEqual(tmp.size(), 2) - self.assertEqual(tmp.back(), 77) - - tmp.pop_back() - self.assertEqual(tmp.size(), 1) - self.assertEqual(tmp.back(), 42) - - tmp.pop_back() - self.assertEqual(tmp.size(), 0) - - def test_front(self): + self.assertEqual(tmp.size(), 0) + + tmp.push_back(42) + self.assertEqual(tmp.size(), 1) + self.assertEqual(tmp.back(), 42) + + tmp.push_back(77) + self.assertEqual(tmp.size(), 2) + self.assertEqual(tmp.back(), 77) + + tmp.pop_back() + self.assertEqual(tmp.size(), 1) + self.assertEqual(tmp.back(), 42) + + tmp.pop_back() + self.assertEqual(tmp.size(), 0) + + def test_front(self): cdef TList[int] tmp - tmp.push_back(42) - self.assertEqual(tmp.front(), 42) - - def test_empty(self): + tmp.push_back(42) + self.assertEqual(tmp.front(), 42) + + def test_empty(self): cdef TList[int] tmp - self.assertTrue(tmp.empty()) - tmp.push_back(42) - self.assertFalse(tmp.empty()) - - def test_max_size(self): + self.assertTrue(tmp.empty()) + tmp.push_back(42) + self.assertFalse(tmp.empty()) + + def test_max_size(self): cdef TList[int] tmp - self.assertTrue(tmp.max_size() > 0) - + self.assertTrue(tmp.max_size() > 0) + def test_resize(self): cdef TList[int] tmp - - tmp.resize(100, 42) - self.assertEqual(tmp.size(), 100) - self.assertEqual(tmp.front(), 42) - self.assertEqual(tmp.back(), 42) - - def test_iter(self): + + tmp.resize(100, 42) + self.assertEqual(tmp.size(), 100) + self.assertEqual(tmp.front(), 42) + self.assertEqual(tmp.back(), 42) + + def test_iter(self): cdef TList[int] tmp - tmp.push_back(1) - tmp.push_back(20) - tmp.push_back(300) - - self.assertEqual([i for i in tmp], [1, 20, 300]) - - def test_iterator(self): + tmp.push_back(1) + tmp.push_back(20) + tmp.push_back(300) + + self.assertEqual([i for i in tmp], [1, 20, 300]) + + def test_iterator(self): cdef TList[int] tmp - - self.assertTrue(tmp.begin() == tmp.end()) - self.assertTrue(tmp.rbegin() == tmp.rend()) - self.assertTrue(tmp.const_begin() == tmp.const_end()) - self.assertTrue(tmp.const_rbegin() == tmp.const_rend()) - - tmp.push_back(1) - - self.assertTrue(tmp.begin() != tmp.end()) - self.assertTrue(tmp.rbegin() != tmp.rend()) - self.assertTrue(tmp.const_begin() != tmp.const_end()) - self.assertTrue(tmp.const_rbegin() != tmp.const_rend()) - + + self.assertTrue(tmp.begin() == tmp.end()) + self.assertTrue(tmp.rbegin() == tmp.rend()) + self.assertTrue(tmp.const_begin() == tmp.const_end()) + self.assertTrue(tmp.const_rbegin() == tmp.const_rend()) + + tmp.push_back(1) + + self.assertTrue(tmp.begin() != tmp.end()) + self.assertTrue(tmp.rbegin() != tmp.rend()) + self.assertTrue(tmp.const_begin() != tmp.const_end()) + self.assertTrue(tmp.const_rbegin() != tmp.const_rend()) + self.assertTrue(preincrement(tmp.begin()) == tmp.end()) self.assertTrue(preincrement(tmp.rbegin()) == tmp.rend()) self.assertTrue(preincrement(tmp.const_begin()) == tmp.const_end()) self.assertTrue(preincrement(tmp.const_rbegin()) == tmp.const_rend()) - - def test_assign(self): + + def test_assign(self): cdef TList[int] tmp - - tmp.assign(10, 42) - self.assertEqual(tmp.size(), 10) - self.assertEqual(tmp.front(), 42) - self.assertEqual(tmp.back(), 42) - - def test_insert(self): + + tmp.assign(10, 42) + self.assertEqual(tmp.size(), 10) + self.assertEqual(tmp.front(), 42) + self.assertEqual(tmp.back(), 42) + + def test_insert(self): cdef TList[int] tmp - tmp.push_back(1) - tmp.push_back(2) - tmp.push_back(3) - - tmp.insert(tmp.begin(), 8) - self.assertEqual([i for i in tmp], [8, 1, 2, 3]) - - tmp.insert(tmp.begin(), 2, 6) - self.assertEqual([i for i in tmp], [6, 6, 8, 1, 2, 3]) - - def test_erase(self): + tmp.push_back(1) + tmp.push_back(2) + tmp.push_back(3) + + tmp.insert(tmp.begin(), 8) + self.assertEqual([i for i in tmp], [8, 1, 2, 3]) + + tmp.insert(tmp.begin(), 2, 6) + self.assertEqual([i for i in tmp], [6, 6, 8, 1, 2, 3]) + + def test_erase(self): cdef TList[int] tmp - tmp.push_back(1) - tmp.push_back(2) - tmp.push_back(3) - tmp.push_back(4) - + tmp.push_back(1) + tmp.push_back(2) + tmp.push_back(3) + tmp.push_back(4) + tmp.erase(preincrement(tmp.begin())) - self.assertEqual([i for i in tmp], [1, 3, 4]) - + self.assertEqual([i for i in tmp], [1, 3, 4]) + tmp.erase(tmp.begin(), preincrement(preincrement(tmp.begin()))) - self.assertEqual([i for i in tmp], [4]) + self.assertEqual([i for i in tmp], [4]) diff --git a/util/generic/maybe.pxd b/util/generic/maybe.pxd index 736f44c5e6..15161dd204 100644 --- a/util/generic/maybe.pxd +++ b/util/generic/maybe.pxd @@ -1,35 +1,35 @@ -cdef extern from "<util/generic/maybe.h>" nogil: - cdef cppclass TNothing: - pass - - cdef TNothing Nothing() - - cdef cppclass TMaybe[T]: - TMaybe(...) except + - - TMaybe& operator=(...) except + - - void ConstructInPlace(...) except + - void Clear() except + - - bint Defined() - bint Empty() - - void CheckDefined() except + - - T* Get() except + - T& GetRef() except + - - T GetOrElse(T&) except + - TMaybe OrElse(TMaybe&) except + - - TMaybe[U] Cast[U]() except + - - void Swap(TMaybe& other) except + - - bint operator ==[U](U&) except + - bint operator !=[U](U&) except + - bint operator <[U](U&) except + - bint operator >[U](U&) except + - bint operator <=[U](U&) except + - bint operator >=[U](U&) except + +cdef extern from "<util/generic/maybe.h>" nogil: + cdef cppclass TNothing: + pass + + cdef TNothing Nothing() + + cdef cppclass TMaybe[T]: + TMaybe(...) except + + + TMaybe& operator=(...) except + + + void ConstructInPlace(...) except + + void Clear() except + + + bint Defined() + bint Empty() + + void CheckDefined() except + + + T* Get() except + + T& GetRef() except + + + T GetOrElse(T&) except + + TMaybe OrElse(TMaybe&) except + + + TMaybe[U] Cast[U]() except + + + void Swap(TMaybe& other) except + + + bint operator ==[U](U&) except + + bint operator !=[U](U&) except + + bint operator <[U](U&) except + + bint operator >[U](U&) except + + bint operator <=[U](U&) except + + bint operator >=[U](U&) except + diff --git a/util/generic/maybe_ut.pyx b/util/generic/maybe_ut.pyx index c983f11053..2de185c807 100644 --- a/util/generic/maybe_ut.pyx +++ b/util/generic/maybe_ut.pyx @@ -1,185 +1,185 @@ -from util.generic.maybe cimport TMaybe, Nothing - -import pytest -import unittest - - -def _check_from_py(TMaybe[int] x): - return x.Defined() - - -def _check_to_py_value(): - cdef TMaybe[int] tmp = TMaybe[int](42) - return tmp - - -def _check_to_py_nothing(): - cdef TMaybe[int] tmp = Nothing() - return tmp - - -class TestMaybe(unittest.TestCase): - - def test_ctor1(self): - cdef TMaybe[int] tmp = TMaybe[int]() - self.assertFalse(tmp.Defined()) - - def test_ctor2(self): - cdef TMaybe[int] tmp = TMaybe[int](42) - self.assertTrue(tmp.Defined()) - self.assertEquals(tmp.GetRef(), 42) - - def test_ctor3(self): - cdef TMaybe[int] tmp = Nothing() - self.assertFalse(tmp.Defined()) - - def test_operator_assign(self): - cdef TMaybe[int] tmp - tmp = 42 - self.assertTrue(tmp.Defined()) - self.assertEquals(tmp.GetRef(), 42) - - def test_compare(self): - cdef TMaybe[int] tmp1 = 17 - cdef TMaybe[int] tmp2 = 42 - cdef TMaybe[int] nothing - - # == - self.assertTrue(tmp1 == 17) - self.assertTrue(tmp1 == tmp1) - self.assertTrue(nothing == nothing) - - self.assertFalse(tmp1 == 16) - self.assertFalse(tmp1 == tmp2) - self.assertFalse(tmp1 == nothing) - - # != - self.assertTrue(tmp1 != 16) - self.assertTrue(tmp1 != tmp2) - self.assertTrue(tmp1 != nothing) - - self.assertFalse(tmp1 != 17) - self.assertFalse(tmp1 != tmp1) - self.assertFalse(nothing != nothing) - - # < - self.assertTrue(nothing < tmp1) - self.assertTrue(nothing < tmp2) - self.assertTrue(tmp1 < tmp2) - self.assertTrue(nothing < 0) - self.assertTrue(tmp1 < 18) - - self.assertFalse(nothing < nothing) - self.assertFalse(tmp1 < tmp1) - self.assertFalse(tmp2 < tmp1) - self.assertFalse(tmp1 < 16) - - # <= - self.assertTrue(nothing <= nothing) - self.assertTrue(nothing <= tmp1) - self.assertTrue(nothing <= tmp2) - self.assertTrue(tmp1 <= tmp1) - self.assertTrue(tmp1 <= tmp2) - self.assertTrue(nothing <= 0) - self.assertTrue(tmp1 <= 18) - - self.assertFalse(tmp2 <= tmp1) - self.assertFalse(tmp1 <= 16) - - # > - self.assertTrue(tmp1 > nothing) - self.assertTrue(tmp2 > nothing) - self.assertTrue(tmp2 > tmp1) - self.assertTrue(tmp1 > 16) - - self.assertFalse(nothing > nothing) - self.assertFalse(nothing > 0) - self.assertFalse(tmp1 > tmp1) - self.assertFalse(tmp1 > tmp2) - self.assertFalse(tmp1 > 18) - - # >= - self.assertTrue(nothing >= nothing) - self.assertTrue(tmp1 >= nothing) - self.assertTrue(tmp2 >= nothing) - self.assertTrue(tmp2 >= tmp1) - self.assertTrue(tmp1 >= tmp1) - self.assertTrue(tmp1 >= 16) - - self.assertFalse(nothing >= 0) - self.assertFalse(tmp1 >= tmp2) - self.assertFalse(tmp1 >= 18) - - def test_construct_in_place(self): - cdef TMaybe[int] tmp - tmp.ConstructInPlace(42) - self.assertTrue(tmp.Defined()) - self.assertEquals(tmp.GetRef(), 42) - - def test_clear(self): - cdef TMaybe[int] tmp = 42 - tmp.Clear() - self.assertFalse(tmp.Defined()) - - def test_defined(self): - cdef TMaybe[int] tmp - self.assertFalse(tmp.Defined()) - self.assertTrue(tmp.Empty()) - tmp = 42 - self.assertTrue(tmp.Defined()) - self.assertFalse(tmp.Empty()) - - def test_check_defined(self): - cdef TMaybe[int] tmp - with pytest.raises(RuntimeError): - tmp.CheckDefined() - tmp = 42 - tmp.CheckDefined() - - def test_get(self): - cdef TMaybe[int] tmp = 42 - cdef int* p = tmp.Get() - self.assertTrue(p != NULL) - self.assertEquals(p[0], 42) - - def test_get_ref(self): - cdef TMaybe[int] tmp = 42 - self.assertTrue(tmp.Defined()) - self.assertEquals(tmp.GetRef(), 42) - - def test_get_or_else(self): - cdef TMaybe[int] tmp = 42 - self.assertEquals(tmp.GetOrElse(13), 42) - tmp.Clear() - self.assertEquals(tmp.GetOrElse(13), 13) - - def test_or_else(self): - cdef TMaybe[int] tmp = 42 - cdef TMaybe[int] nothing - self.assertFalse(nothing.OrElse(nothing).Defined()) - self.assertEquals(tmp.OrElse(nothing).GetRef(), 42) - self.assertEquals(nothing.OrElse(tmp).GetRef(), 42) - self.assertEquals(tmp.OrElse(tmp).GetRef(), 42) - - def test_cast(self): - cdef TMaybe[int] tmp = 42 - cdef TMaybe[char] tmp2 = tmp.Cast[char]() - self.assertEquals(tmp2.GetRef(), 42) - - def test_swap(self): - cdef TMaybe[int] tmp1 = 42 - cdef TMaybe[int] tmp2 - tmp2.Swap(tmp1) - self.assertFalse(tmp1.Defined()) - self.assertEquals(tmp2.GetRef(), 42) - - def test_from_py(self): - self.assertTrue(_check_from_py(42)) - self.assertFalse(_check_from_py(None)) - - with self.assertRaises(TypeError): - _check_from_py("ttt") - - def test_to_py(self): - self.assertEquals(_check_to_py_value(), 42) - self.assertEquals(_check_to_py_nothing(), None) +from util.generic.maybe cimport TMaybe, Nothing + +import pytest +import unittest + + +def _check_from_py(TMaybe[int] x): + return x.Defined() + + +def _check_to_py_value(): + cdef TMaybe[int] tmp = TMaybe[int](42) + return tmp + + +def _check_to_py_nothing(): + cdef TMaybe[int] tmp = Nothing() + return tmp + + +class TestMaybe(unittest.TestCase): + + def test_ctor1(self): + cdef TMaybe[int] tmp = TMaybe[int]() + self.assertFalse(tmp.Defined()) + + def test_ctor2(self): + cdef TMaybe[int] tmp = TMaybe[int](42) + self.assertTrue(tmp.Defined()) + self.assertEquals(tmp.GetRef(), 42) + + def test_ctor3(self): + cdef TMaybe[int] tmp = Nothing() + self.assertFalse(tmp.Defined()) + + def test_operator_assign(self): + cdef TMaybe[int] tmp + tmp = 42 + self.assertTrue(tmp.Defined()) + self.assertEquals(tmp.GetRef(), 42) + + def test_compare(self): + cdef TMaybe[int] tmp1 = 17 + cdef TMaybe[int] tmp2 = 42 + cdef TMaybe[int] nothing + + # == + self.assertTrue(tmp1 == 17) + self.assertTrue(tmp1 == tmp1) + self.assertTrue(nothing == nothing) + + self.assertFalse(tmp1 == 16) + self.assertFalse(tmp1 == tmp2) + self.assertFalse(tmp1 == nothing) + + # != + self.assertTrue(tmp1 != 16) + self.assertTrue(tmp1 != tmp2) + self.assertTrue(tmp1 != nothing) + + self.assertFalse(tmp1 != 17) + self.assertFalse(tmp1 != tmp1) + self.assertFalse(nothing != nothing) + + # < + self.assertTrue(nothing < tmp1) + self.assertTrue(nothing < tmp2) + self.assertTrue(tmp1 < tmp2) + self.assertTrue(nothing < 0) + self.assertTrue(tmp1 < 18) + + self.assertFalse(nothing < nothing) + self.assertFalse(tmp1 < tmp1) + self.assertFalse(tmp2 < tmp1) + self.assertFalse(tmp1 < 16) + + # <= + self.assertTrue(nothing <= nothing) + self.assertTrue(nothing <= tmp1) + self.assertTrue(nothing <= tmp2) + self.assertTrue(tmp1 <= tmp1) + self.assertTrue(tmp1 <= tmp2) + self.assertTrue(nothing <= 0) + self.assertTrue(tmp1 <= 18) + + self.assertFalse(tmp2 <= tmp1) + self.assertFalse(tmp1 <= 16) + + # > + self.assertTrue(tmp1 > nothing) + self.assertTrue(tmp2 > nothing) + self.assertTrue(tmp2 > tmp1) + self.assertTrue(tmp1 > 16) + + self.assertFalse(nothing > nothing) + self.assertFalse(nothing > 0) + self.assertFalse(tmp1 > tmp1) + self.assertFalse(tmp1 > tmp2) + self.assertFalse(tmp1 > 18) + + # >= + self.assertTrue(nothing >= nothing) + self.assertTrue(tmp1 >= nothing) + self.assertTrue(tmp2 >= nothing) + self.assertTrue(tmp2 >= tmp1) + self.assertTrue(tmp1 >= tmp1) + self.assertTrue(tmp1 >= 16) + + self.assertFalse(nothing >= 0) + self.assertFalse(tmp1 >= tmp2) + self.assertFalse(tmp1 >= 18) + + def test_construct_in_place(self): + cdef TMaybe[int] tmp + tmp.ConstructInPlace(42) + self.assertTrue(tmp.Defined()) + self.assertEquals(tmp.GetRef(), 42) + + def test_clear(self): + cdef TMaybe[int] tmp = 42 + tmp.Clear() + self.assertFalse(tmp.Defined()) + + def test_defined(self): + cdef TMaybe[int] tmp + self.assertFalse(tmp.Defined()) + self.assertTrue(tmp.Empty()) + tmp = 42 + self.assertTrue(tmp.Defined()) + self.assertFalse(tmp.Empty()) + + def test_check_defined(self): + cdef TMaybe[int] tmp + with pytest.raises(RuntimeError): + tmp.CheckDefined() + tmp = 42 + tmp.CheckDefined() + + def test_get(self): + cdef TMaybe[int] tmp = 42 + cdef int* p = tmp.Get() + self.assertTrue(p != NULL) + self.assertEquals(p[0], 42) + + def test_get_ref(self): + cdef TMaybe[int] tmp = 42 + self.assertTrue(tmp.Defined()) + self.assertEquals(tmp.GetRef(), 42) + + def test_get_or_else(self): + cdef TMaybe[int] tmp = 42 + self.assertEquals(tmp.GetOrElse(13), 42) + tmp.Clear() + self.assertEquals(tmp.GetOrElse(13), 13) + + def test_or_else(self): + cdef TMaybe[int] tmp = 42 + cdef TMaybe[int] nothing + self.assertFalse(nothing.OrElse(nothing).Defined()) + self.assertEquals(tmp.OrElse(nothing).GetRef(), 42) + self.assertEquals(nothing.OrElse(tmp).GetRef(), 42) + self.assertEquals(tmp.OrElse(tmp).GetRef(), 42) + + def test_cast(self): + cdef TMaybe[int] tmp = 42 + cdef TMaybe[char] tmp2 = tmp.Cast[char]() + self.assertEquals(tmp2.GetRef(), 42) + + def test_swap(self): + cdef TMaybe[int] tmp1 = 42 + cdef TMaybe[int] tmp2 + tmp2.Swap(tmp1) + self.assertFalse(tmp1.Defined()) + self.assertEquals(tmp2.GetRef(), 42) + + def test_from_py(self): + self.assertTrue(_check_from_py(42)) + self.assertFalse(_check_from_py(None)) + + with self.assertRaises(TypeError): + _check_from_py("ttt") + + def test_to_py(self): + self.assertEquals(_check_to_py_value(), 42) + self.assertEquals(_check_to_py_nothing(), None) diff --git a/util/generic/overloaded.h b/util/generic/overloaded.h index eb9b58cad4..96a97e44bc 100644 --- a/util/generic/overloaded.h +++ b/util/generic/overloaded.h @@ -1,52 +1,52 @@ #pragma once -/** +/** * Construct an ad-hoc object with an overloaded `operator()`. - * + * * Typically used with lambdas to construct type-matching visitors for e.g. std::variant: - * ``` + * ``` * std::variant<int, void*, TString> var; - * Visit(TOverloaded{ - * [](int val) { Cerr << "int: " << val; }, - * [](void* val) { Cerr << "ptr: " << val; }, - * [](const TString& val) { Cerr << "str: " << val; }, - * }, var); - * ``` - * - * *** IMPORTANT NOTE (IMPLICIT ARGUMENT CONVERSIONS) *** - * - * Since the resulting objects use regular overloaded method resolution rules, - * methods may be called by inexact matches (causing implicit casts), hence this - * implementation does not guarantee exhaustiveness of cases. - * - * For example, the following code will compile and run by casting all values to - * double: - * ``` + * Visit(TOverloaded{ + * [](int val) { Cerr << "int: " << val; }, + * [](void* val) { Cerr << "ptr: " << val; }, + * [](const TString& val) { Cerr << "str: " << val; }, + * }, var); + * ``` + * + * *** IMPORTANT NOTE (IMPLICIT ARGUMENT CONVERSIONS) *** + * + * Since the resulting objects use regular overloaded method resolution rules, + * methods may be called by inexact matches (causing implicit casts), hence this + * implementation does not guarantee exhaustiveness of cases. + * + * For example, the following code will compile and run by casting all values to + * double: + * ``` * std::variant<int, double, char> var; - * Visit(TOverloaded{ - * [](double val) { Cerr << "dbl: " << val; }, - * }, var); - * ``` - * - * If cases may be ambigous or specific type-matching logic is required, - * a verbose `if constexpr`-based version would be preferred: - * ``` + * Visit(TOverloaded{ + * [](double val) { Cerr << "dbl: " << val; }, + * }, var); + * ``` + * + * If cases may be ambigous or specific type-matching logic is required, + * a verbose `if constexpr`-based version would be preferred: + * ``` * std::variant<int, double, char> var; - * Visit([](auto&& val) { - * using T = std::decay_t<decltype(val)>; - * if constexpr (std::is_same_v<T, int>) { - * Cerr << "int: " << val; - * } else if constexpr (std::is_same_v<T, double>) { - * Cerr << "dbl: " << val; - * } else if constexpr (std::is_same_v<T, char>) { - * Cerr << "chr: " << val; - * } else { - * static_assert(TDependentFalse<T>, "unexpected type"); - * } - * }, var); - * ``` - */ - + * Visit([](auto&& val) { + * using T = std::decay_t<decltype(val)>; + * if constexpr (std::is_same_v<T, int>) { + * Cerr << "int: " << val; + * } else if constexpr (std::is_same_v<T, double>) { + * Cerr << "dbl: " << val; + * } else if constexpr (std::is_same_v<T, char>) { + * Cerr << "chr: " << val; + * } else { + * static_assert(TDependentFalse<T>, "unexpected type"); + * } + * }, var); + * ``` + */ + template <class... Fs> struct TOverloaded: Fs... { using Fs::operator()...; diff --git a/util/generic/overloaded_ut.cpp b/util/generic/overloaded_ut.cpp index bf32daf475..f3d73895ad 100644 --- a/util/generic/overloaded_ut.cpp +++ b/util/generic/overloaded_ut.cpp @@ -1,4 +1,4 @@ -#include <util/generic/overloaded.h> +#include <util/generic/overloaded.h> #include <library/cpp/testing/unittest/registar.h> @@ -35,7 +35,7 @@ Y_UNIT_TEST_SUITE(TOverloadedTest) { [&](double) { res = -1; }, [&](TType1) { res = -1; }}, v); - UNIT_ASSERT_VALUES_EQUAL(res, 5); + UNIT_ASSERT_VALUES_EQUAL(res, 5); } Y_UNIT_TEST(TupleTest) { @@ -48,35 +48,35 @@ Y_UNIT_TEST_SUITE(TOverloadedTest) { [&](bool val) { res += "(bool) " + ToString(val) + ' '; }, }); - UNIT_ASSERT_VALUES_EQUAL(res, "(int) 5 (double) 3.14 (bool) 1 (int) 20 "); + UNIT_ASSERT_VALUES_EQUAL(res, "(int) 5 (double) 3.14 (bool) 1 (int) 20 "); } - - Y_UNIT_TEST(ImplicitConversionsTest) { + + Y_UNIT_TEST(ImplicitConversionsTest) { using TTestVariant = std::variant<int, double, char>; - - // Purposefully exhibit inexact overload matched with implicit type - // conversions - - // All cases implicitly cast to int - auto matchAsInt = [](TTestVariant var) { + + // Purposefully exhibit inexact overload matched with implicit type + // conversions + + // All cases implicitly cast to int + auto matchAsInt = [](TTestVariant var) { return std::visit(TOverloaded{ [](int val) { return val; }, }, var); - }; - - UNIT_ASSERT_VALUES_EQUAL(matchAsInt(TTestVariant{17.77}), 17); - UNIT_ASSERT_VALUES_EQUAL(matchAsInt(TTestVariant{12345}), 12345); - UNIT_ASSERT_VALUES_EQUAL(matchAsInt(TTestVariant{'X'}), 88); - - // All cases implicitly cast to double - auto matchAsDouble = [](TTestVariant var) { + }; + + UNIT_ASSERT_VALUES_EQUAL(matchAsInt(TTestVariant{17.77}), 17); + UNIT_ASSERT_VALUES_EQUAL(matchAsInt(TTestVariant{12345}), 12345); + UNIT_ASSERT_VALUES_EQUAL(matchAsInt(TTestVariant{'X'}), 88); + + // All cases implicitly cast to double + auto matchAsDouble = [](TTestVariant var) { return std::visit(TOverloaded{ [](double val) { return val; }, }, var); - }; - - UNIT_ASSERT_VALUES_EQUAL(matchAsDouble(TTestVariant{17.77}), 17.77); - UNIT_ASSERT_VALUES_EQUAL(matchAsDouble(TTestVariant{12345}), 12345.0); - UNIT_ASSERT_VALUES_EQUAL(matchAsDouble(TTestVariant{'X'}), 88.0); - } + }; + + UNIT_ASSERT_VALUES_EQUAL(matchAsDouble(TTestVariant{17.77}), 17.77); + UNIT_ASSERT_VALUES_EQUAL(matchAsDouble(TTestVariant{12345}), 12345.0); + UNIT_ASSERT_VALUES_EQUAL(matchAsDouble(TTestVariant{'X'}), 88.0); + } } diff --git a/util/generic/ptr.h b/util/generic/ptr.h index 2ef6a9ad72..19db0e3ec5 100644 --- a/util/generic/ptr.h +++ b/util/generic/ptr.h @@ -411,37 +411,37 @@ private: C Counter_; }; -/** - * Atomically reference-counted base with a virtual destructor. - * - * @note Plays well with inheritance, should be used for refcounted base classes. - */ +/** + * Atomically reference-counted base with a virtual destructor. + * + * @note Plays well with inheritance, should be used for refcounted base classes. + */ struct TThrRefBase: public TRefCounted<TThrRefBase, TAtomicCounter> { virtual ~TThrRefBase(); }; -/** - * Atomically reference-counted base. - * - * Deletes refcounted object as type T. - * - * @warning Additional care should be taken with regard to inheritance. If used - * as a base class, @p T should either declare a virtual destructor, or be +/** + * Atomically reference-counted base. + * + * Deletes refcounted object as type T. + * + * @warning Additional care should be taken with regard to inheritance. If used + * as a base class, @p T should either declare a virtual destructor, or be * derived from @p TThrRefBase instead. Otherwise, only destructor of class @p T - * would be called, potentially slicing the object and creating memory leaks. - * - * @note To avoid accidental inheritance when it is not originally intended, - * class @p T should be marked as final. - */ + * would be called, potentially slicing the object and creating memory leaks. + * + * @note To avoid accidental inheritance when it is not originally intended, + * class @p T should be marked as final. + */ template <class T, class D = TDelete> using TAtomicRefCount = TRefCounted<T, TAtomicCounter, D>; -/** - * Non-atomically reference-counted base. - * - * @warning Not thread-safe. Use with great care. If in doubt, use @p ThrRefBase - * or @p TAtomicRefCount instead. - */ +/** + * Non-atomically reference-counted base. + * + * @warning Not thread-safe. Use with great care. If in doubt, use @p ThrRefBase + * or @p TAtomicRefCount instead. + */ template <class T, class D = TDelete> using TSimpleRefCount = TRefCounted<T, TSimpleCounter, D>; diff --git a/util/generic/strbuf_ut.cpp b/util/generic/strbuf_ut.cpp index 245bc3175e..69cde785af 100644 --- a/util/generic/strbuf_ut.cpp +++ b/util/generic/strbuf_ut.cpp @@ -28,15 +28,15 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { } Y_UNIT_TEST(TestConstExpr) { - static constexpr TStringBuf str1("qwe\0rty", 7); + static constexpr TStringBuf str1("qwe\0rty", 7); static constexpr TStringBuf str2(str1.data(), str1.size()); static constexpr TStringBuf str3 = "qwe\0rty"sv; - + UNIT_ASSERT_VALUES_EQUAL(str1.size(), 7); - - UNIT_ASSERT_VALUES_EQUAL(str1, str2); - UNIT_ASSERT_VALUES_EQUAL(str2, str3); - UNIT_ASSERT_VALUES_EQUAL(str1, str3); + + UNIT_ASSERT_VALUES_EQUAL(str1, str2); + UNIT_ASSERT_VALUES_EQUAL(str2, str3); + UNIT_ASSERT_VALUES_EQUAL(str1, str3); static constexpr std::string_view view1(str1); UNIT_ASSERT_VALUES_EQUAL(str1, view1); @@ -47,8 +47,8 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { UNIT_ASSERT_VALUES_EQUAL(str1, str4); static_assert(str1.data() == str4.data()); static_assert(str1.size() == str4.size()); - } - + } + Y_UNIT_TEST(TestAfter) { TStringBuf str("qwerty"); diff --git a/util/generic/string.h b/util/generic/string.h index de41fa7c0c..8cd8aa6917 100644 --- a/util/generic/string.h +++ b/util/generic/string.h @@ -79,11 +79,11 @@ struct TStdString: public TRefCountHolder, public B { } static TStdString* NullStr() noexcept { - #ifdef _LIBCPP_VERSION + #ifdef _LIBCPP_VERSION return (TStdString*)NULL_STRING_REPR; - #else + #else return Singleton<TStdString>(); - #endif + #endif } private: diff --git a/util/generic/string.pxd b/util/generic/string.pxd index 917c4e5a2a..c25f7392a1 100644 --- a/util/generic/string.pxd +++ b/util/generic/string.pxd @@ -1,8 +1,8 @@ -from libcpp.string cimport string as _std_string +from libcpp.string cimport string as _std_string -cdef extern from "<util/generic/strbuf.h>" nogil: - - cdef cppclass TStringBuf: +cdef extern from "<util/generic/strbuf.h>" nogil: + + cdef cppclass TStringBuf: TStringBuf() except + TStringBuf(const char*) except + TStringBuf(const char*, size_t) except + @@ -10,14 +10,14 @@ cdef extern from "<util/generic/strbuf.h>" nogil: char* Data() size_t size() size_t Size() - - + + cdef extern from "<util/generic/string.h>" nogil: size_t npos "TString::npos" - # Inheritance is bogus, but it's safe to assume TString is-a TStringBuf via implicit cast - cdef cppclass TString(TStringBuf): + # Inheritance is bogus, but it's safe to assume TString is-a TStringBuf via implicit cast + cdef cppclass TString(TStringBuf): TString() except + TString(TString&) except + TString(_std_string&) except + @@ -28,34 +28,34 @@ cdef extern from "<util/generic/string.h>" nogil: # as a TString formed by a repetition of character c, n times. TString(size_t, char) except + TString(char*, char*) except + - TString(TStringBuf&) except + - TString(TStringBuf&, TStringBuf&) except + - TString(TStringBuf&, TStringBuf&, TStringBuf&) except + + TString(TStringBuf&) except + + TString(TStringBuf&, TStringBuf&) except + + TString(TStringBuf&, TStringBuf&, TStringBuf&) except + const char* c_str() size_t max_size() size_t length() - void resize(size_t) except + - void resize(size_t, char c) except + + void resize(size_t) except + + void resize(size_t, char c) except + size_t capacity() - void reserve(size_t) except + - void clear() except + + void reserve(size_t) except + + void clear() except + bint empty() char& at(size_t) char& operator[](size_t) - int compare(TStringBuf&) + int compare(TStringBuf&) - TString& append(TStringBuf&) except + - TString& append(TStringBuf&, size_t, size_t) except + + TString& append(TStringBuf&) except + + TString& append(TStringBuf&, size_t, size_t) except + TString& append(char *) except + TString& append(char *, size_t) except + TString& append(size_t, char) except + - void push_back(char c) except + + void push_back(char c) except + - TString& assign(TStringBuf&) except + - TString& assign(TStringBuf&, size_t, size_t) except + + TString& assign(TStringBuf&) except + + TString& assign(TStringBuf&, size_t, size_t) except + TString& assign(char *) except + TString& assign(char *, size_t) except + @@ -65,54 +65,54 @@ cdef extern from "<util/generic/string.h>" nogil: TString& insert(size_t, char* s, size_t) except + TString& insert(size_t, size_t, char c) except + - size_t copy(char *, size_t) except + - size_t copy(char *, size_t, size_t) except + + size_t copy(char *, size_t) except + + size_t copy(char *, size_t, size_t) except + - size_t find(TStringBuf&) - size_t find(TStringBuf&, size_t pos) - size_t find(char) + size_t find(TStringBuf&) + size_t find(TStringBuf&, size_t pos) + size_t find(char) size_t find(char, size_t pos) - size_t rfind(TStringBuf&) - size_t rfind(TStringBuf&, size_t pos) - size_t rfind(char) - size_t rfind(char, size_t pos) + size_t rfind(TStringBuf&) + size_t rfind(TStringBuf&, size_t pos) + size_t rfind(char) + size_t rfind(char, size_t pos) size_t find_first_of(char c) - size_t find_first_of(char c, size_t pos) - size_t find_first_of(TStringBuf& set) - size_t find_first_of(TStringBuf& set, size_t pos) + size_t find_first_of(char c, size_t pos) + size_t find_first_of(TStringBuf& set) + size_t find_first_of(TStringBuf& set, size_t pos) size_t find_first_not_of(char c) - size_t find_first_not_of(char c, size_t pos) - size_t find_first_not_of(TStringBuf& set) - size_t find_first_not_of(TStringBuf& set, size_t pos) + size_t find_first_not_of(char c, size_t pos) + size_t find_first_not_of(TStringBuf& set) + size_t find_first_not_of(TStringBuf& set, size_t pos) size_t find_last_of(char c) - size_t find_last_of(char c, size_t pos) - size_t find_last_of(TStringBuf& set) - size_t find_last_of(TStringBuf& set, size_t pos) + size_t find_last_of(char c, size_t pos) + size_t find_last_of(TStringBuf& set) + size_t find_last_of(TStringBuf& set, size_t pos) TString substr(size_t pos) except + TString substr(size_t pos, size_t n) except + - TString operator+(TStringBuf& rhs) except + + TString operator+(TStringBuf& rhs) except + TString operator+(char* rhs) except + - bint operator==(TStringBuf&) + bint operator==(TStringBuf&) bint operator==(char*) - bint operator!=(TStringBuf&) - bint operator!=(char*) + bint operator!=(TStringBuf&) + bint operator!=(char*) - bint operator<(TStringBuf&) - bint operator<(char*) + bint operator<(TStringBuf&) + bint operator<(char*) - bint operator>(TStringBuf&) - bint operator>(char*) + bint operator>(TStringBuf&) + bint operator>(char*) - bint operator<=(TStringBuf&) - bint operator<=(char*) + bint operator<=(TStringBuf&) + bint operator<=(char*) - bint operator>=(TStringBuf&) - bint operator>=(char*) + bint operator>=(TStringBuf&) + bint operator>=(char*) diff --git a/util/generic/string_ut.cpp b/util/generic/string_ut.cpp index 0d47f2d022..ac82e9091d 100644 --- a/util/generic/string_ut.cpp +++ b/util/generic/string_ut.cpp @@ -107,7 +107,7 @@ protected: // Non-shared behaviour - never shrink s.reserve(256); - #ifndef TSTRING_IS_STD_STRING + #ifndef TSTRING_IS_STD_STRING const auto* data = s.data(); UNIT_ASSERT(s.capacity() >= 256); @@ -115,18 +115,18 @@ protected: s.reserve(128); UNIT_ASSERT(s.capacity() >= 256 && s.data() == data); - #endif + #endif s.resize(64, 'x'); s.reserve(10); - #ifdef TSTRING_IS_STD_STRING + #ifdef TSTRING_IS_STD_STRING UNIT_ASSERT(s.capacity() >= 64); - #else + #else UNIT_ASSERT(s.capacity() >= 256 && s.data() == data); - #endif + #endif - #ifndef TSTRING_IS_STD_STRING + #ifndef TSTRING_IS_STD_STRING // Shared behaviour - always reallocate, just as much as requisted TStringType holder = s; @@ -146,7 +146,7 @@ protected: UNIT_ASSERT(s.capacity() >= 64 && s.capacity() < 128 && s.data() != data); UNIT_ASSERT(s.IsDetached()); - #endif + #endif #endif } diff --git a/util/generic/string_ut.pyx b/util/generic/string_ut.pyx index 0aafffd1d1..5407f5b4c1 100644 --- a/util/generic/string_ut.pyx +++ b/util/generic/string_ut.pyx @@ -1,225 +1,225 @@ # cython: c_string_type=str, c_string_encoding=utf8 -from libcpp.string cimport string as std_string +from libcpp.string cimport string as std_string from util.generic.string cimport TString, npos - -import pytest -import unittest - + +import pytest +import unittest + import sys - -class TestStroka(unittest.TestCase): + +class TestStroka(unittest.TestCase): def test_unicode(self): cdef TString x = "привет" self.assertEquals(x, "привет") - - def test_ctor1(self): + + def test_ctor1(self): cdef TString tmp = TString() cdef TString tmp2 = TString(tmp) self.assertEquals(tmp2, "") - - def test_ctor2(self): - cdef std_string tmp = b"hello" + + def test_ctor2(self): + cdef std_string tmp = b"hello" cdef TString tmp2 = TString(tmp) self.assertEquals(tmp2, "hello") - - def test_ctor3(self): - cdef TString tmp = b"hello" + + def test_ctor3(self): + cdef TString tmp = b"hello" cdef TString tmp2 = TString(tmp, 0, 4) self.assertEquals(tmp2, "hell") - - def test_ctor4(self): + + def test_ctor4(self): cdef TString tmp = TString(<char*>b"hello") self.assertEquals(tmp, "hello") - - def test_ctor5(self): + + def test_ctor5(self): cdef TString tmp = TString(<char*>b"hello", 4) self.assertEquals(tmp, "hell") - - def test_ctor6(self): + + def test_ctor6(self): cdef TString tmp = TString(<char*>b"hello", 1, 3) self.assertEquals(tmp, "ell") - - def test_ctor7(self): + + def test_ctor7(self): cdef TString tmp = TString(3, <char>'x') self.assertEquals(tmp, "xxx") - - def test_ctor8(self): - cdef bytes tmp = b"hello" + + def test_ctor8(self): + cdef bytes tmp = b"hello" cdef TString tmp2 = TString(<char*>tmp, <char*>tmp + 4) self.assertEquals(tmp2, "hell") - - def test_compare(self): - cdef TString tmp1 = b"abacab" - cdef TString tmp2 = b"abacab" - cdef TString tmp3 = b"abacac" - - self.assertTrue(tmp1.compare(tmp2) == 0) - self.assertTrue(tmp1.compare(tmp3) < 0) - self.assertTrue(tmp3.compare(tmp1) > 0) - - self.assertTrue(tmp1 == tmp2) - self.assertTrue(tmp1 != tmp3) - - self.assertTrue(tmp1 < tmp3) - self.assertTrue(tmp1 <= tmp3) - - self.assertTrue(tmp3 > tmp1) - self.assertTrue(tmp3 >= tmp1) - - def test_operator_assign(self): - cdef TString tmp = b"hello" + + def test_compare(self): + cdef TString tmp1 = b"abacab" + cdef TString tmp2 = b"abacab" + cdef TString tmp3 = b"abacac" + + self.assertTrue(tmp1.compare(tmp2) == 0) + self.assertTrue(tmp1.compare(tmp3) < 0) + self.assertTrue(tmp3.compare(tmp1) > 0) + + self.assertTrue(tmp1 == tmp2) + self.assertTrue(tmp1 != tmp3) + + self.assertTrue(tmp1 < tmp3) + self.assertTrue(tmp1 <= tmp3) + + self.assertTrue(tmp3 > tmp1) + self.assertTrue(tmp3 >= tmp1) + + def test_operator_assign(self): + cdef TString tmp = b"hello" cdef TString tmp2 = tmp self.assertEquals(tmp2, "hello") - - def test_operator_plus(self): - cdef TString tmp = TString(b"hello ") + TString(b"world") + + def test_operator_plus(self): + cdef TString tmp = TString(b"hello ") + TString(b"world") self.assertEquals(tmp, "hello world") - - def test_c_str(self): - cdef TString tmp = b"hello" + + def test_c_str(self): + cdef TString tmp = b"hello" if sys.version_info.major == 2: self.assertEquals(bytes(tmp.c_str()), b"hello") else: self.assertEquals(bytes(tmp.c_str(), 'utf8'), b"hello") - - def test_length(self): - cdef TString tmp = b"hello" - self.assertEquals(tmp.size(), tmp.length()) - - def test_index(self): - cdef TString tmp = b"hello" - - self.assertEquals(<bytes>tmp[0], b'h') - self.assertEquals(<bytes>tmp.at(0), b'h') - - self.assertEquals(<bytes>tmp[4], b'o') - self.assertEquals(<bytes>tmp.at(4), b'o') - + + def test_length(self): + cdef TString tmp = b"hello" + self.assertEquals(tmp.size(), tmp.length()) + + def test_index(self): + cdef TString tmp = b"hello" + + self.assertEquals(<bytes>tmp[0], b'h') + self.assertEquals(<bytes>tmp.at(0), b'h') + + self.assertEquals(<bytes>tmp[4], b'o') + self.assertEquals(<bytes>tmp.at(4), b'o') + # Actually, TString::at() is noexcept - # with pytest.raises(IndexError): - # tmp.at(100) - - def test_append(self): + # with pytest.raises(IndexError): + # tmp.at(100) + + def test_append(self): cdef TString tmp - cdef TString tmp2 = b"fuu" - - tmp.append(tmp2) + cdef TString tmp2 = b"fuu" + + tmp.append(tmp2) self.assertEquals(tmp, "fuu") - - tmp.append(tmp2, 1, 2) + + tmp.append(tmp2, 1, 2) self.assertEquals(tmp, "fuuuu") - - tmp.append(<char*>"ll ") + + tmp.append(<char*>"ll ") self.assertEquals(tmp, "fuuuull ") - - tmp.append(<char*>"of greatness", 4) + + tmp.append(<char*>"of greatness", 4) self.assertEquals(tmp, "fuuuull of g") - - tmp.append(2, <char>b'o') + + tmp.append(2, <char>b'o') self.assertEquals(tmp, "fuuuull of goo") - - tmp.push_back(b'z') + + tmp.push_back(b'z') self.assertEquals(tmp, "fuuuull of gooz") - - def test_assign(self): + + def test_assign(self): cdef TString tmp - - tmp.assign(b"one") + + tmp.assign(b"one") self.assertEquals(tmp, "one") - - tmp.assign(b"two hundred", 0, 3) + + tmp.assign(b"two hundred", 0, 3) self.assertEquals(tmp, "two") - - tmp.assign(<char*>b"three") + + tmp.assign(<char*>b"three") self.assertEquals(tmp, "three") - - tmp.assign(<char*>b"three fiddy", 5) + + tmp.assign(<char*>b"three fiddy", 5) self.assertEquals(tmp, "three") - - def test_insert(self): + + def test_insert(self): cdef TString tmp - - tmp = b"xx" - tmp.insert(1, b"foo") + + tmp = b"xx" + tmp.insert(1, b"foo") self.assertEquals(tmp, "xfoox") - - tmp = b"xx" - tmp.insert(1, b"haxor", 1, 3) + + tmp = b"xx" + tmp.insert(1, b"haxor", 1, 3) self.assertEquals(tmp, "xaxox") - - tmp = b"xx" - tmp.insert(1, <char*>b"foo") + + tmp = b"xx" + tmp.insert(1, <char*>b"foo") self.assertEquals(tmp, "xfoox") - - tmp = b"xx" - tmp.insert(1, <char*>b"foozzy", 3) + + tmp = b"xx" + tmp.insert(1, <char*>b"foozzy", 3) self.assertEquals(tmp, "xfoox") - - tmp = b"xx" - tmp.insert(1, 2, <char>b'u') + + tmp = b"xx" + tmp.insert(1, 2, <char>b'u') self.assertEquals(tmp, "xuux") - - def test_copy(self): - cdef char buf[16] - cdef TString tmp = b"hello" - tmp.copy(buf, 5, 0) + + def test_copy(self): + cdef char buf[16] + cdef TString tmp = b"hello" + tmp.copy(buf, 5, 0) self.assertEquals(buf[:5], "hello") - - def test_find(self): - cdef TString haystack = b"whole lotta bytes" + + def test_find(self): + cdef TString haystack = b"whole lotta bytes" cdef TString needle = "hole" - - self.assertEquals(haystack.find(needle), 1) - self.assertEquals(haystack.find(needle, 3), npos) - - self.assertEquals(haystack.find(<char>b'h'), 1) - self.assertEquals(haystack.find(<char>b'h', 3), npos) - - def test_rfind(self): - cdef TString haystack = b"whole lotta bytes" - cdef TString needle = b"hole" - - self.assertEquals(haystack.rfind(needle), 1) - self.assertEquals(haystack.rfind(needle, 0), npos) - - self.assertEquals(haystack.rfind(<char>b'h'), 1) - self.assertEquals(haystack.rfind(<char>b'h', 0), npos) - - def test_find_first_of(self): - cdef TString haystack = b"whole lotta bytes" - cdef TString cset = b"hxz" - - self.assertEquals(haystack.find_first_of(<char>b'h'), 1) - self.assertEquals(haystack.find_first_of(<char>b'h', 3), npos) - - self.assertEquals(haystack.find_first_of(cset), 1) - self.assertEquals(haystack.find_first_of(cset, 3), npos) - - def test_first_not_of(self): - cdef TString haystack = b"whole lotta bytes" - cdef TString cset = b"wxz" - - self.assertEquals(haystack.find_first_not_of(<char>b'w'), 1) - self.assertEquals(haystack.find_first_not_of(<char>b'w', 3), 3) - - self.assertEquals(haystack.find_first_not_of(cset), 1) - self.assertEquals(haystack.find_first_not_of(cset, 3), 3) - - def test_find_last_of(self): - cdef TString haystack = b"whole lotta bytes" - cdef TString cset = b"hxz" - - self.assertEquals(haystack.find_last_of(<char>b'h'), 1) - self.assertEquals(haystack.find_last_of(<char>b'h', 0), npos) - - self.assertEquals(haystack.find_last_of(cset), 1) - self.assertEquals(haystack.find_last_of(cset, 0), npos) - - def test_substr(self): - cdef TString tmp = b"foobar" - + + self.assertEquals(haystack.find(needle), 1) + self.assertEquals(haystack.find(needle, 3), npos) + + self.assertEquals(haystack.find(<char>b'h'), 1) + self.assertEquals(haystack.find(<char>b'h', 3), npos) + + def test_rfind(self): + cdef TString haystack = b"whole lotta bytes" + cdef TString needle = b"hole" + + self.assertEquals(haystack.rfind(needle), 1) + self.assertEquals(haystack.rfind(needle, 0), npos) + + self.assertEquals(haystack.rfind(<char>b'h'), 1) + self.assertEquals(haystack.rfind(<char>b'h', 0), npos) + + def test_find_first_of(self): + cdef TString haystack = b"whole lotta bytes" + cdef TString cset = b"hxz" + + self.assertEquals(haystack.find_first_of(<char>b'h'), 1) + self.assertEquals(haystack.find_first_of(<char>b'h', 3), npos) + + self.assertEquals(haystack.find_first_of(cset), 1) + self.assertEquals(haystack.find_first_of(cset, 3), npos) + + def test_first_not_of(self): + cdef TString haystack = b"whole lotta bytes" + cdef TString cset = b"wxz" + + self.assertEquals(haystack.find_first_not_of(<char>b'w'), 1) + self.assertEquals(haystack.find_first_not_of(<char>b'w', 3), 3) + + self.assertEquals(haystack.find_first_not_of(cset), 1) + self.assertEquals(haystack.find_first_not_of(cset, 3), 3) + + def test_find_last_of(self): + cdef TString haystack = b"whole lotta bytes" + cdef TString cset = b"hxz" + + self.assertEquals(haystack.find_last_of(<char>b'h'), 1) + self.assertEquals(haystack.find_last_of(<char>b'h', 0), npos) + + self.assertEquals(haystack.find_last_of(cset), 1) + self.assertEquals(haystack.find_last_of(cset, 0), npos) + + def test_substr(self): + cdef TString tmp = b"foobar" + self.assertEquals(tmp.substr(1), "oobar") self.assertEquals(tmp.substr(1, 4), "ooba") diff --git a/util/generic/ut/ya.make b/util/generic/ut/ya.make index 61f5ed02a7..6eaf24cc5f 100644 --- a/util/generic/ut/ya.make +++ b/util/generic/ut/ya.make @@ -32,7 +32,7 @@ SRCS( generic/maybe_ut.cpp generic/mem_copy_ut.cpp generic/objects_counter_ut.cpp - generic/overloaded_ut.cpp + generic/overloaded_ut.cpp generic/ptr_ut.cpp generic/queue_ut.cpp generic/serialized_enum_ut.cpp diff --git a/util/generic/vector.pxd b/util/generic/vector.pxd index 1675abb609..99dde95d48 100644 --- a/util/generic/vector.pxd +++ b/util/generic/vector.pxd @@ -1,4 +1,4 @@ -cdef extern from "<util/generic/vector.h>" nogil: +cdef extern from "<util/generic/vector.h>" nogil: cdef cppclass TVector[T]: cppclass iterator: T& operator*() @@ -12,67 +12,67 @@ cdef extern from "<util/generic/vector.h>" nogil: bint operator>(iterator) bint operator<=(iterator) bint operator>=(iterator) - + cppclass reverse_iterator: T& operator*() - reverse_iterator operator++() - reverse_iterator operator--() - reverse_iterator operator+(size_t) - reverse_iterator operator-(size_t) + reverse_iterator operator++() + reverse_iterator operator--() + reverse_iterator operator+(size_t) + reverse_iterator operator-(size_t) bint operator==(reverse_iterator) bint operator!=(reverse_iterator) bint operator<(reverse_iterator) bint operator>(reverse_iterator) bint operator<=(reverse_iterator) bint operator>=(reverse_iterator) - + cppclass const_iterator(iterator): pass - + cppclass const_reverse_iterator(reverse_iterator): pass - + TVector() except + TVector(TVector&) except + TVector(size_t) except + TVector(size_t, T&) except + - + bint operator==(TVector&) bint operator!=(TVector&) bint operator<(TVector&) bint operator>(TVector&) bint operator<=(TVector&) bint operator>=(TVector&) - - void assign(size_t, const T&) except + + + void assign(size_t, const T&) except + void assign[input_iterator](input_iterator, input_iterator) except + - + T& at(size_t) except + - T& operator[](size_t) - + T& operator[](size_t) + T& back() iterator begin() const_iterator const_begin "begin"() size_t capacity() - void clear() except + + void clear() except + bint empty() iterator end() const_iterator const_end "end"() - iterator erase(iterator) except + - iterator erase(iterator, iterator) except + + 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 + size_t max_size() - void pop_back() except + + void pop_back() except + void push_back(T&) except + void emplace_back(...) except + reverse_iterator rbegin() const_reverse_iterator const_rbegin "rbegin"() reverse_iterator rend() const_reverse_iterator const_rend "rend"() - void reserve(size_t) except + + void reserve(size_t) except + void resize(size_t) except + void resize(size_t, T&) except + size_t size() @@ -80,4 +80,4 @@ cdef extern from "<util/generic/vector.h>" nogil: # C++11 methods T* data() - void shrink_to_fit() except + + void shrink_to_fit() except + diff --git a/util/generic/vector_ut.pyx b/util/generic/vector_ut.pyx index 1aa7af2427..904e67733b 100644 --- a/util/generic/vector_ut.pyx +++ b/util/generic/vector_ut.pyx @@ -1,221 +1,221 @@ # cython: c_string_type=str, c_string_encoding=utf8 from util.generic.vector cimport TVector -from util.generic.string cimport TString - -import pytest -import unittest - - +from util.generic.string cimport TString + +import pytest +import unittest + + def _check_convert(TVector[TString] x): - return x - - -class TestVector(unittest.TestCase): - - def test_ctor1(self): + return x + + +class TestVector(unittest.TestCase): + + def test_ctor1(self): cdef TVector[int] tmp = TVector[int]() - self.assertEqual(tmp.size(), 0) - - def test_ctor2(self): + self.assertEqual(tmp.size(), 0) + + def test_ctor2(self): cdef TVector[int] tmp = TVector[int](10) - self.assertEqual(tmp.size(), 10) - self.assertEqual(tmp[0], 0) - - def test_ctor3(self): + self.assertEqual(tmp.size(), 10) + self.assertEqual(tmp[0], 0) + + def test_ctor3(self): cdef TVector[int] tmp = TVector[int](10, 42) - self.assertEqual(tmp.size(), 10) - self.assertEqual(tmp[0], 42) - - def test_ctor4(self): + self.assertEqual(tmp.size(), 10) + self.assertEqual(tmp[0], 42) + + def test_ctor4(self): cdef TVector[int] tmp = TVector[int](10, 42) cdef TVector[int] tmp2 = TVector[int](tmp) - self.assertEqual(tmp2.size(), 10) - self.assertEqual(tmp2[0], 42) - - def test_operator_assign(self): + self.assertEqual(tmp2.size(), 10) + self.assertEqual(tmp2[0], 42) + + def test_operator_assign(self): cdef TVector[int] tmp2 - tmp2.push_back(1) - tmp2.push_back(2) - + tmp2.push_back(1) + tmp2.push_back(2) + cdef TVector[int] tmp3 - tmp3.push_back(1) - tmp3.push_back(3) - + tmp3.push_back(1) + tmp3.push_back(3) + self.assertEqual(tmp2[1], 2) self.assertEqual(tmp3[1], 3) - tmp3 = tmp2 - + tmp3 = tmp2 + self.assertEqual(tmp2[1], 2) self.assertEqual(tmp3[1], 2) - def test_compare(self): + def test_compare(self): cdef TVector[int] tmp1 - tmp1.push_back(1) - tmp1.push_back(2) - + tmp1.push_back(1) + tmp1.push_back(2) + cdef TVector[int] tmp2 - tmp2.push_back(1) - tmp2.push_back(2) - + tmp2.push_back(1) + tmp2.push_back(2) + cdef TVector[int] tmp3 - tmp3.push_back(1) - tmp3.push_back(3) - - self.assertTrue(tmp1 == tmp2) - self.assertTrue(tmp1 != tmp3) - - self.assertTrue(tmp1 < tmp3) - self.assertTrue(tmp1 <= tmp3) - - self.assertTrue(tmp3 > tmp1) - self.assertTrue(tmp3 >= tmp1) - - def test_index(self): + tmp3.push_back(1) + tmp3.push_back(3) + + self.assertTrue(tmp1 == tmp2) + self.assertTrue(tmp1 != tmp3) + + self.assertTrue(tmp1 < tmp3) + self.assertTrue(tmp1 <= tmp3) + + self.assertTrue(tmp3 > tmp1) + self.assertTrue(tmp3 >= tmp1) + + def test_index(self): cdef TVector[int] tmp = TVector[int](10, 42) - - self.assertEqual(tmp[0], 42) - self.assertEqual(tmp[5], 42) - - self.assertEqual(tmp.data()[0], 42) - self.assertEqual(tmp.data()[5], 42) - - self.assertEqual(tmp.at(0), 42) - self.assertEqual(tmp.at(5), 42) - - with pytest.raises(IndexError): - tmp.at(100) - - def test_push_pop_back(self): + + self.assertEqual(tmp[0], 42) + self.assertEqual(tmp[5], 42) + + self.assertEqual(tmp.data()[0], 42) + self.assertEqual(tmp.data()[5], 42) + + self.assertEqual(tmp.at(0), 42) + self.assertEqual(tmp.at(5), 42) + + with pytest.raises(IndexError): + tmp.at(100) + + def test_push_pop_back(self): cdef TVector[int] tmp - self.assertEqual(tmp.size(), 0) - - tmp.push_back(42) - self.assertEqual(tmp.size(), 1) - self.assertEqual(tmp.back(), 42) - - tmp.push_back(77) - self.assertEqual(tmp.size(), 2) - self.assertEqual(tmp.back(), 77) - - tmp.pop_back() - self.assertEqual(tmp.size(), 1) - self.assertEqual(tmp.back(), 42) - - tmp.pop_back() - self.assertEqual(tmp.size(), 0) - - def test_front(self): + self.assertEqual(tmp.size(), 0) + + tmp.push_back(42) + self.assertEqual(tmp.size(), 1) + self.assertEqual(tmp.back(), 42) + + tmp.push_back(77) + self.assertEqual(tmp.size(), 2) + self.assertEqual(tmp.back(), 77) + + tmp.pop_back() + self.assertEqual(tmp.size(), 1) + self.assertEqual(tmp.back(), 42) + + tmp.pop_back() + self.assertEqual(tmp.size(), 0) + + def test_front(self): cdef TVector[int] tmp - tmp.push_back(42) - self.assertEqual(tmp.front(), 42) - - def test_empty(self): + tmp.push_back(42) + self.assertEqual(tmp.front(), 42) + + def test_empty(self): cdef TVector[int] tmp - self.assertTrue(tmp.empty()) - tmp.push_back(42) - self.assertFalse(tmp.empty()) - - def test_max_size(self): + self.assertTrue(tmp.empty()) + tmp.push_back(42) + self.assertFalse(tmp.empty()) + + def test_max_size(self): cdef TVector[int] tmp - self.assertTrue(tmp.max_size() > 0) - - def test_reserve_resize(self): + self.assertTrue(tmp.max_size() > 0) + + def test_reserve_resize(self): cdef TVector[int] tmp - tmp.reserve(1000) - self.assertEqual(tmp.capacity(), 1000) - - tmp.resize(100) - self.assertEqual(tmp.size(), 100) - self.assertEqual(tmp.front(), 0) - self.assertEqual(tmp.back(), 0) - - tmp.shrink_to_fit() - tmp.clear() - - tmp.resize(100, 42) - self.assertEqual(tmp.size(), 100) - self.assertEqual(tmp.front(), 42) - self.assertEqual(tmp.back(), 42) - - def test_iter(self): + tmp.reserve(1000) + self.assertEqual(tmp.capacity(), 1000) + + tmp.resize(100) + self.assertEqual(tmp.size(), 100) + self.assertEqual(tmp.front(), 0) + self.assertEqual(tmp.back(), 0) + + tmp.shrink_to_fit() + tmp.clear() + + tmp.resize(100, 42) + self.assertEqual(tmp.size(), 100) + self.assertEqual(tmp.front(), 42) + self.assertEqual(tmp.back(), 42) + + def test_iter(self): cdef TVector[int] tmp - tmp.push_back(1) - tmp.push_back(20) - tmp.push_back(300) - - self.assertEqual([i for i in tmp], [1, 20, 300]) - - def test_iterator(self): + tmp.push_back(1) + tmp.push_back(20) + tmp.push_back(300) + + self.assertEqual([i for i in tmp], [1, 20, 300]) + + def test_iterator(self): cdef TVector[int] tmp - - self.assertTrue(tmp.begin() == tmp.end()) - self.assertTrue(tmp.rbegin() == tmp.rend()) - self.assertTrue(tmp.const_begin() == tmp.const_end()) - self.assertTrue(tmp.const_rbegin() == tmp.const_rend()) - - tmp.push_back(1) - - self.assertTrue(tmp.begin() != tmp.end()) - self.assertTrue(tmp.rbegin() != tmp.rend()) - self.assertTrue(tmp.const_begin() != tmp.const_end()) - self.assertTrue(tmp.const_rbegin() != tmp.const_rend()) - - self.assertTrue(tmp.begin() < tmp.end()) - self.assertTrue(tmp.rbegin() < tmp.rend()) - self.assertTrue(tmp.const_begin() < tmp.const_end()) - self.assertTrue(tmp.const_rbegin() < tmp.const_rend()) - - self.assertTrue(tmp.begin() + 1 == tmp.end()) - self.assertTrue(tmp.rbegin() + 1 == tmp.rend()) - self.assertTrue(tmp.const_begin() + 1 == tmp.const_end()) - self.assertTrue(tmp.const_rbegin() + 1 == tmp.const_rend()) - - def test_assign(self): + + self.assertTrue(tmp.begin() == tmp.end()) + self.assertTrue(tmp.rbegin() == tmp.rend()) + self.assertTrue(tmp.const_begin() == tmp.const_end()) + self.assertTrue(tmp.const_rbegin() == tmp.const_rend()) + + tmp.push_back(1) + + self.assertTrue(tmp.begin() != tmp.end()) + self.assertTrue(tmp.rbegin() != tmp.rend()) + self.assertTrue(tmp.const_begin() != tmp.const_end()) + self.assertTrue(tmp.const_rbegin() != tmp.const_rend()) + + self.assertTrue(tmp.begin() < tmp.end()) + self.assertTrue(tmp.rbegin() < tmp.rend()) + self.assertTrue(tmp.const_begin() < tmp.const_end()) + self.assertTrue(tmp.const_rbegin() < tmp.const_rend()) + + self.assertTrue(tmp.begin() + 1 == tmp.end()) + self.assertTrue(tmp.rbegin() + 1 == tmp.rend()) + self.assertTrue(tmp.const_begin() + 1 == tmp.const_end()) + self.assertTrue(tmp.const_rbegin() + 1 == tmp.const_rend()) + + def test_assign(self): cdef TVector[int] tmp - - tmp.assign(10, 42) - self.assertEqual(tmp.size(), 10) - self.assertEqual(tmp.front(), 42) - self.assertEqual(tmp.back(), 42) - - def test_insert(self): + + tmp.assign(10, 42) + self.assertEqual(tmp.size(), 10) + self.assertEqual(tmp.front(), 42) + self.assertEqual(tmp.back(), 42) + + def test_insert(self): cdef TVector[int] tmp - tmp.push_back(1) - tmp.push_back(2) - tmp.push_back(3) - + tmp.push_back(1) + tmp.push_back(2) + tmp.push_back(3) + cdef TVector[int] tmp2 - tmp2.push_back(7) - tmp2.push_back(9) - - tmp.insert(tmp.begin(), 8) - self.assertEqual([i for i in tmp], [8, 1, 2, 3]) - - tmp.insert(tmp.begin(), 2, 6) - self.assertEqual([i for i in tmp], [6, 6, 8, 1, 2, 3]) - - tmp.insert(tmp.begin(), tmp2.begin(), tmp2.end()) - self.assertEqual([i for i in tmp], [7, 9, 6, 6, 8, 1, 2, 3]) - - def test_erase(self): + tmp2.push_back(7) + tmp2.push_back(9) + + tmp.insert(tmp.begin(), 8) + self.assertEqual([i for i in tmp], [8, 1, 2, 3]) + + tmp.insert(tmp.begin(), 2, 6) + self.assertEqual([i for i in tmp], [6, 6, 8, 1, 2, 3]) + + tmp.insert(tmp.begin(), tmp2.begin(), tmp2.end()) + self.assertEqual([i for i in tmp], [7, 9, 6, 6, 8, 1, 2, 3]) + + def test_erase(self): cdef TVector[int] tmp - tmp.push_back(1) - tmp.push_back(2) - tmp.push_back(3) - tmp.push_back(4) - - tmp.erase(tmp.begin() + 1) - self.assertEqual([i for i in tmp], [1, 3, 4]) - - tmp.erase(tmp.begin(), tmp.begin() + 2) - self.assertEqual([i for i in tmp], [4]) - - def test_convert(self): - src = ['foo', 'bar', 'baz'] - self.assertEqual(_check_convert(src), src) - - bad_src = ['foo', 42] - with self.assertRaises(TypeError): - _check_convert(bad_src) + tmp.push_back(1) + tmp.push_back(2) + tmp.push_back(3) + tmp.push_back(4) + + tmp.erase(tmp.begin() + 1) + self.assertEqual([i for i in tmp], [1, 3, 4]) + + tmp.erase(tmp.begin(), tmp.begin() + 2) + self.assertEqual([i for i in tmp], [4]) + + def test_convert(self): + src = ['foo', 'bar', 'baz'] + self.assertEqual(_check_convert(src), src) + + bad_src = ['foo', 42] + with self.assertRaises(TypeError): + _check_convert(bad_src) diff --git a/util/memory/benchmark/pool/metrics/main.py b/util/memory/benchmark/pool/metrics/main.py index 1674fb3aa4..cc17b7b888 100644 --- a/util/memory/benchmark/pool/metrics/main.py +++ b/util/memory/benchmark/pool/metrics/main.py @@ -2,4 +2,4 @@ import yatest.common as yc def test_export_metrics(metrics): - metrics.set_benchmark(yc.execute_benchmark('util/memory/benchmark/pool/pool', threads=8)) + metrics.set_benchmark(yc.execute_benchmark('util/memory/benchmark/pool/pool', threads=8)) diff --git a/util/memory/tempbuf.cpp b/util/memory/tempbuf.cpp index 06a43843ba..09a2d0f140 100644 --- a/util/memory/tempbuf.cpp +++ b/util/memory/tempbuf.cpp @@ -132,7 +132,7 @@ namespace { Unused_.ForEach(deleter); } - inline TPerThreadedBuf* Acquire() { + inline TPerThreadedBuf* Acquire() { if (!Unused_.Empty()) { return Unused_.PopFront(); } @@ -154,15 +154,15 @@ static inline TTempBufManager* TempBufManager() { return FastTlsSingletonWithPriority<TTempBufManager, 2>(); } -static inline TTempBuf::TImpl* AcquireSmallBuffer(size_t size) { -#if defined(_asan_enabled_) - return new (size) TAllocedBuf(); -#else - Y_UNUSED(size); - return TempBufManager()->Acquire(); -#endif -} - +static inline TTempBuf::TImpl* AcquireSmallBuffer(size_t size) { +#if defined(_asan_enabled_) + return new (size) TAllocedBuf(); +#else + Y_UNUSED(size); + return TempBufManager()->Acquire(); +#endif +} + void TPerThreadedBuf::Dispose() noexcept { if (Manager_ == TempBufManager()) { Manager_->Return(this); @@ -172,7 +172,7 @@ void TPerThreadedBuf::Dispose() noexcept { } TTempBuf::TTempBuf() - : Impl_(AcquireSmallBuffer(TMP_BUF_LEN)) + : Impl_(AcquireSmallBuffer(TMP_BUF_LEN)) { } @@ -183,7 +183,7 @@ TTempBuf::TTempBuf() */ static inline TTempBuf::TImpl* ConstructImpl(size_t len) { if (len <= TMP_BUF_LEN) { - return AcquireSmallBuffer(len); + return AcquireSmallBuffer(len); } return new (len) TAllocedBuf(); diff --git a/util/random/benchmark/prng/metrics/main.py b/util/random/benchmark/prng/metrics/main.py index c90daa70d3..15b371fe75 100644 --- a/util/random/benchmark/prng/metrics/main.py +++ b/util/random/benchmark/prng/metrics/main.py @@ -2,4 +2,4 @@ import yatest.common as yc def test_export_metrics(metrics): - metrics.set_benchmark(yc.execute_benchmark('util/random/benchmark/prng/prng', threads=8)) + metrics.set_benchmark(yc.execute_benchmark('util/random/benchmark/prng/prng', threads=8)) diff --git a/util/stream/format.cpp b/util/stream/format.cpp index b4ffa0aac1..3996130df5 100644 --- a/util/stream/format.cpp +++ b/util/stream/format.cpp @@ -1,7 +1,7 @@ #include "format.h" #include "output.h" -#include <util/generic/ymath.h> +#include <util/generic/ymath.h> #include <util/string/cast.h> namespace NFormatPrivate { @@ -12,27 +12,27 @@ namespace NFormatPrivate { } static inline IOutputStream& PrintDoubleShortly(IOutputStream& os, const double& d) { - // General case: request 3 significant digits - // Side-effect: allows exponential representation - EFloatToStringMode mode = PREC_NDIGITS; - int ndigits = 3; - - if (IsValidFloat(d) && Abs(d) < 1e12) { - // For reasonably-sized finite values, it's better to avoid - // exponential representation. - // Use compact fixed representation and determine - // precision based on magnitude. - mode = PREC_POINT_DIGITS_STRIP_ZEROES; - if (i64(Abs(d) * 100) < 1000) { - ndigits = 2; - } else if (i64(Abs(d) * 10) < 1000) { - ndigits = 1; - } else { - ndigits = 0; - } - } - - return os << Prec(d, mode, ndigits); + // General case: request 3 significant digits + // Side-effect: allows exponential representation + EFloatToStringMode mode = PREC_NDIGITS; + int ndigits = 3; + + if (IsValidFloat(d) && Abs(d) < 1e12) { + // For reasonably-sized finite values, it's better to avoid + // exponential representation. + // Use compact fixed representation and determine + // precision based on magnitude. + mode = PREC_POINT_DIGITS_STRIP_ZEROES; + if (i64(Abs(d) * 100) < 1000) { + ndigits = 2; + } else if (i64(Abs(d) * 10) < 1000) { + ndigits = 1; + } else { + ndigits = 0; + } + } + + return os << Prec(d, mode, ndigits); } } @@ -51,11 +51,11 @@ void Out<NFormatPrivate::THumanReadableSize>(IOutputStream& stream, const NForma if (v < base) { NFormatPrivate::PrintDoubleShortly(stream, v); - } else if (v < base2) { + } else if (v < base2) { NFormatPrivate::PrintDoubleShortly(stream, v / (double)base) << 'K'; - } else if (v < base3) { + } else if (v < base3) { NFormatPrivate::PrintDoubleShortly(stream, v / (double)base2) << 'M'; - } else if (v < base4) { + } else if (v < base4) { NFormatPrivate::PrintDoubleShortly(stream, v / (double)base3) << 'G'; } else { NFormatPrivate::PrintDoubleShortly(stream, v / (double)base4) << 'T'; diff --git a/util/stream/format_ut.cpp b/util/stream/format_ut.cpp index c1845dab59..43245aeb48 100644 --- a/util/stream/format_ut.cpp +++ b/util/stream/format_ut.cpp @@ -97,23 +97,23 @@ Y_UNIT_TEST_SUITE(TOutputStreamFormattingTest) { Y_UNIT_TEST(TestHumanReadableSize1000) { UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(0, SF_QUANTITY)), "0"); - + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1, SF_QUANTITY)), "1"); UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1000, SF_QUANTITY)), "1K"); UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1234567, SF_QUANTITY)), "1.23M"); UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(12345678, SF_QUANTITY)), "12.3M"); UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(12345678 * 1000ull, SF_QUANTITY)), "12.3G"); - - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1, SF_QUANTITY)), "-1"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1000, SF_QUANTITY)), "-1K"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1234567, SF_QUANTITY)), "-1.23M"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-12345678, SF_QUANTITY)), "-12.3M"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-12345678 * 1000ll, SF_QUANTITY)), "-12.3G"); + + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1, SF_QUANTITY)), "-1"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1000, SF_QUANTITY)), "-1K"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1234567, SF_QUANTITY)), "-1.23M"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-12345678, SF_QUANTITY)), "-12.3M"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-12345678 * 1000ll, SF_QUANTITY)), "-12.3G"); } Y_UNIT_TEST(TestHumanReadableSize1024) { UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(0, SF_BYTES)), "0B"); - + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(100, SF_BYTES)), "100B"); UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1024, SF_BYTES)), "1KiB"); UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(2.25 * 1024 * 1024, SF_BYTES)), "2.25MiB"); @@ -124,41 +124,41 @@ Y_UNIT_TEST_SUITE(TOutputStreamFormattingTest) { UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1236 * 1024 * 1024, SF_BYTES)), "1.21GiB"); UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1024ull * 1024 * 1024 * 1024, SF_BYTES)), "1TiB"); UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(100 / 3., SF_BYTES)), "33.3B"); - - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-100, SF_BYTES)), "-100B"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1024, SF_BYTES)), "-1KiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-2.25 * 1024 * 1024, SF_BYTES)), "-2.25MiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-2.5 * 1024, SF_BYTES)), "-2.5KiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-45.3 * 1024, SF_BYTES)), "-45.3KiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1024 * 1024, SF_BYTES)), "-1MiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-5 * 1024 * 1024, SF_BYTES)), "-5MiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1236 * 1024 * 1024, SF_BYTES)), "-1.21GiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1024ll * 1024 * 1024 * 1024, SF_BYTES)), "-1TiB"); + + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-100, SF_BYTES)), "-100B"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1024, SF_BYTES)), "-1KiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-2.25 * 1024 * 1024, SF_BYTES)), "-2.25MiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-2.5 * 1024, SF_BYTES)), "-2.5KiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-45.3 * 1024, SF_BYTES)), "-45.3KiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1024 * 1024, SF_BYTES)), "-1MiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-5 * 1024 * 1024, SF_BYTES)), "-5MiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1236 * 1024 * 1024, SF_BYTES)), "-1.21GiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1024ll * 1024 * 1024 * 1024, SF_BYTES)), "-1TiB"); UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-100 / 3., SF_BYTES)), "-33.3B"); - - // XXX: For 1000 <= x < 1024, Prec(x, 3) falls back to exponential form - - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1000ll, SF_BYTES)), "1000B"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1010ll, SF_BYTES)), "1010B"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1000ll * 1024, SF_BYTES)), "1000KiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1010ll * 1024, SF_BYTES)), "1010KiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1000ll * 1024 * 1024, SF_BYTES)), "1000MiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1010ll * 1024 * 1024, SF_BYTES)), "1010MiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1000ll * 1024 * 1024 * 1024, SF_BYTES)), "1000GiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1010ll * 1024 * 1024 * 1024, SF_BYTES)), "1010GiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1000ll * 1024 * 1024 * 1024 * 1024, SF_BYTES)), "1000TiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1010ll * 1024 * 1024 * 1024 * 1024, SF_BYTES)), "1010TiB"); - - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1000ll, SF_BYTES)), "-1000B"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1010ll, SF_BYTES)), "-1010B"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1000ll * 1024, SF_BYTES)), "-1000KiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1010ll * 1024, SF_BYTES)), "-1010KiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1000ll * 1024 * 1024, SF_BYTES)), "-1000MiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1010ll * 1024 * 1024, SF_BYTES)), "-1010MiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1000ll * 1024 * 1024 * 1024, SF_BYTES)), "-1000GiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1010ll * 1024 * 1024 * 1024, SF_BYTES)), "-1010GiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1000ll * 1024 * 1024 * 1024 * 1024, SF_BYTES)), "-1000TiB"); - UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1010ll * 1024 * 1024 * 1024 * 1024, SF_BYTES)), "-1010TiB"); + + // XXX: For 1000 <= x < 1024, Prec(x, 3) falls back to exponential form + + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1000ll, SF_BYTES)), "1000B"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1010ll, SF_BYTES)), "1010B"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1000ll * 1024, SF_BYTES)), "1000KiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1010ll * 1024, SF_BYTES)), "1010KiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1000ll * 1024 * 1024, SF_BYTES)), "1000MiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1010ll * 1024 * 1024, SF_BYTES)), "1010MiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1000ll * 1024 * 1024 * 1024, SF_BYTES)), "1000GiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1010ll * 1024 * 1024 * 1024, SF_BYTES)), "1010GiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1000ll * 1024 * 1024 * 1024 * 1024, SF_BYTES)), "1000TiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(1010ll * 1024 * 1024 * 1024 * 1024, SF_BYTES)), "1010TiB"); + + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1000ll, SF_BYTES)), "-1000B"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1010ll, SF_BYTES)), "-1010B"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1000ll * 1024, SF_BYTES)), "-1000KiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1010ll * 1024, SF_BYTES)), "-1010KiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1000ll * 1024 * 1024, SF_BYTES)), "-1000MiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1010ll * 1024 * 1024, SF_BYTES)), "-1010MiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1000ll * 1024 * 1024 * 1024, SF_BYTES)), "-1000GiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1010ll * 1024 * 1024 * 1024, SF_BYTES)), "-1010GiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1000ll * 1024 * 1024 * 1024 * 1024, SF_BYTES)), "-1000TiB"); + UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadableSize(-1010ll * 1024 * 1024 * 1024 * 1024, SF_BYTES)), "-1010TiB"); } Y_UNIT_TEST(TestHumanReadableDuration) { diff --git a/util/stream/output.cpp b/util/stream/output.cpp index c7fce77a90..db81b81b70 100644 --- a/util/stream/output.cpp +++ b/util/stream/output.cpp @@ -203,7 +203,7 @@ DEF_CONV_NUM(long double, 512) #if !defined(_YNDX_LIBCXX_ENABLE_VECTOR_BOOL_COMPRESSION) || (_YNDX_LIBCXX_ENABLE_VECTOR_BOOL_COMPRESSION == 1) // TODO: acknowledge std::bitset::reference for both libc++ and libstdc++ -template <> +template <> void Out<typename std::vector<bool>::reference>(IOutputStream& o, const std::vector<bool>::reference& bit) { return Out<bool>(o, static_cast<bool>(bit)); } diff --git a/util/string/benchmark/ascii/main.cpp b/util/string/benchmark/ascii/main.cpp index 49ad13228d..673047025d 100644 --- a/util/string/benchmark/ascii/main.cpp +++ b/util/string/benchmark/ascii/main.cpp @@ -17,20 +17,20 @@ namespace { return Get((ui8)x) ? x + ('a' - 'A') : x; } }; - - struct TToLowerLookup { - char Table[256]; - - TToLowerLookup() { - for (size_t i : xrange(256)) { - Table[i] = AsciiToLower(i); - } - } - - char ToLower(char x) const noexcept { - return Table[(ui8)x]; - } - }; + + struct TToLowerLookup { + char Table[256]; + + TToLowerLookup() { + for (size_t i : xrange(256)) { + Table[i] = AsciiToLower(i); + } + } + + char ToLower(char x) const noexcept { + return Table[(ui8)x]; + } + }; } static inline char FastAsciiToLower(char c) { @@ -91,27 +91,27 @@ Y_CPU_BENCHMARK(BitMapAsciiToLower, iface) { } } -Y_CPU_BENCHMARK(LookupAsciiToLower, iface) { - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); - - for (int j = 0; j < 256; ++j) { - Y_DO_NOT_OPTIMIZE_AWAY(Singleton<TToLowerLookup>()->ToLower(j)); - } - } -} - -Y_CPU_BENCHMARK(LookupAsciiToLowerNoSingleton, iface) { - TToLowerLookup lookup; - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); - - for (int j = 0; j < 256; ++j) { - Y_DO_NOT_OPTIMIZE_AWAY(lookup.ToLower(j)); - } - } -} - +Y_CPU_BENCHMARK(LookupAsciiToLower, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + + for (int j = 0; j < 256; ++j) { + Y_DO_NOT_OPTIMIZE_AWAY(Singleton<TToLowerLookup>()->ToLower(j)); + } + } +} + +Y_CPU_BENCHMARK(LookupAsciiToLowerNoSingleton, iface) { + TToLowerLookup lookup; + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + + for (int j = 0; j < 256; ++j) { + Y_DO_NOT_OPTIMIZE_AWAY(lookup.ToLower(j)); + } + } +} + Y_CPU_BENCHMARK(tolower, iface) { for (const auto i : xrange(iface.Iterations())) { Y_UNUSED(i); diff --git a/util/string/benchmark/float_to_string/metrics/main.py b/util/string/benchmark/float_to_string/metrics/main.py index ec98b468e0..e9d4b7ac1d 100644 --- a/util/string/benchmark/float_to_string/metrics/main.py +++ b/util/string/benchmark/float_to_string/metrics/main.py @@ -2,4 +2,4 @@ import yatest.common as yc def test_export_metrics(metrics): - metrics.set_benchmark(yc.execute_benchmark('util/string/benchmark/float_to_string/float_to_string', threads=8)) + metrics.set_benchmark(yc.execute_benchmark('util/string/benchmark/float_to_string/float_to_string', threads=8)) diff --git a/util/string/benchmark/join/metrics/main.py b/util/string/benchmark/join/metrics/main.py index 876985d719..1ed5014808 100644 --- a/util/string/benchmark/join/metrics/main.py +++ b/util/string/benchmark/join/metrics/main.py @@ -2,4 +2,4 @@ import yatest.common as yc def test_export_metrics(metrics): - metrics.set_benchmark(yc.execute_benchmark('util/string/benchmark/join/join', threads=8)) + metrics.set_benchmark(yc.execute_benchmark('util/string/benchmark/join/join', threads=8)) diff --git a/util/string/benchmark/subst_global/metrics/main.py b/util/string/benchmark/subst_global/metrics/main.py index dcfc0e1307..62f2f3d76d 100644 --- a/util/string/benchmark/subst_global/metrics/main.py +++ b/util/string/benchmark/subst_global/metrics/main.py @@ -2,4 +2,4 @@ import yatest.common as yc def test_export_metrics(metrics): - metrics.set_benchmark(yc.execute_benchmark('util/string/benchmark/subst_global/subst_global', threads=8)) + metrics.set_benchmark(yc.execute_benchmark('util/string/benchmark/subst_global/subst_global', threads=8)) diff --git a/util/string/cast.h b/util/string/cast.h index 622c96aae7..90e925c194 100644 --- a/util/string/cast.h +++ b/util/string/cast.h @@ -323,14 +323,14 @@ inline TString IntToString(T t) { return TString(buf, IntToString<base>(t, buf, sizeof(buf))); } -template <int base, class TInt, class TChar> -bool TryIntFromString(const TChar* data, size_t len, TInt& result); - +template <int base, class TInt, class TChar> +bool TryIntFromString(const TChar* data, size_t len, TInt& result); + template <int base, class TInt, class TStringType> inline bool TryIntFromString(const TStringType& s, TInt& result) { return TryIntFromString<base>(s.data(), s.size(), result); -} - +} + template <class TInt, int base, class TChar> TInt IntFromString(const TChar* str, size_t len); diff --git a/util/string/cast.py b/util/string/cast.py index 47425494c0..4787f6ef44 100644 --- a/util/string/cast.py +++ b/util/string/cast.py @@ -1,6 +1,6 @@ print 'static const ui8 SAFE_LENS[4][15] = {' - + def nb(n, b): if n == 0: return [0] @@ -15,7 +15,7 @@ def nb(n, b): for p in (1, 2, 4, 8): - + def it1(): for base in range(2, 17): m = 2 ** (8 * p) - 1 diff --git a/util/string/cast_ut.cpp b/util/string/cast_ut.cpp index c861add9bf..033450c38c 100644 --- a/util/string/cast_ut.cpp +++ b/util/string/cast_ut.cpp @@ -24,22 +24,22 @@ #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); -#define TRY_HEX_MACROS_MAP(mac, type, val, result, def) \ +#define TRY_HEX_MACROS_MAP(mac, type, val, result, def) \ mac(type, val, result, def, 2) \ mac(type, val, result, def, 8) \ mac(type, val, result, def, 10) \ mac(type, val, result, def, 16) - + #define TRY_OK_HEX_CHECK(type, val, result, def, base) \ result = def; \ - UNIT_ASSERT_EQUAL(TryIntFromStringForCheck<base>(IntToString<base>(val), result), true); \ - UNIT_ASSERT_EQUAL(result, val); - + UNIT_ASSERT_EQUAL(TryIntFromStringForCheck<base>(IntToString<base>(val), result), true); \ + UNIT_ASSERT_EQUAL(result, val); + #define TRY_FAIL_HEX_CHECK(type, val, result, def, base) \ result = def; \ UNIT_ASSERT_VALUES_EQUAL(TryIntFromStringForCheck<base>(IntToString<base>(val), result), false); \ UNIT_ASSERT_VALUES_EQUAL(result, def); - + template <class A> struct TRet { template <int base> @@ -47,11 +47,11 @@ struct TRet { return IntFromString<A, base>(str); } - template <int base> + template <int base> inline bool TryIntFromStringForCheck(const TString& str, A& result) { - return TryIntFromString<base>(str, result); - } - + return TryIntFromString<base>(str, result); + } + template <class B> inline void CheckOK(B v) { UNIT_ASSERT_VALUES_EQUAL(FromString<A>(ToString(v)), v); // char @@ -68,14 +68,14 @@ struct TRet { template <class B> inline void CheckTryOK(B v) { - static const A defaultV = 42; + static const A defaultV = 42; A convV; UNIT_ASSERT_VALUES_EQUAL(TryFromString<A>(ToString(v), convV), true); // char UNIT_ASSERT_VALUES_EQUAL(v, convV); UNIT_ASSERT_VALUES_EQUAL(TryFromString<A>(ToWtring(v), convV), true); // wide char UNIT_ASSERT_VALUES_EQUAL(v, convV); - TRY_HEX_MACROS_MAP(TRY_OK_HEX_CHECK, A, v, convV, defaultV); + TRY_HEX_MACROS_MAP(TRY_OK_HEX_CHECK, A, v, convV, defaultV); } template <class B> @@ -86,8 +86,8 @@ struct TRet { UNIT_ASSERT_VALUES_EQUAL(defaultV, convV); UNIT_ASSERT_VALUES_EQUAL(TryFromString<A>(ToWtring(v), convV), false); // wide char UNIT_ASSERT_VALUES_EQUAL(defaultV, convV); - - TRY_HEX_MACROS_MAP(TRY_FAIL_HEX_CHECK, A, v, convV, defaultV); + + TRY_HEX_MACROS_MAP(TRY_FAIL_HEX_CHECK, A, v, convV, defaultV); } }; diff --git a/util/system/benchmark/cpu_id/metrics/main.py b/util/system/benchmark/cpu_id/metrics/main.py index 5b814f6f43..d9a86e825c 100644 --- a/util/system/benchmark/cpu_id/metrics/main.py +++ b/util/system/benchmark/cpu_id/metrics/main.py @@ -2,4 +2,4 @@ import yatest.common as yc def test_export_metrics(metrics): - metrics.set_benchmark(yc.execute_benchmark('util/system/benchmark/cpu_id/cpu_id', threads=8)) + metrics.set_benchmark(yc.execute_benchmark('util/system/benchmark/cpu_id/cpu_id', threads=8)) diff --git a/util/system/benchmark/create_destroy_thread/metrics/main.py b/util/system/benchmark/create_destroy_thread/metrics/main.py index 38a40a448f..45564cda7f 100644 --- a/util/system/benchmark/create_destroy_thread/metrics/main.py +++ b/util/system/benchmark/create_destroy_thread/metrics/main.py @@ -2,6 +2,6 @@ import yatest.common as yc def test_export_metrics(metrics): - metrics.set_benchmark( - yc.execute_benchmark('util/system/benchmark/create_destroy_thread/create_destroy_thread', threads=8) - ) + metrics.set_benchmark( + yc.execute_benchmark('util/system/benchmark/create_destroy_thread/create_destroy_thread', threads=8) + ) diff --git a/util/system/sanitizers.h b/util/system/sanitizers.h index 0a08b7e24b..965e5c751e 100644 --- a/util/system/sanitizers.h +++ b/util/system/sanitizers.h @@ -4,10 +4,10 @@ extern "C" { // sanitizers API -#if defined(_asan_enabled_) +#if defined(_asan_enabled_) void __lsan_ignore_object(const void* p); -#endif - +#endif + #if defined(_msan_enabled_) void __msan_unpoison(const volatile void* a, size_t size); void __msan_poison(const volatile void* a, size_t size); @@ -82,7 +82,7 @@ namespace NSan { } // Make memory region fully initialized (without changing its contents). - inline static void Unpoison(const volatile void* a, size_t size) noexcept { + inline static void Unpoison(const volatile void* a, size_t size) noexcept { #if defined(_msan_enabled_) __msan_unpoison(a, size); #else @@ -93,7 +93,7 @@ namespace NSan { // Make memory region fully uninitialized (without changing its contents). // This is a legacy interface that does not update origin information. Use __msan_allocated_memory() instead. - inline static void Poison(const volatile void* a, size_t size) noexcept { + inline static void Poison(const volatile void* a, size_t size) noexcept { #if defined(_msan_enabled_) __msan_poison(a, size); #else @@ -103,7 +103,7 @@ namespace NSan { } // Checks that memory range is fully initialized, and reports an error if it is not. - inline static void CheckMemIsInitialized(const volatile void* a, size_t size) noexcept { + inline static void CheckMemIsInitialized(const volatile void* a, size_t size) noexcept { #if defined(_msan_enabled_) __msan_check_mem_is_initialized(a, size); #else @@ -111,14 +111,14 @@ namespace NSan { Y_UNUSED(size); #endif } - - inline static void MarkAsIntentionallyLeaked(const void* ptr) noexcept { -#if defined(_asan_enabled_) - __lsan_ignore_object(ptr); -#else - Y_UNUSED(ptr); -#endif - } + + inline static void MarkAsIntentionallyLeaked(const void* ptr) noexcept { +#if defined(_asan_enabled_) + __lsan_ignore_object(ptr); +#else + Y_UNUSED(ptr); +#endif + } #if defined(_tsan_enabled_) // defined in .cpp to avoid exposing problematic C-linkage version of AnnotateBenignRaceSized(...) diff --git a/util/system/sanitizers_ut.cpp b/util/system/sanitizers_ut.cpp index a27e171e45..5de096e14b 100644 --- a/util/system/sanitizers_ut.cpp +++ b/util/system/sanitizers_ut.cpp @@ -1,15 +1,15 @@ -#include "sanitizers.h" -#include "sys_alloc.h" - +#include "sanitizers.h" +#include "sys_alloc.h" + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(Sanitizers) { Y_UNIT_TEST(MarkAsIntentionallyLeaked) { - auto* p1 = new i32[100]; - NSan::MarkAsIntentionallyLeaked(p1); - - auto* p2 = y_allocate(123); - NSan::MarkAsIntentionallyLeaked(p2); - } - + auto* p1 = new i32[100]; + NSan::MarkAsIntentionallyLeaked(p1); + + auto* p2 = y_allocate(123); + NSan::MarkAsIntentionallyLeaked(p2); + } + } // Y_UNIT_TEST_SUITE(Sanitizers) diff --git a/util/system/types.pxd b/util/system/types.pxd index bee758348d..cc916f6e70 100644 --- a/util/system/types.pxd +++ b/util/system/types.pxd @@ -1,13 +1,13 @@ -from libc.stdint cimport int8_t, int16_t, int32_t, int64_t -from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t - -cdef extern from "<util/system/types.h>" nogil: - ctypedef int8_t i8 - ctypedef int16_t i16 - ctypedef int32_t i32 - ctypedef int64_t i64 - - ctypedef uint8_t ui8 - ctypedef uint16_t ui16 - ctypedef uint32_t ui32 - ctypedef uint64_t ui64 +from libc.stdint cimport int8_t, int16_t, int32_t, int64_t +from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t + +cdef extern from "<util/system/types.h>" nogil: + ctypedef int8_t i8 + ctypedef int16_t i16 + ctypedef int32_t i32 + ctypedef int64_t i64 + + ctypedef uint8_t ui8 + ctypedef uint16_t ui16 + ctypedef uint32_t ui32 + ctypedef uint64_t ui64 diff --git a/util/system/types_ut.pyx b/util/system/types_ut.pyx index a63f3ce0b0..bb93ac8566 100644 --- a/util/system/types_ut.pyx +++ b/util/system/types_ut.pyx @@ -1,40 +1,40 @@ -from util.system.types cimport i8, i16, i32, i64 -from util.system.types cimport ui8, ui16, ui32, ui64 - -import pytest -import unittest - - -class TestTypes(unittest.TestCase): - def test_i8(self): - cdef i8 value = 42 - self.assertEqual(sizeof(value), 1) - - def test_ui8(self): - cdef ui8 value = 42 - self.assertEqual(sizeof(value), 1) - - def test_i16(self): - cdef i16 value = 42 - self.assertEqual(sizeof(value), 2) - - def test_ui16(self): - cdef ui16 value = 42 - self.assertEqual(sizeof(value), 2) - - def test_i32(self): - cdef i32 value = 42 - self.assertEqual(sizeof(value), 4) - - def test_ui32(self): - cdef ui32 value = 42 - self.assertEqual(sizeof(value), 4) - - def test_i64(self): - cdef i64 value = 42 - self.assertEqual(sizeof(value), 8) - - def test_ui64(self): - cdef ui64 value = 42 - self.assertEqual(sizeof(value), 8) - +from util.system.types cimport i8, i16, i32, i64 +from util.system.types cimport ui8, ui16, ui32, ui64 + +import pytest +import unittest + + +class TestTypes(unittest.TestCase): + def test_i8(self): + cdef i8 value = 42 + self.assertEqual(sizeof(value), 1) + + def test_ui8(self): + cdef ui8 value = 42 + self.assertEqual(sizeof(value), 1) + + def test_i16(self): + cdef i16 value = 42 + self.assertEqual(sizeof(value), 2) + + def test_ui16(self): + cdef ui16 value = 42 + self.assertEqual(sizeof(value), 2) + + def test_i32(self): + cdef i32 value = 42 + self.assertEqual(sizeof(value), 4) + + def test_ui32(self): + cdef ui32 value = 42 + self.assertEqual(sizeof(value), 4) + + def test_i64(self): + cdef i64 value = 42 + self.assertEqual(sizeof(value), 8) + + def test_ui64(self): + cdef ui64 value = 42 + self.assertEqual(sizeof(value), 8) + diff --git a/util/system/ut/ya.make b/util/system/ut/ya.make index ce6c3e811d..127e7c261e 100644 --- a/util/system/ut/ya.make +++ b/util/system/ut/ya.make @@ -61,7 +61,7 @@ SRCS( system/progname_ut.cpp system/rusage_ut.cpp system/rwlock_ut.cpp - system/sanitizers_ut.cpp + system/sanitizers_ut.cpp system/shellcommand_ut.cpp system/spinlock_ut.cpp system/src_root_ut.cpp diff --git a/util/tests/cython/test_generic.py b/util/tests/cython/test_generic.py index 874eb71230..a0d61339cc 100644 --- a/util/tests/cython/test_generic.py +++ b/util/tests/cython/test_generic.py @@ -1,29 +1,29 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function, absolute_import, division - +# -*- coding: utf-8 -*- + +from __future__ import print_function, absolute_import, division + from util.generic.deque_ut import TestDeque -from util.generic.hash_ut import TestHash +from util.generic.hash_ut import TestHash from util.generic.hash_set_ut import TestHashSet from util.generic.list_ut import TestList -from util.generic.maybe_ut import TestMaybe +from util.generic.maybe_ut import TestMaybe from util.generic.ptr_ut import TestHolder from util.generic.string_ut import TestStroka -from util.generic.vector_ut import TestVector +from util.generic.vector_ut import TestVector from util.string.cast_ut import TestFromString, TestToString - -# Test discovery does not work in cython modules. -# Reexporting test classes here to satisfy pylint and pytest. - -__all__ = [ + +# Test discovery does not work in cython modules. +# Reexporting test classes here to satisfy pylint and pytest. + +__all__ = [ 'TestDeque', - 'TestHash', + 'TestHash', 'TestHashSet', 'TestHolder', 'TestList', - 'TestMaybe', - 'TestStroka', - 'TestVector', + 'TestMaybe', + 'TestStroka', + 'TestVector', 'TestFromString', 'TestToString', -] +] diff --git a/util/tests/cython/test_system.py b/util/tests/cython/test_system.py index 56c6aaecbd..923fb442e5 100644 --- a/util/tests/cython/test_system.py +++ b/util/tests/cython/test_system.py @@ -1,12 +1,12 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function, absolute_import, division - -from util.system.types_ut import TestTypes - -# Test discovery does not work in cython modules. -# Reexporting test classes here to satisfy pylint and pytest. - -__all__ = [ - 'TestTypes', -] +# -*- coding: utf-8 -*- + +from __future__ import print_function, absolute_import, division + +from util.system.types_ut import TestTypes + +# Test discovery does not work in cython modules. +# Reexporting test classes here to satisfy pylint and pytest. + +__all__ = [ + 'TestTypes', +] diff --git a/util/tests/cython/ya.make b/util/tests/cython/ya.make index 10c0267e2e..b928c19026 100644 --- a/util/tests/cython/ya.make +++ b/util/tests/cython/ya.make @@ -1,39 +1,39 @@ PY23_TEST() - + OWNER(g:util) SUBSCRIBER(g:util-subscribers) - -SRCDIR(util) - + +SRCDIR(util) + NO_WSHADOW() -PY_SRCS( +PY_SRCS( NAMESPACE util folder/path_ut.pyx generic/array_ref_ut.pyx generic/deque_ut.pyx - generic/maybe_ut.pyx + generic/maybe_ut.pyx generic/ptr_ut.pyx generic/string_ut.pyx - generic/vector_ut.pyx + generic/vector_ut.pyx generic/list_ut.pyx generic/hash_set_ut.pyx generic/hash_ut.pyx memory/blob_ut.pyx stream/str_ut.pyx string/cast_ut.pyx - system/types_ut.pyx + system/types_ut.pyx digest/multi_ut.pyx -) - -TEST_SRCS( +) + +TEST_SRCS( test_digest.py test_folder.py - test_generic.py + test_generic.py test_memory.py test_stream.py - test_system.py -) - -END() + test_system.py +) + +END() diff --git a/util/tests/ya.make b/util/tests/ya.make index 8310294548..e1e85c2931 100644 --- a/util/tests/ya.make +++ b/util/tests/ya.make @@ -1,6 +1,6 @@ RECURSE( benchmark - cython + cython fuzzing ut style diff --git a/util/ya.make b/util/ya.make index 22ec2cf21a..6ebe7e40cf 100644 --- a/util/ya.make +++ b/util/ya.make @@ -115,7 +115,7 @@ JOIN_SRCS( generic/mem_copy.cpp generic/noncopyable.cpp generic/object_counter.cpp - generic/overloaded.cpp + generic/overloaded.cpp generic/ptr.cpp generic/queue.cpp generic/refcount.cpp diff --git a/util/ysaveload.h b/util/ysaveload.h index 5f48a0d690..02efb4049b 100644 --- a/util/ysaveload.h +++ b/util/ysaveload.h @@ -10,8 +10,8 @@ #include <util/stream/input.h> #ifndef __NVCC__ - // cuda is compiled in C++14 mode at the time - #include <variant> + // cuda is compiled in C++14 mode at the time + #include <variant> #endif template <typename T> |