diff options
author | dimko <dimko@yandex-team.ru> | 2022-02-10 16:50:07 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:07 +0300 |
commit | 811ece47d06924d20a94f89d1b0f5cd37254a49c (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /util/generic | |
parent | 5df1bbceafd25528f800dbe399738150b20384f3 (diff) | |
download | ydb-811ece47d06924d20a94f89d1b0f5cd37254a49c.tar.gz |
Restoring authorship annotation for <dimko@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/generic')
-rw-r--r-- | util/generic/bitmap.h | 56 | ||||
-rw-r--r-- | util/generic/bitmap_ut.cpp | 82 | ||||
-rw-r--r-- | util/generic/strbase.h | 4 |
3 files changed, 71 insertions, 71 deletions
diff --git a/util/generic/bitmap.h b/util/generic/bitmap.h index 09f66b4b37..f77d182460 100644 --- a/util/generic/bitmap.h +++ b/util/generic/bitmap.h @@ -310,7 +310,7 @@ struct TDynamicBitMapTraits { template <class TTraits> class TBitMapOps { -public: +public: using TChunk = typename TTraits::TChunk; using TThis = TBitMapOps<TTraits>; @@ -417,21 +417,21 @@ private: public: TBitMapOps() = default; - + TBitMapOps(TChunk val) { Mask.Data[0] = val; Mask.Sanitize(); - } - + } + TBitMapOps(const TThis&) = default; - + template <class T> TBitMapOps(const TBitMapOps<T>& bitmap) : Mask(bitmap.Mask.Data, bitmap.Mask.GetChunkCapacity()) { Mask.Sanitize(); - } - + } + template <class T> Y_FORCE_INLINE bool operator==(const TBitMapOps<T>& bitmap) const { return Equal(bitmap); @@ -589,19 +589,19 @@ public: } Y_FORCE_INLINE bool Test(size_t n) const { - return Get(n); - } - + return Get(n); + } + Y_FORCE_INLINE TThis& Push(bool val) { LShift(1); return val ? Set(0) : *this; - } - + } + Y_FORCE_INLINE bool Pop() { bool val = Get(0); return RShift(1), val; - } - + } + // Clear entire bitmap. Current capacity is kept unchanged Y_FORCE_INLINE TThis& Clear() { for (size_t i = 0; i < Mask.GetChunkCapacity(); ++i) { @@ -685,13 +685,13 @@ public: for (size_t i = bitmap.Mask.GetChunkCapacity(); i < Mask.GetChunkCapacity(); ++i) Mask.Data[i] = 0; return *this; - } - + } + template <class T> Y_FORCE_INLINE TThis& And(const TBitMapOps<T>& bitmap) { return And(TThis(bitmap)); - } - + } + Y_FORCE_INLINE TThis& And(const TChunk& val) { Mask.Data[0] &= val; for (size_t i = 1; i < Mask.GetChunkCapacity(); ++i) @@ -911,7 +911,7 @@ public: return l.Compare(r); } - size_t FirstNonZeroBit() const { + size_t FirstNonZeroBit() const { for (size_t i = 0; i < Mask.GetChunkCapacity(); ++i) { if (Mask.Data[i]) { // CountTrailingZeroBits() expects unsigned types not smaller than unsigned int. So, convert before calling @@ -937,26 +937,26 @@ public: const TChunk val = Mask.Data[i] & ((~TChunk(0)) << offset); if (val) { return BitsPerChunk * i + CountTrailingZeroBits(TIntType(val)); - } + } // Continue with other chunks ++i; - } + } for (; i < Mask.GetChunkCapacity(); ++i) { if (Mask.Data[i]) { return BitsPerChunk * i + CountTrailingZeroBits(TIntType(Mask.Data[i])); } } - } + } return Size(); - } - + } + Y_FORCE_INLINE size_t Count() const { - size_t count = 0; + size_t count = 0; for (size_t i = 0; i < Mask.GetChunkCapacity(); ++i) count += ::NBitMapPrivate::CountBitsPrivate(Mask.Data[i]); - return count; - } + return count; + } void Save(IOutputStream* out) const { ::Save(out, ui8(sizeof(TChunk))); @@ -1008,7 +1008,7 @@ public: constexpr size_t GetChunkCount() const noexcept { return Mask.GetChunkCapacity(); } -}; +}; template <class X, class Y> inline TBitMapOps<X> operator&(const TBitMapOps<X>& x, const TBitMapOps<Y>& y) { diff --git a/util/generic/bitmap_ut.cpp b/util/generic/bitmap_ut.cpp index 9cf0cc33a1..087d34a8dc 100644 --- a/util/generic/bitmap_ut.cpp +++ b/util/generic/bitmap_ut.cpp @@ -1,7 +1,7 @@ #include "bitmap.h" #include <library/cpp/testing/unittest/registar.h> - + #define INIT_BITMAP(bitmap, bits) \ for (size_t i = 0; i < sizeof(bits) / sizeof(size_t); ++i) { \ bitmap.Set(bits[i]); \ @@ -40,23 +40,23 @@ Y_UNIT_TEST_SUITE(TBitMapTest) { Y_UNIT_TEST(TestBitMap) { TBitMap<101> bitmap; - + UNIT_ASSERT_EQUAL(bitmap.Size(), 101); - UNIT_ASSERT_EQUAL(bitmap.Count(), 0); - UNIT_ASSERT_EQUAL(bitmap.FirstNonZeroBit(), 101); - + UNIT_ASSERT_EQUAL(bitmap.Count(), 0); + UNIT_ASSERT_EQUAL(bitmap.FirstNonZeroBit(), 101); + size_t initBits[] = {0, 50, 100, 45}; INIT_BITMAP(bitmap, initBits); - bitmap.Reset(45); - - UNIT_ASSERT_EQUAL(bitmap.FirstNonZeroBit(), 0); + bitmap.Reset(45); + + UNIT_ASSERT_EQUAL(bitmap.FirstNonZeroBit(), 0); size_t setBits[] = {0, 50, 100}; CHECK_BITMAP(bitmap, setBits); - + for (size_t i = 0; i < bitmap.Size(); ++i) { UNIT_ASSERT_EQUAL(bitmap.Get(i), bitmap.Test(i)); } - + UNIT_ASSERT_EQUAL(bitmap.Count(), 3); bitmap.Reset(0); @@ -87,51 +87,51 @@ Y_UNIT_TEST_SUITE(TBitMapTest) { CHECK_BITMAP(bitmap, setBits); for (size_t i = 0; i < bitmap.Size(); ++i) { - UNIT_ASSERT_EQUAL(bitmap.Get(i), bitmap.Test(i)); + UNIT_ASSERT_EQUAL(bitmap.Get(i), bitmap.Test(i)); } - - UNIT_ASSERT_EQUAL(bitmap.Count(), 3); - - bitmap.Reset(0); - - UNIT_ASSERT_EQUAL(bitmap.FirstNonZeroBit(), 50); - - bitmap.Clear(); - - UNIT_ASSERT_EQUAL(bitmap.Count(), 0); + + UNIT_ASSERT_EQUAL(bitmap.Count(), 3); + + bitmap.Reset(0); + + UNIT_ASSERT_EQUAL(bitmap.FirstNonZeroBit(), 50); + + bitmap.Clear(); + + UNIT_ASSERT_EQUAL(bitmap.Count(), 0); UNIT_ASSERT_EQUAL(bitmap.Empty(), true); - } - + } + template <class TBitMapImpl> void TestAndImpl() { TBitMapImpl bitmap1; TBitMapImpl bitmap2; - + size_t initBits1[] = {10, 20, 50, 100}; size_t initBits2[] = {10, 11, 22, 50}; INIT_BITMAP(bitmap1, initBits1); INIT_BITMAP(bitmap2, initBits2); - bitmap1.And(bitmap2); - - UNIT_ASSERT_EQUAL(bitmap1.Count(), 2); - UNIT_ASSERT_EQUAL(bitmap2.Count(), 4); - + bitmap1.And(bitmap2); + + UNIT_ASSERT_EQUAL(bitmap1.Count(), 2); + UNIT_ASSERT_EQUAL(bitmap2.Count(), 4); + size_t resBits[] = {10, 50}; - + CHECK_BITMAP(bitmap1, resBits); CHECK_BITMAP(bitmap2, initBits2); - } - + } + Y_UNIT_TEST(TestAndFixed) { TestAndImpl<TBitMap<101>>(); } - + Y_UNIT_TEST(TestAndDyn) { TestAndImpl<TDynBitMap>(); } - + template <class TBitMapImpl> void TestOrImpl() { TBitMapImpl bitmap1; @@ -143,13 +143,13 @@ Y_UNIT_TEST_SUITE(TBitMapTest) { INIT_BITMAP(bitmap1, initBits1); INIT_BITMAP(bitmap2, initBits2); - bitmap1.Or(bitmap2); - - UNIT_ASSERT_EQUAL(bitmap1.Count(), 7); - UNIT_ASSERT_EQUAL(bitmap2.Count(), 4); - + bitmap1.Or(bitmap2); + + UNIT_ASSERT_EQUAL(bitmap1.Count(), 7); + UNIT_ASSERT_EQUAL(bitmap2.Count(), 4); + size_t resBits[] = {0, 1, 10, 11, 22, 50, 76}; - + CHECK_BITMAP(bitmap1, resBits); CHECK_BITMAP(bitmap2, initBits2); @@ -548,7 +548,7 @@ Y_UNIT_TEST_SUITE(TBitMapTest) { bitmapDynamic.Set(128); UNIT_ASSERT_UNEQUAL(bitmapFixed.Hash(), bitmapDynamic.Hash()); } - + Y_UNIT_TEST(TestSetResetRange) { // Single chunk using TBitMap1Chunk = TBitMap<64>; diff --git a/util/generic/strbase.h b/util/generic/strbase.h index 27ebcb81fa..ab39fc7537 100644 --- a/util/generic/strbase.h +++ b/util/generic/strbase.h @@ -35,7 +35,7 @@ namespace NStringPrivate { } template <typename TDerived, typename TCharType, typename TTraitsType = std::char_traits<TCharType>> -class TStringBase { +class TStringBase { using TStringView = std::basic_string_view<TCharType>; using TStringViewWithTraits = std::basic_string_view<TCharType, TTraitsType>; @@ -43,7 +43,7 @@ public: using TChar = TCharType; using TTraits = TTraitsType; using TSelf = TStringBase<TDerived, TChar, TTraits>; - + using size_type = size_t; using difference_type = ptrdiff_t; static constexpr size_t npos = size_t(-1); |