aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/containers/bitseq/readonly_bitvector.h
diff options
context:
space:
mode:
authorIvan Komarov <Ivan.Komarov@dfyz.info>2022-02-10 16:46:48 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:48 +0300
commit4de97ab2fe437cbe83e4c63234e809ddd5ac34f2 (patch)
treeff8fb38b661955e6c99d1d000d6c72f739199590 /library/cpp/containers/bitseq/readonly_bitvector.h
parent9abfb1a53b7f7b791444d1378e645d8fad9b06ed (diff)
downloadydb-4de97ab2fe437cbe83e4c63234e809ddd5ac34f2.tar.gz
Restoring authorship annotation for Ivan Komarov <Ivan.Komarov@dfyz.info>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/containers/bitseq/readonly_bitvector.h')
-rw-r--r--library/cpp/containers/bitseq/readonly_bitvector.h136
1 files changed, 68 insertions, 68 deletions
diff --git a/library/cpp/containers/bitseq/readonly_bitvector.h b/library/cpp/containers/bitseq/readonly_bitvector.h
index 8612739c3f..bed2cfc061 100644
--- a/library/cpp/containers/bitseq/readonly_bitvector.h
+++ b/library/cpp/containers/bitseq/readonly_bitvector.h
@@ -1,76 +1,76 @@
-#pragma once
-
-#include "bitvector.h"
-#include "traits.h"
-
-#include <util/memory/blob.h>
-
-#include <cstring>
-
-template <typename T>
-class TReadonlyBitVector {
-public:
- using TWord = T;
- using TTraits = TBitSeqTraits<TWord>;
-
- TReadonlyBitVector()
- : Size_()
- , Data_()
+#pragma once
+
+#include "bitvector.h"
+#include "traits.h"
+
+#include <util/memory/blob.h>
+
+#include <cstring>
+
+template <typename T>
+class TReadonlyBitVector {
+public:
+ using TWord = T;
+ using TTraits = TBitSeqTraits<TWord>;
+
+ TReadonlyBitVector()
+ : Size_()
+ , Data_()
{
}
-
+
explicit TReadonlyBitVector(const TBitVector<T>& vector)
: Size_(vector.Size_)
, Data_(vector.Data_.data())
{
}
- bool Test(ui64 pos) const {
- return TTraits::Test(Data_, pos, Size_);
- }
-
- TWord Get(ui64 pos, ui8 width, TWord mask) const {
- return TTraits::Get(Data_, pos, width, mask, Size_);
- }
-
- TWord Get(ui64 pos, ui8 width) const {
- return Get(pos, width, TTraits::ElemMask(width));
- }
-
- ui64 Size() const {
- return Size_;
- }
-
- const T* Data() const {
- return Data_;
- }
-
- static void SaveForReadonlyAccess(IOutputStream* out, const TBitVector<T>& bv) {
- ::Save(out, bv.Size_);
- ::Save(out, static_cast<ui64>(bv.Data_.size()));
- ::SavePodArray(out, bv.Data_.data(), bv.Data_.size());
- }
-
- virtual TBlob LoadFromBlob(const TBlob& blob) {
- size_t read = 0;
- auto cursor = [&]() { return blob.AsUnsignedCharPtr() + read; };
- auto readToPtr = [&](auto* ptr) {
- memcpy(ptr, cursor(), sizeof(*ptr));
- read += sizeof(*ptr);
- };
-
- readToPtr(&Size_);
-
- ui64 wordCount{};
- readToPtr(&wordCount);
-
- Data_ = reinterpret_cast<const T*>(cursor());
- read += wordCount * sizeof(T);
-
- return blob.SubBlob(read, blob.Size());
- }
-
-private:
- ui64 Size_;
- const T* Data_;
-};
+ bool Test(ui64 pos) const {
+ return TTraits::Test(Data_, pos, Size_);
+ }
+
+ TWord Get(ui64 pos, ui8 width, TWord mask) const {
+ return TTraits::Get(Data_, pos, width, mask, Size_);
+ }
+
+ TWord Get(ui64 pos, ui8 width) const {
+ return Get(pos, width, TTraits::ElemMask(width));
+ }
+
+ ui64 Size() const {
+ return Size_;
+ }
+
+ const T* Data() const {
+ return Data_;
+ }
+
+ static void SaveForReadonlyAccess(IOutputStream* out, const TBitVector<T>& bv) {
+ ::Save(out, bv.Size_);
+ ::Save(out, static_cast<ui64>(bv.Data_.size()));
+ ::SavePodArray(out, bv.Data_.data(), bv.Data_.size());
+ }
+
+ virtual TBlob LoadFromBlob(const TBlob& blob) {
+ size_t read = 0;
+ auto cursor = [&]() { return blob.AsUnsignedCharPtr() + read; };
+ auto readToPtr = [&](auto* ptr) {
+ memcpy(ptr, cursor(), sizeof(*ptr));
+ read += sizeof(*ptr);
+ };
+
+ readToPtr(&Size_);
+
+ ui64 wordCount{};
+ readToPtr(&wordCount);
+
+ Data_ = reinterpret_cast<const T*>(cursor());
+ read += wordCount * sizeof(T);
+
+ return blob.SubBlob(read, blob.Size());
+ }
+
+private:
+ ui64 Size_;
+ const T* Data_;
+};