2
2
3
3
#include " column.h"
4
4
#include " numeric.h"
5
+ #include " utils.h"
5
6
6
7
#include < memory>
7
8
@@ -125,13 +126,8 @@ class ColumnArrayT : public ColumnArray {
125
126
* This is a static method to make such conversion verbose.
126
127
*/
127
128
static auto Wrap (ColumnArray&& col) {
128
- if constexpr (std::is_base_of_v<ColumnArray, NestedColumnType> && !std::is_same_v<ColumnArray, NestedColumnType>) {
129
- // assuming NestedColumnType is ArrayT specialization
130
- return std::make_shared<ColumnArrayT<NestedColumnType>>(NestedColumnType::Wrap (col.GetData ()), col.offsets_ );
131
- } else {
132
- auto nested_data = col.GetData ()->template AsStrict <NestedColumnType>();
133
- return std::make_shared<ColumnArrayT<NestedColumnType>>(nested_data, col.offsets_ );
134
- }
129
+ auto nested_data = WrapColumn<NestedColumnType>(col.GetData ());
130
+ return std::make_shared<ColumnArrayT<NestedColumnType>>(nested_data, col.offsets_ );
135
131
}
136
132
137
133
static auto Wrap (Column&& col) {
@@ -150,7 +146,7 @@ class ColumnArrayT : public ColumnArray {
150
146
const size_t size_;
151
147
152
148
public:
153
- using ValueType = typename NestedColumnType::ValueType ;
149
+ using ValueType = std:: decay_t <decltype(std::declval<NestedColumnType>().At( 0 ))> ;
154
150
155
151
ArrayValueView (std::shared_ptr<NestedColumnType> data, size_t offset = 0 , size_t size = std::numeric_limits<size_t >::max())
156
152
: typed_nested_data_(data)
@@ -175,14 +171,16 @@ class ColumnArrayT : public ColumnArray {
175
171
const size_t size_;
176
172
size_t index_;
177
173
public:
174
+ Iterator () = default ;
175
+
178
176
Iterator (std::shared_ptr<NestedColumnType> typed_nested_data, size_t offset, size_t size, size_t index)
179
177
: typed_nested_data_(typed_nested_data)
180
178
, offset_(offset)
181
179
, size_(size)
182
180
, index_(index)
183
181
{}
184
182
185
- using ValueType = typename NestedColumnType ::ValueType;
183
+ using ValueType = typename ArrayValueView ::ValueType;
186
184
187
185
inline auto operator *() const {
188
186
return typed_nested_data_->At (offset_ + index_);
@@ -230,6 +228,22 @@ class ColumnArrayT : public ColumnArray {
230
228
inline size_t Size () const {
231
229
return size_;
232
230
}
231
+
232
+ inline bool operator ==(const ArrayValueView& other) const {
233
+ if (size () != other.size ()) {
234
+ return false ;
235
+ }
236
+ for (size_t i = 0 ; i < size_; ++i) {
237
+ if ((*this )[i] != other[i]) {
238
+ return false ;
239
+ }
240
+ }
241
+ return true ;
242
+ }
243
+
244
+ inline bool operator !=(const ArrayValueView& other) const {
245
+ return !(*this == other);
246
+ }
233
247
};
234
248
235
249
inline auto At (size_t index) const {
@@ -262,7 +276,7 @@ class ColumnArrayT : public ColumnArray {
262
276
size_t counter = 0 ;
263
277
264
278
while (begin != end) {
265
- nested_data.Append (*begin);
279
+ nested_data.Append (std::move ( *begin) );
266
280
++begin;
267
281
++counter;
268
282
}
@@ -271,6 +285,20 @@ class ColumnArrayT : public ColumnArray {
271
285
AddOffset (counter);
272
286
}
273
287
288
+ ColumnRef Slice (size_t begin, size_t size) const override {
289
+ return Wrap (ColumnArray::Slice (begin, size));
290
+ }
291
+
292
+ ColumnRef CloneEmpty () const override {
293
+ return Wrap (ColumnArray::CloneEmpty ());
294
+ }
295
+
296
+ void Swap (Column& other) override {
297
+ auto & col = dynamic_cast <ColumnArrayT<NestedColumnType> &>(other);
298
+ typed_nested_data_.swap (col.typed_nested_data_ );
299
+ ColumnArray::Swap (other);
300
+ }
301
+
274
302
private:
275
303
// / Helper to allow wrapping a "typeless" ColumnArray
276
304
ColumnArrayT (ColumnArray&& array, std::shared_ptr<NestedColumnType> nested_data)
0 commit comments