#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
typedef struct ArrowArray {
int64_t length;
int64_t null_count;
int64_t offset;
int64_t n_buffers;
int64_t n_children;
const void **buffers;
struct ArrowArray **children;
struct ArrowArray *dictionary;
void (*release)(struct ArrowArray*);
void *private_data;
} ArrowArray;
typedef struct ArrowSchema
{
const char* format;
const char* name;
const char* metadata;
int64_t flags;
int64_t n_children;
struct ArrowSchema** children;
struct ArrowSchema* dictionary;
void (*release)(struct ArrowSchema*);
void* private_data;
} ArrowSchema;
static int bitmap_lsb_is_set(const uint8_t* bm, size_t idx)
{
return (bm[idx >> 3] >> (idx & 7)) & 1;
}
int c_arrow_check_i32(const ArrowArray* arr)
{
if (!arr || arr->n_buffers != 2 || arr->length != 3) return 0;
const int32_t* v = (const int32_t*)arr->buffers[1];
return v && v[0]==11 && v[1]==22 && v[2]==33;
}
int c_arrow_check_i64(const ArrowArray* a)
{
if (!a || a->n_buffers!=2 || a->length!=3) return 0;
const int64_t* v = (const int64_t*)a->buffers[1];
return v && v[0]==1001 && v[1]==-42 && v[2]==777;
}
int c_arrow_check_u32(const ArrowArray* a)
{
if (!a || a->n_buffers!=2 || a->length!=3) return 0;
const uint32_t* v = (const uint32_t*)a->buffers[1];
return v && v[0]==1 && v[1]==2 && v[2]==3;
}
int c_arrow_check_f32(const ArrowArray* a)
{
if (!a || a->n_buffers!=2 || a->length!=3) return 0;
const float* v = (const float*)a->buffers[1];
return v && v[0]==1.5f && v[1]==-2.0f && v[2]==3.25f;
}
int c_arrow_check_f64(const ArrowArray* a)
{
if (!a || a->n_buffers!=2 || a->length!=3) return 0;
const double* v = (const double*)a->buffers[1];
return v && v[0]==0.1 && v[1]==0.2 && v[2]==0.3;
}
int c_arrow_check_bool(const ArrowArray* a)
{
if (!a || a->n_buffers!=2 || a->length!=3) return 0;
const uint8_t* data = (const uint8_t*)a->buffers[1];
return data && data[0]==0x05;
}
int c_arrow_check_str(const ArrowArray* a)
{
if (!a || a->n_buffers!=3 || a->length!=2) return 0;
const uint32_t* offs = (const uint32_t*)a->buffers[1];
const uint8_t* vals = (const uint8_t*) a->buffers[2];
return vals && offs && offs[0]==0 && offs[1]==3 && offs[2]==6
&& memcmp(vals,"foobar",6)==0;
}
int c_arrow_check_i32_null(const ArrowArray* a)
{
if (!a || a->n_buffers!=2 || a->length!=3) return 0;
const uint8_t* bitmap = (const uint8_t*)a->buffers[0];
if (!bitmap || bitmap_lsb_is_set(bitmap,0)==0 || bitmap_lsb_is_set(bitmap,1)!=0
|| bitmap_lsb_is_set(bitmap,2)==0) return 0;
const int32_t* v = (const int32_t*)a->buffers[1];
return v && v[0]==42 && v[2]==88;
}
int c_arrow_check_dict32(const ArrowArray* a)
{
if (!a || a->n_buffers != 2 || a->length != 3) return 0;
const uint32_t* codes = (const uint32_t*)a->buffers[1];
if (!codes || codes[0] != 0 || codes[1] != 1 || codes[2] != 0) return 0;
const ArrowArray* dict = a->dictionary;
if (!dict || dict->n_buffers != 3 || dict->length != 2) return 0;
const uint32_t* offs = (const uint32_t*)dict->buffers[1];
const uint8_t* vals = (const uint8_t*) dict->buffers[2];
if (!offs || !vals) return 0;
if (offs[0] != 0 || offs[1] != 1 || offs[2] != 2) return 0;
if (!(vals[0] == 'A' && vals[1] == 'B')) return 0;
return 1;
}
int c_arrow_check_dt64(const ArrowArray* a)
{
if (!a || a->n_buffers!=2 || a->length!=2) return 0;
const int64_t* v = (const int64_t*)a->buffers[1];
return v && v[0]==1 && v[1]==2;
}
int c_arrow_check_schema(const ArrowSchema* schema, const char* expected_name, const char* expected_format)
{
if (!schema || !schema->name || !schema->format)
return 0;
if (strcmp(schema->name, expected_name) != 0)
return 0;
if (strcmp(schema->format, expected_format) != 0)
return 0;
return 1;
}