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

Function createStringArray

test/include/arrow_test_utils.h:203–268  ·  view source on GitHub ↗

Helper to create a string array from vector

Source from the content-addressed store, hash-verified

201
202// Helper to create a string array from vector
203inline void createStringArray(ArrowArray* array, const std::vector<std::string>& data) {
204 struct ArrayPrivateData {
205 void* validity = nullptr;
206 void* data = nullptr;
207 int32_t* offsets = nullptr;
208 };
209
210 auto* private_data = new ArrayPrivateData();
211 private_data->validity = nullptr; // No nulls
212
213 // Calculate total string length
214 int32_t total_length = 0;
215 for (const auto& str : data) {
216 total_length += str.length();
217 }
218
219 // Create offsets buffer (n+1 offsets for n strings)
220 private_data->offsets = static_cast<int32_t*>(malloc((data.size() + 1) * sizeof(int32_t)));
221 private_data->offsets[0] = 0;
222 for (size_t i = 0; i < data.size(); i++) {
223 private_data->offsets[i + 1] = private_data->offsets[i] + data[i].length();
224 }
225
226 // Create data buffer
227 private_data->data = malloc(total_length);
228 char* data_ptr = static_cast<char*>(private_data->data);
229 for (const auto& str : data) {
230 memcpy(data_ptr, str.data(), str.length());
231 data_ptr += str.length();
232 }
233
234 array->length = data.size();
235 array->null_count = 0;
236 array->offset = 0;
237 array->n_buffers = 3; // validity, offsets, and data
238 array->n_children = 0;
239 array->buffers = static_cast<const void**>(malloc(sizeof(void*) * 3));
240 array->buffers[0] = nullptr; // validity buffer (no nulls)
241 array->buffers[1] = private_data->offsets;
242 array->buffers[2] = private_data->data;
243 array->children = nullptr;
244 array->dictionary = nullptr;
245 array->release = [](ArrowArray* a) {
246 if (a->private_data) {
247 auto* pd = static_cast<ArrayPrivateData*>(a->private_data);
248 free(pd->validity);
249 free(pd->data);
250 free(pd->offsets);
251 delete pd;
252 }
253 if (a->buffers) {
254 free(const_cast<void**>(a->buffers));
255 }
256 if (a->children) {
257 for (int64_t i = 0; i < a->n_children; i++) {
258 if (a->children[i]->release) {
259 a->children[i]->release(a->children[i]);
260 }

Callers 15

makeSimplePersonArraysFunction · 0.85
TEST_FFunction · 0.85
makeUserBatchFunction · 0.85
makeCityBatchFunction · 0.85
makeFollowsBatchFunction · 0.85
makePersonBatchFunction · 0.85
makeCityBatchFunction · 0.85
makeKnowsBatchFunction · 0.85
createArrowPersonTableFunction · 0.85
makeCsrNodeBatchFunction · 0.85
makeCsrEdgeBatchFunction · 0.85
TEST_FFunction · 0.85

Calls 4

lengthMethod · 0.80
releaseMethod · 0.80
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected