Finished moving obiblob functions to obiblob files and documentation for
obiblob functions
This commit is contained in:
14
src/obiavl.c
14
src/obiavl.c
@ -951,7 +951,7 @@ int add_new_avl_in_group(OBIDMS_avl_group_p avl_group)
|
|||||||
|
|
||||||
int maybe_in_avl(OBIDMS_avl_p avl, Obi_blob_p value)
|
int maybe_in_avl(OBIDMS_avl_p avl, Obi_blob_p value)
|
||||||
{
|
{
|
||||||
return (bloom_check(&((avl->header)->bloom_filter), value, blob_sizeof(value)));
|
return (bloom_check(&((avl->header)->bloom_filter), value, obi_blob_sizeof(value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -963,7 +963,7 @@ index_t avl_add_value_in_data_array(OBIDMS_avl_p avl, Obi_blob_p value)
|
|||||||
value_idx = ((avl->data)->header)->data_size_used;
|
value_idx = ((avl->data)->header)->data_size_used;
|
||||||
|
|
||||||
// Grow the data if needed
|
// Grow the data if needed
|
||||||
value_size = blob_sizeof(value);
|
value_size = obi_blob_sizeof(value);
|
||||||
while (((avl->data)->header)->data_size_max < (value_idx + value_size))
|
while (((avl->data)->header)->data_size_max < (value_idx + value_size))
|
||||||
{
|
{
|
||||||
if (grow_avl_data(avl->data) < 0)
|
if (grow_avl_data(avl->data) < 0)
|
||||||
@ -1978,7 +1978,7 @@ index_t obi_avl_add(OBIDMS_avl_p avl, Obi_blob_p value)
|
|||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
depth = 0;
|
depth = 0;
|
||||||
crc = crc64((byte_t*)value, blob_sizeof(value));
|
crc = crc64((byte_t*)value, obi_blob_sizeof(value));
|
||||||
|
|
||||||
// Check if first node
|
// Check if first node
|
||||||
if (!((avl->header)->nb_items))
|
if (!((avl->header)->nb_items))
|
||||||
@ -2025,7 +2025,7 @@ index_t obi_avl_add(OBIDMS_avl_p avl, Obi_blob_p value)
|
|||||||
if (comp == 0)
|
if (comp == 0)
|
||||||
{ // check if really same value
|
{ // check if really same value
|
||||||
to_compare = obi_avl_get(avl, current_node->value);
|
to_compare = obi_avl_get(avl, current_node->value);
|
||||||
comp = blob_compare(to_compare, value);
|
comp = obi_blob_compare(to_compare, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (comp > 0)
|
if (comp > 0)
|
||||||
@ -2107,7 +2107,7 @@ index_t obi_avl_find(OBIDMS_avl_p avl, Obi_blob_p value)
|
|||||||
AVL_node_p current_node;
|
AVL_node_p current_node;
|
||||||
uint64_t crc;
|
uint64_t crc;
|
||||||
|
|
||||||
crc = crc64((byte_t*)value, blob_sizeof(value));
|
crc = crc64((byte_t*)value, obi_blob_sizeof(value));
|
||||||
|
|
||||||
next = (avl->header)->root_idx;
|
next = (avl->header)->root_idx;
|
||||||
while (next != -1)
|
while (next != -1)
|
||||||
@ -2120,7 +2120,7 @@ index_t obi_avl_find(OBIDMS_avl_p avl, Obi_blob_p value)
|
|||||||
if (comp == 0)
|
if (comp == 0)
|
||||||
{ // Check if really same value
|
{ // Check if really same value
|
||||||
to_compare = obi_avl_get(avl, current_node->value);
|
to_compare = obi_avl_get(avl, current_node->value);
|
||||||
comp = blob_compare(to_compare, value);
|
comp = obi_blob_compare(to_compare, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (comp > 0)
|
if (comp > 0)
|
||||||
@ -2205,7 +2205,7 @@ index_t obi_avl_group_add(OBIDMS_avl_group_p avl_group, Obi_blob_p value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add in the current AVL
|
// Add in the current AVL
|
||||||
bloom_add(&((((avl_group->sub_avls)[avl_group->current_avl_idx])->header)->bloom_filter), value, blob_sizeof(value));
|
bloom_add(&((((avl_group->sub_avls)[avl_group->current_avl_idx])->header)->bloom_filter), value, obi_blob_sizeof(value));
|
||||||
index_in_avl = (int32_t) obi_avl_add((avl_group->sub_avls)[avl_group->current_avl_idx], value);
|
index_in_avl = (int32_t) obi_avl_add((avl_group->sub_avls)[avl_group->current_avl_idx], value);
|
||||||
|
|
||||||
// Build the index containing the AVL index
|
// Build the index containing the AVL index
|
||||||
|
@ -55,3 +55,37 @@ Obi_blob_p obi_blob(byte_t* encoded_value, uint8_t element_size, int32_t length_
|
|||||||
return blob;
|
return blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int obi_blob_compare(Obi_blob_p value_1, Obi_blob_p value_2)
|
||||||
|
{
|
||||||
|
int comp;
|
||||||
|
int32_t b;
|
||||||
|
|
||||||
|
if (value_1->element_size != value_2->element_size)
|
||||||
|
return (value_1->element_size - value_2->element_size);
|
||||||
|
|
||||||
|
if (value_1->length_encoded_value != value_2->length_encoded_value)
|
||||||
|
return (value_1->length_encoded_value - value_2->length_encoded_value);
|
||||||
|
|
||||||
|
if (value_1->element_size != ELEMENT_SIZE_STR) // because if so, length_decoded_value == length_encoded_value
|
||||||
|
{
|
||||||
|
if (value_1->length_decoded_value != value_2->length_decoded_value)
|
||||||
|
return (value_1->length_decoded_value - value_2->length_decoded_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
b = 0;
|
||||||
|
comp = 0;
|
||||||
|
while (!comp && (b < value_1->length_encoded_value))
|
||||||
|
{
|
||||||
|
comp = *((value_1->value)+b) - *((value_2->value)+b);
|
||||||
|
b++;
|
||||||
|
}
|
||||||
|
return comp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int obi_blob_sizeof(Obi_blob_p value)
|
||||||
|
{
|
||||||
|
return (sizeof(Obi_blob_t) + (value->length_encoded_value));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -21,20 +21,19 @@
|
|||||||
#include "obitypes.h"
|
#include "obitypes.h"
|
||||||
|
|
||||||
|
|
||||||
#define ELEMENT_SIZE_STR (8) /**< The size of an element from a value of type character string.
|
#define ELEMENT_SIZE_STR (8) /**< The size of an element from a value of type character string.
|
||||||
*/
|
*/
|
||||||
#define ELEMENT_SIZE_SEQ_2 (2) /**< The size of an element from a value of type DNA sequence encoded on 2 bits.
|
#define ELEMENT_SIZE_SEQ_2 (2) /**< The size of an element from a value of type DNA sequence encoded on 2 bits.
|
||||||
*/
|
*/
|
||||||
#define ELEMENT_SIZE_SEQ_4 (4) /**< The size of an element from a value of type DNA sequence encoded on 4 bits.
|
#define ELEMENT_SIZE_SEQ_4 (4) /**< The size of an element from a value of type DNA sequence encoded on 4 bits.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Blob structure.
|
* @brief Blob structure, for handling encoded values.
|
||||||
* TODO
|
|
||||||
*/
|
*/
|
||||||
typedef struct Obi_blob {
|
typedef struct Obi_blob {
|
||||||
uint8_t element_size; /**< Size in bits of one element from the value.
|
uint8_t element_size; /**< Size in bits of one element from the encoded value.
|
||||||
*/
|
*/
|
||||||
int32_t length_encoded_value; /**< Length in bytes of the encoded value.
|
int32_t length_encoded_value; /**< Length in bytes of the encoded value.
|
||||||
*/
|
*/
|
||||||
@ -46,9 +45,54 @@ typedef struct Obi_blob {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO doc
|
/**
|
||||||
|
* @brief Function building a blob structure.
|
||||||
|
*
|
||||||
|
* @param encoded_value A pointer to the encoded value that will be stored in the blob.
|
||||||
|
* @param element_size The size in bits of one element from the encoded value.
|
||||||
|
* @param length_encoded_value The length in bytes of the encoded value.
|
||||||
|
* @param length_decoded_value The length in bytes of the decoded value.
|
||||||
|
*
|
||||||
|
* @returns A pointer to the created blob structure.
|
||||||
|
* @retval NULL if an error occurred.
|
||||||
|
*
|
||||||
|
* @since April 2016
|
||||||
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
|
*/
|
||||||
Obi_blob_p obi_blob(byte_t* encoded_value, uint8_t element_size, int32_t length_encoded_value, int32_t length_decoded_value);
|
Obi_blob_p obi_blob(byte_t* encoded_value, uint8_t element_size, int32_t length_encoded_value, int32_t length_decoded_value);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Function comparing two blobs.
|
||||||
|
*
|
||||||
|
* The encoding is compared first, then the length of the
|
||||||
|
* values, then the values themselves.
|
||||||
|
*
|
||||||
|
* @param value_1 A pointer to the first blob structure.
|
||||||
|
* @param value_2 A pointer to the second blob structure.
|
||||||
|
*
|
||||||
|
* @returns A value < 0 if value_1 < value_2,
|
||||||
|
* a value > 0 if value_1 > value_2,
|
||||||
|
* and 0 if value_1 == value_2.
|
||||||
|
*
|
||||||
|
* @since October 2015
|
||||||
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
|
*/
|
||||||
|
int obi_blob_compare(Obi_blob_p value_1, Obi_blob_p value_2);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Function calculating the size in bytes of a blob.
|
||||||
|
*
|
||||||
|
* @param value A pointer to the blob structure.
|
||||||
|
*
|
||||||
|
* @returns The size of the blob in bytes.
|
||||||
|
*
|
||||||
|
* @since October 2015
|
||||||
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
|
*/
|
||||||
|
int obi_blob_sizeof(Obi_blob_p value);
|
||||||
|
|
||||||
|
|
||||||
#endif /* OBIBLOB_H_ */
|
#endif /* OBIBLOB_H_ */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user