Character string indexer API

This commit is contained in:
Celine Mercier
2016-04-12 17:21:01 +02:00
parent 04c9470f7d
commit 5ec2d8842e
14 changed files with 165 additions and 80 deletions

View File

@ -18,7 +18,7 @@
#include "obitypes.h"
#include "obierrno.h"
#include "obidebug.h"
#include "obiblob_indexer.h"
#include "char_str_indexer.h"
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
@ -32,7 +32,6 @@
int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value)
{
Obi_blob_p value_b;
index_t idx;
// Check that the line number is not greater than the maximum allowed
@ -55,21 +54,14 @@ int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb,
if ((line_nb+1) > (column->header)->lines_used)
(column->header)->lines_used = line_nb+1;
// Encode the value on a byte array with a header
value_b = obi_str_to_blob(value);
if (value_b == NULL)
return -1;
// Add in the indexer
idx = obi_indexer_add(column->indexer, value_b);
idx = obi_index_char_str(column->indexer, value);
if (idx == -1)
return -1;
// Add the value's index in the column
*(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = idx;
free(value_b);
return 0;
}
@ -104,17 +96,13 @@ int obi_column_set_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p c
return -1;
}
if (obi_column_set_obistr_with_elt_idx(column, line_nb, element_idx, value) < 0)
return -1;
return 0;
return obi_column_set_obistr_with_elt_idx(column, line_nb, element_idx, value);
}
const char* obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
{
index_t idx;
Obi_blob_p value_b;
if ((line_nb+1) > ((column->header)->line_count))
{
@ -129,9 +117,7 @@ const char* obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, index_t l
if (idx == OBIIdx_NA)
return OBIStr_NA;
value_b = obi_indexer_get(column->indexer, idx);
return obi_blob_to_str(value_b);
return obi_retrieve_char_str(column->indexer, idx);
}
@ -157,8 +143,7 @@ int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb,
element_idx = obi_column_get_element_index_from_name(column, element_name);
if (element_idx == OBIIdx_NA)
return -1;
obi_column_set_obistr_with_elt_idx(column, line_nb, element_idx, value);
return 0;
return obi_column_set_obistr_with_elt_idx(column, line_nb, element_idx, value);
}
@ -168,8 +153,7 @@ int obi_column_set_obistr_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p
element_idx = obi_column_get_element_index_from_name(column, element_name);
if (element_idx == OBIIdx_NA)
return -1;
obi_column_set_obistr_with_elt_idx_in_view(view, column, line_nb, element_idx, value);
return 0;
return obi_column_set_obistr_with_elt_idx_in_view(view, column, line_nb, element_idx, value);
}