MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / createDoubleArray

Function createDoubleArray

test/include/arrow_test_utils.h:271–316  ·  view source on GitHub ↗

Helper to create a double array from vector

Source from the content-addressed store, hash-verified

269
270// Helper to create a double array from vector
271inline void createDoubleArray(ArrowArray* array, const std::vector<double>& data) {
272 struct ArrayPrivateData {
273 void* validity = nullptr;
274 void* data = nullptr;
275 int32_t* offsets = nullptr;
276 };
277
278 auto* private_data = new ArrayPrivateData();
279 private_data->validity = nullptr; // No nulls
280 private_data->data = malloc(data.size() * sizeof(double));
281 memcpy(private_data->data, data.data(), data.size() * sizeof(double));
282
283 array->length = data.size();
284 array->null_count = 0;
285 array->offset = 0;
286 array->n_buffers = 2; // validity and data
287 array->n_children = 0;
288 array->buffers = static_cast<const void**>(malloc(sizeof(void*) * 2));
289 array->buffers[0] = nullptr; // validity buffer (no nulls)
290 array->buffers[1] = private_data->data;
291 array->children = nullptr;
292 array->dictionary = nullptr;
293 array->release = [](ArrowArray* a) {
294 if (a->private_data) {
295 auto* pd = static_cast<ArrayPrivateData*>(a->private_data);
296 free(pd->validity);
297 free(pd->data);
298 free(pd->offsets);
299 delete pd;
300 }
301 if (a->buffers) {
302 free(const_cast<void**>(a->buffers));
303 }
304 if (a->children) {
305 for (int64_t i = 0; i < a->n_children; i++) {
306 if (a->children[i]->release) {
307 a->children[i]->release(a->children[i]);
308 }
309 free(a->children[i]);
310 }
311 free(a->children);
312 }
313 a->release = nullptr;
314 };
315 array->private_data = private_data;
316}
317
318template<>
319inline void createSchema<uint64_t>(ArrowSchema* schema, const char* name) {

Callers 2

TEST_FFunction · 0.85
TEST_FFunction · 0.85

Calls 3

releaseMethod · 0.80
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected