Added tuple columns containing immutable indexed data arrays of any type

This commit is contained in:
Celine Mercier
2017-11-15 13:48:59 +01:00
parent 1684f96b79
commit 9a50803c00
32 changed files with 1097 additions and 284 deletions

73
src/array_indexer.c Normal file
View File

@ -0,0 +1,73 @@
/****************************************************************************
* Array indexing functions *
****************************************************************************/
/**
* @file array_indexer.c
* @author Celine Mercier
* @date October 5th 2017
* @brief Functions handling the indexing and retrieval of arrays of any type.
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include "obiblob.h"
#include "obiblob_indexer.h"
#include "obidebug.h"
#include "obitypes.h"
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
index_t obi_index_array(Obi_indexer_p indexer, const void* value, uint8_t elt_size, int value_length)
{
Obi_blob_p value_b;
index_t idx;
int32_t length_bytes;
// fprintf(stderr, "\nelt size in C: %u", elt_size);
// for (int i=0; i<value_length; i++)
// fprintf(stderr, "\nvalue %d", ((obibool_t*)value)[i]);
length_bytes = value_length * elt_size;
// Encode value
value_b = obi_blob((byte_t*)value, elt_size, length_bytes, length_bytes);
if (value_b == NULL)
return -1;
// for (int i=0; i<value_length; i++)
// fprintf(stderr, "\nin blob: value %d", ((obibool_t*)(value_b->value))[i]);
// Add in the indexer
idx = obi_indexer_add(indexer, value_b);
free(value_b);
return idx;
}
const void* obi_retrieve_array(Obi_indexer_p indexer, index_t idx, int* value_length_p)
{
Obi_blob_p value_b;
// Get encoded value
value_b = obi_indexer_get(indexer, idx);
// Store array length
*value_length_p = (value_b->length_decoded_value) / (value_b->element_size);
// for (int i=0; i<*value_length_p; i++)
// fprintf(stderr, "\nvalue %d", ((obibool_t*)(value_b->value))[i]);
// Return pointer on mapped array
return ((void*) (value_b->value));
}