diff options
author | dmikhalev <dmikhalev@yandex-team.ru> | 2022-02-10 16:49:29 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:29 +0300 |
commit | b93b3eb857a34bc32cef3c1b0c709e8365253b34 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /util/generic | |
parent | 3b5ee31ed70f690af39dfdec632060610b71b89e (diff) | |
download | ydb-b93b3eb857a34bc32cef3c1b0c709e8365253b34.tar.gz |
Restoring authorship annotation for <dmikhalev@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/generic')
-rw-r--r-- | util/generic/bitmap.h | 52 | ||||
-rw-r--r-- | util/generic/bitmap_ut.cpp | 28 |
2 files changed, 40 insertions, 40 deletions
diff --git a/util/generic/bitmap.h b/util/generic/bitmap.h index 565d86c2d1..f77d182460 100644 --- a/util/generic/bitmap.h +++ b/util/generic/bitmap.h @@ -566,28 +566,28 @@ public: } template <class TTo> - void Export(size_t pos, TTo& to) const { + void Export(size_t pos, TTo& to) const { static_assert(std::is_unsigned<TTo>::value, "expect std::is_unsigned<TTo>::value"); - to = 0; - size_t chunkpos = pos >> DivCount; - if (chunkpos >= Mask.GetChunkCapacity()) - return; - if ((pos & ModMask) == 0) { - if (sizeof(TChunk) >= sizeof(TTo)) - to = (TTo)Mask.Data[chunkpos]; - else //if (sizeof(TChunk) < sizeof(TTo)) - NBitMapPrivate::CopyData(&to, 1, Mask.Data + chunkpos, Min(((sizeof(TTo) * 8) >> DivCount), Mask.GetChunkCapacity() - chunkpos)); - } else if ((pos & (sizeof(TTo) * 8 - 1)) == 0 && sizeof(TChunk) >= 2 * sizeof(TTo)) - to = (TTo)(Mask.Data[chunkpos] >> (pos & ModMask)); - else { + to = 0; + size_t chunkpos = pos >> DivCount; + if (chunkpos >= Mask.GetChunkCapacity()) + return; + if ((pos & ModMask) == 0) { + if (sizeof(TChunk) >= sizeof(TTo)) + to = (TTo)Mask.Data[chunkpos]; + else //if (sizeof(TChunk) < sizeof(TTo)) + NBitMapPrivate::CopyData(&to, 1, Mask.Data + chunkpos, Min(((sizeof(TTo) * 8) >> DivCount), Mask.GetChunkCapacity() - chunkpos)); + } else if ((pos & (sizeof(TTo) * 8 - 1)) == 0 && sizeof(TChunk) >= 2 * sizeof(TTo)) + to = (TTo)(Mask.Data[chunkpos] >> (pos & ModMask)); + else { static constexpr size_t copyToSize = (sizeof(TChunk) >= sizeof(TTo)) ? (sizeof(TChunk) / sizeof(TTo)) + 2 : 3; - TTo temp[copyToSize] = {0, 0}; - //or use non defined by now TBitmap<copyToSize, TTo>::CopyData,RShift(pos & ModMask),Export(0,to) - NBitMapPrivate::CopyData(temp, copyToSize, Mask.Data + chunkpos, Min((sizeof(TTo) / sizeof(TChunk)) + 1, Mask.GetChunkCapacity() - chunkpos)); - to = (temp[0] >> (pos & ModMask)) | (temp[1] << (8 * sizeof(TTo) - (pos & ModMask))); - } - } - + TTo temp[copyToSize] = {0, 0}; + //or use non defined by now TBitmap<copyToSize, TTo>::CopyData,RShift(pos & ModMask),Export(0,to) + NBitMapPrivate::CopyData(temp, copyToSize, Mask.Data + chunkpos, Min((sizeof(TTo) / sizeof(TChunk)) + 1, Mask.GetChunkCapacity() - chunkpos)); + to = (temp[0] >> (pos & ModMask)) | (temp[1] << (8 * sizeof(TTo) - (pos & ModMask))); + } + } + Y_FORCE_INLINE bool Test(size_t n) const { return Get(n); } @@ -608,8 +608,8 @@ public: Mask.Data[i] = 0; } return *this; - } - + } + // Returns bits capacity Y_FORCE_INLINE constexpr size_t Size() const noexcept { return Mask.GetBitCapacity(); @@ -631,10 +631,10 @@ public: Y_PURE_FUNCTION Y_FORCE_INLINE bool Empty() const { for (size_t i = 0; i < Mask.GetChunkCapacity(); ++i) if (Mask.Data[i]) - return false; - return true; - } - + return false; + return true; + } + bool HasAny(const TThis& bitmap) const { for (size_t i = 0; i < Min(Mask.GetChunkCapacity(), bitmap.Mask.GetChunkCapacity()); ++i) { if (0 != (Mask.Data[i] & bitmap.Mask.Data[i])) { diff --git a/util/generic/bitmap_ut.cpp b/util/generic/bitmap_ut.cpp index de3fedbc0a..087d34a8dc 100644 --- a/util/generic/bitmap_ut.cpp +++ b/util/generic/bitmap_ut.cpp @@ -264,25 +264,25 @@ Y_UNIT_TEST_SUITE(TBitMapTest) { TDynBitMap bitmap4 = ~((bitmap3 | 3) & bitmap2); CHECK_BITMAP_WITH_TAIL(bitmap4, resBits); - - TBitMap<128, ui32> expmap; - expmap.Set(47); - expmap.Set(90); - ui64 tst1 = 0; - ui32 tst2 = 0; - ui16 tst3 = 0; - expmap.Export(32, tst1); + + TBitMap<128, ui32> expmap; + expmap.Set(47); + expmap.Set(90); + ui64 tst1 = 0; + ui32 tst2 = 0; + ui16 tst3 = 0; + expmap.Export(32, tst1); UNIT_ASSERT_EQUAL(tst1, (1 << 15) | (((ui64)1) << 58)); - expmap.Export(32, tst2); + expmap.Export(32, tst2); UNIT_ASSERT_EQUAL(tst2, (1 << 15)); - expmap.Export(32, tst3); + expmap.Export(32, tst3); UNIT_ASSERT_EQUAL(tst3, (1 << 15)); - - expmap.Export(33, tst1); + + expmap.Export(33, tst1); UNIT_ASSERT_EQUAL(tst1, (1 << 14) | (((ui64)1) << 57)); - expmap.Export(33, tst2); + expmap.Export(33, tst2); UNIT_ASSERT_EQUAL(tst2, (1 << 14)); - expmap.Export(33, tst3); + expmap.Export(33, tst3); UNIT_ASSERT_EQUAL(tst3, (1 << 14)); } |