Skip to content

Commit 8912222

Browse files
petrmikheevcopybara-github
authored andcommitted
Add constructor ValueBuffer(arolla::Buffer)
PiperOrigin-RevId: 714904434 Change-Id: I3773796c4146065be849305ff22cf5e0563d2681
1 parent 6c8ea18 commit 8912222

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

koladata/internal/value_array.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ using ::arolla::Unit;
5050
using ::arolla::bitmap::AlmostFullBuilder;
5151
using ::arolla::bitmap::Bitmap;
5252
using ::arolla::bitmap::Word;
53+
using ::arolla::view_type_t;
5354

5455
// Filters and remaps bitmap by given array of ObjectId.
5556
// The result is
@@ -122,13 +123,25 @@ class ValueBuffer : public absl::Span<T> {
122123
ValueBuffer(ValueBuffer&& other) : absl::Span<T>(other) {
123124
static_cast<absl::Span<T>&>(other) = absl::Span<T>(nullptr, 0);
124125
}
126+
127+
explicit ValueBuffer(const arolla::Buffer<T>& buf) : ValueBuffer(buf.size()) {
128+
if constexpr (!std::is_same_v<view_type_t<T>, T>) {
129+
for (int64_t i = 0; i < buf.size(); ++i) {
130+
(*this)[i] = buf[i];
131+
}
132+
} else {
133+
std::copy(buf.begin(), buf.end(), this->begin());
134+
}
135+
}
136+
125137
~ValueBuffer() { delete [] this->data(); }
126138
};
127139

128140
template <>
129141
class ValueBuffer<Unit> {
130142
public:
131143
explicit ValueBuffer(int64_t size) : size_(size) {}
144+
explicit ValueBuffer(const arolla::Buffer<Unit>& buf) : size_(buf.size()) {}
132145
int64_t size() const { return size_; }
133146
Unit operator[](int64_t offset) const { return Unit{}; }
134147
private:

0 commit comments

Comments
 (0)