Renamed "Obi_byte_arrays" to "Obiblobs" and moved Obiblob functions to
separate obiblob.c and obiblob.h files
This commit is contained in:
67
src/obiavl.c
67
src/obiavl.c
@ -22,6 +22,7 @@
|
||||
#include "bloom.h"
|
||||
#include "crc64.h"
|
||||
#include "obiavl.h"
|
||||
#include "obiblob.h"
|
||||
#include "obierrno.h"
|
||||
#include "obitypes.h"
|
||||
#include "obidebug.h"
|
||||
@ -270,7 +271,7 @@ int add_new_avl_in_group(OBIDMS_avl_group_p avl_group);
|
||||
* The function checks a bloom filter. No false negatives, possible false positives.
|
||||
*
|
||||
* @param avl A pointer to the AVL tree structure.
|
||||
* @param value A pointer to the byte array structure.
|
||||
* @param value A pointer to the blob structure.
|
||||
*
|
||||
* @retval 0 if the value is definitely not already stored in the AVL tree.
|
||||
* @retval 1 if the value might already be stored in the AVL tree.
|
||||
@ -278,17 +279,17 @@ int add_new_avl_in_group(OBIDMS_avl_group_p avl_group);
|
||||
* @since April 2016
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int maybe_in_avl(OBIDMS_avl_p avl, Obi_byte_array_p value);
|
||||
int maybe_in_avl(OBIDMS_avl_p avl, Obi_blob_p value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Internal function comparing two byte arrays.
|
||||
* @brief Internal 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 byte array structure.
|
||||
* @param value_2 A pointer to the second byte array structure.
|
||||
* @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,
|
||||
@ -297,27 +298,27 @@ int maybe_in_avl(OBIDMS_avl_p avl, Obi_byte_array_p value);
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int byte_array_compare(Obi_byte_array_p value_1, Obi_byte_array_p value_2);
|
||||
int blob_compare(Obi_blob_p value_1, Obi_blob_p value_2);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Internal function calculating the size in bytes of a byte array.
|
||||
* @brief Internal function calculating the size in bytes of a blob.
|
||||
*
|
||||
* @param value A pointer to the byte array structure.
|
||||
* @param value A pointer to the blob structure.
|
||||
*
|
||||
* @returns The size of the byte array in bytes.
|
||||
* @returns The size of the blob in bytes.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int byte_array_sizeof(Obi_byte_array_p value);
|
||||
int blob_sizeof(Obi_blob_p value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Internal function storing a value (byte array) in the data array referred to by an AVL tree.
|
||||
* @brief Internal function storing a value (blob) in the data array referred to by an AVL tree.
|
||||
*
|
||||
* @param avl A pointer to the AVL tree structure.
|
||||
* @param value A pointer to the value (byte array structure).
|
||||
* @param value A pointer to the value (blob structure).
|
||||
*
|
||||
* @returns The index of the stored value.
|
||||
* @retval -1 if an error occurred.
|
||||
@ -325,7 +326,7 @@ int byte_array_sizeof(Obi_byte_array_p value);
|
||||
* @since December 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
index_t avl_add_value_in_data_array(OBIDMS_avl_p avl, Obi_byte_array_p value);
|
||||
index_t avl_add_value_in_data_array(OBIDMS_avl_p avl, Obi_blob_p value);
|
||||
|
||||
|
||||
/**
|
||||
@ -979,13 +980,13 @@ int add_new_avl_in_group(OBIDMS_avl_group_p avl_group)
|
||||
}
|
||||
|
||||
|
||||
int maybe_in_avl(OBIDMS_avl_p avl, Obi_byte_array_p value)
|
||||
int maybe_in_avl(OBIDMS_avl_p avl, Obi_blob_p value)
|
||||
{
|
||||
return (bloom_check(&((avl->header)->bloom_filter), value, byte_array_sizeof(value)));
|
||||
return (bloom_check(&((avl->header)->bloom_filter), value, blob_sizeof(value)));
|
||||
}
|
||||
|
||||
|
||||
int byte_array_compare(Obi_byte_array_p value_1, Obi_byte_array_p value_2)
|
||||
int blob_compare(Obi_blob_p value_1, Obi_blob_p value_2)
|
||||
{
|
||||
int comp;
|
||||
int32_t b;
|
||||
@ -1013,13 +1014,13 @@ int byte_array_compare(Obi_byte_array_p value_1, Obi_byte_array_p value_2)
|
||||
}
|
||||
|
||||
|
||||
int byte_array_sizeof(Obi_byte_array_p value)
|
||||
int blob_sizeof(Obi_blob_p value)
|
||||
{
|
||||
return (sizeof(Obi_byte_array_t) + (value->length_encoded_value));
|
||||
return (sizeof(Obi_blob_t) + (value->length_encoded_value));
|
||||
}
|
||||
|
||||
|
||||
index_t avl_add_value_in_data_array(OBIDMS_avl_p avl, Obi_byte_array_p value)
|
||||
index_t avl_add_value_in_data_array(OBIDMS_avl_p avl, Obi_blob_p value)
|
||||
{
|
||||
index_t value_idx;
|
||||
int value_size;
|
||||
@ -1027,7 +1028,7 @@ index_t avl_add_value_in_data_array(OBIDMS_avl_p avl, Obi_byte_array_p value)
|
||||
value_idx = ((avl->data)->header)->data_size_used;
|
||||
|
||||
// Grow the data if needed
|
||||
value_size = byte_array_sizeof(value);
|
||||
value_size = blob_sizeof(value);
|
||||
while (((avl->data)->header)->data_size_max < (value_idx + value_size))
|
||||
{
|
||||
if (grow_avl_data(avl->data) < 0)
|
||||
@ -2047,20 +2048,20 @@ int obi_close_avl_group(OBIDMS_avl_group_p avl_group)
|
||||
}
|
||||
|
||||
|
||||
Obi_byte_array_p obi_avl_get(OBIDMS_avl_p avl, index_t idx)
|
||||
Obi_blob_p obi_avl_get(OBIDMS_avl_p avl, index_t idx)
|
||||
{
|
||||
return ((Obi_byte_array_p)(((avl->data)->data)+idx));
|
||||
return ((Obi_blob_p)(((avl->data)->data)+idx));
|
||||
}
|
||||
|
||||
|
||||
index_t obi_avl_add(OBIDMS_avl_p avl, Obi_byte_array_p value)
|
||||
index_t obi_avl_add(OBIDMS_avl_p avl, Obi_blob_p value)
|
||||
{
|
||||
AVL_node_p node_to_add = NULL;
|
||||
AVL_node_p current_node;
|
||||
index_t next, parent;
|
||||
index_t value_data_idx;
|
||||
index_t node_idx;
|
||||
Obi_byte_array_p to_compare;
|
||||
Obi_blob_p to_compare;
|
||||
int comp;
|
||||
int n;
|
||||
int depth;
|
||||
@ -2068,7 +2069,7 @@ index_t obi_avl_add(OBIDMS_avl_p avl, Obi_byte_array_p value)
|
||||
|
||||
n = 0;
|
||||
depth = 0;
|
||||
crc = crc64((byte_t*)value, byte_array_sizeof(value));
|
||||
crc = crc64((byte_t*)value, blob_sizeof(value));
|
||||
|
||||
// Check if first node
|
||||
if (!((avl->header)->nb_items))
|
||||
@ -2115,7 +2116,7 @@ index_t obi_avl_add(OBIDMS_avl_p avl, Obi_byte_array_p value)
|
||||
if (comp == 0)
|
||||
{ // check if really same value
|
||||
to_compare = obi_avl_get(avl, current_node->value);
|
||||
comp = byte_array_compare(to_compare, value);
|
||||
comp = blob_compare(to_compare, value);
|
||||
}
|
||||
|
||||
if (comp > 0)
|
||||
@ -2189,15 +2190,15 @@ index_t obi_avl_add(OBIDMS_avl_p avl, Obi_byte_array_p value)
|
||||
|
||||
|
||||
// Find if a value is already in an AVL tree
|
||||
index_t obi_avl_find(OBIDMS_avl_p avl, Obi_byte_array_p value)
|
||||
index_t obi_avl_find(OBIDMS_avl_p avl, Obi_blob_p value)
|
||||
{
|
||||
int comp;
|
||||
index_t next;
|
||||
Obi_byte_array_p to_compare;
|
||||
Obi_blob_p to_compare;
|
||||
AVL_node_p current_node;
|
||||
uint64_t crc;
|
||||
|
||||
crc = crc64((byte_t*)value, byte_array_sizeof(value));
|
||||
crc = crc64((byte_t*)value, blob_sizeof(value));
|
||||
|
||||
next = (avl->header)->root_idx;
|
||||
while (next != -1)
|
||||
@ -2210,7 +2211,7 @@ index_t obi_avl_find(OBIDMS_avl_p avl, Obi_byte_array_p value)
|
||||
if (comp == 0)
|
||||
{ // Check if really same value
|
||||
to_compare = obi_avl_get(avl, current_node->value);
|
||||
comp = byte_array_compare(to_compare, value);
|
||||
comp = blob_compare(to_compare, value);
|
||||
}
|
||||
|
||||
if (comp > 0)
|
||||
@ -2229,7 +2230,7 @@ index_t obi_avl_find(OBIDMS_avl_p avl, Obi_byte_array_p value)
|
||||
}
|
||||
|
||||
|
||||
Obi_byte_array_p obi_avl_group_get(OBIDMS_avl_group_p avl_group, index_t idx)
|
||||
Obi_blob_p obi_avl_group_get(OBIDMS_avl_group_p avl_group, index_t idx)
|
||||
{
|
||||
int32_t avl_idx;
|
||||
index_t idx_in_avl;
|
||||
@ -2241,7 +2242,7 @@ Obi_byte_array_p obi_avl_group_get(OBIDMS_avl_group_p avl_group, index_t idx)
|
||||
}
|
||||
|
||||
|
||||
index_t obi_avl_group_add(OBIDMS_avl_group_p avl_group, Obi_byte_array_p value)
|
||||
index_t obi_avl_group_add(OBIDMS_avl_group_p avl_group, Obi_blob_p value)
|
||||
{
|
||||
int32_t index_in_avl;
|
||||
index_t index_with_avl;
|
||||
@ -2286,7 +2287,7 @@ index_t obi_avl_group_add(OBIDMS_avl_group_p avl_group, Obi_byte_array_p value)
|
||||
}
|
||||
|
||||
// Add in the current AVL
|
||||
bloom_add(&((((avl_group->sub_avls)[avl_group->current_avl_idx])->header)->bloom_filter), value, byte_array_sizeof(value));
|
||||
bloom_add(&((((avl_group->sub_avls)[avl_group->current_avl_idx])->header)->bloom_filter), value, blob_sizeof(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
|
||||
|
Reference in New Issue
Block a user