Implemented the retrieval of values with groups of AVLs

This commit is contained in:
Celine Mercier
2016-03-25 15:35:16 +01:00
parent 69856f18dd
commit ff6c27acf2
5 changed files with 53 additions and 22 deletions

View File

@ -134,9 +134,10 @@ if __name__ == '__main__':
# # #print("header", line)
# #
id = line.split(" ", 1)[0][1:]
# # #print(id)
print(id)
# # #rest = (line[:-1].split(" ", 1)[1]).split(";")
view[i].set_id(id)
#print(view[i]["ID"])
#
i+=1

View File

@ -1528,6 +1528,18 @@ int obi_close_avl(OBIDMS_avl_p avl)
}
byte_t* obi_avl_group_get(OBIDMS_avl_group_p avl_group, index_t idx)
{
int32_t avl_idx;
index_t idx_in_avl;
avl_idx = (int32_t) (idx >> 32);
idx_in_avl = idx & 0x00000000FFFFFFFF;
return obi_avl_get((avl_group->sub_avls)[avl_idx], idx_in_avl);
}
byte_t* obi_avl_get(OBIDMS_avl_p avl, index_t idx)
{
return (((avl->data)->data)+idx);
@ -1540,45 +1552,57 @@ int maybe_in_avl(OBIDMS_avl_p avl, byte_t* value)
}
index_t insert_in_avl_group(OBIDMS_avl_group_p avl_group, byte_t* value) // TODO won't be index_t
int64_t insert_in_avl_group(OBIDMS_avl_group_p avl_group, byte_t* value) // TODO won't be index_t
{
index_t index_if_already_in;
int i;
int32_t index_in_avl;
int64_t index_with_avl;
int i;
if (maybe_in_avl((avl_group->sub_avls)[avl_group->current_avl_idx], value))
{
//fprintf(stderr, "\nyah maybe");
index_if_already_in = obi_avl_find((avl_group->sub_avls)[avl_group->current_avl_idx], value);
if (index_if_already_in >= 0)
return index_if_already_in;
index_in_avl = (int32_t) obi_avl_find((avl_group->sub_avls)[avl_group->current_avl_idx], value);
if (index_in_avl >= 0)
{
index_with_avl = avl_group->current_avl_idx;
index_with_avl = index_with_avl << 32;
index_with_avl = index_with_avl + index_in_avl;
return index_with_avl;
}
}
// else
// fprintf(stderr, "\nnah");
for (i=0; i < (avl_group->current_avl_idx); i++)
{
if (maybe_in_avl((avl_group->sub_avls)[i], value))
{
//fprintf(stderr, "\nyah maybe");
if (remap_an_avl((avl_group->sub_avls)[i]) < 0)
return -1;
index_if_already_in = obi_avl_find((avl_group->sub_avls)[i], value);
index_in_avl = (int32_t) obi_avl_find((avl_group->sub_avls)[i], value);
if (unmap_an_avl((avl_group->sub_avls)[i]) < 0)
return -1;
if (index_if_already_in >= 0)
return index_if_already_in;
if (index_in_avl >= 0)
{
index_with_avl = i;
index_with_avl = index_with_avl << 32;
index_with_avl = index_with_avl + index_in_avl;
return index_with_avl;
}
}
// else
// fprintf(stderr, "\nnah");
}
// not found in any avl: add in current
// first, check if make new one
// Not found in any AVL: add in current
// First, check if make new AVL
if ((((avl_group->sub_avls)[avl_group->current_avl_idx])->header)->nb_items == NODE_COUNT_PER_AVL) // TODO add condition with data size
obi_add_new_avl_in_group(avl_group);
// Add in the current AVL
bloom_add(&((((avl_group->sub_avls)[avl_group->current_avl_idx])->header)->bloom_filter), value, BYTE_ARRAY_HEADER_SIZE + *((int32_t*)(value+1)));
return obi_avl_add((avl_group->sub_avls)[avl_group->current_avl_idx], value);
// Build the index containing the AVL index
index_in_avl = (int32_t) obi_avl_add((avl_group->sub_avls)[avl_group->current_avl_idx], value);
index_with_avl = avl_group->current_avl_idx;
index_with_avl = index_with_avl << 32;
index_with_avl = index_with_avl + index_in_avl;
return index_with_avl;
}

View File

@ -365,7 +365,11 @@ byte_t* obi_seq_to_obibytes(char* seq);
* @since November 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
const char* obi_obibytes_to_seq(byte_t* value_b);
const char* obi_obibytes_to_seq(byte_t* value_b); // TODO move to encode source files
// TODO
byte_t* obi_avl_group_get(OBIDMS_avl_group_p avl_group, index_t idx);
#endif /* OBIAVL_H_ */

View File

@ -135,7 +135,8 @@ const char* obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column, index_t l
if (idx == OBIIdx_NA)
return OBISeq_NA;
//value_b = obi_avl_get((column->avl)[crc(value)], idx);
value_b = obi_avl_group_get(column->avl, idx);
return obi_obibytes_to_seq(value_b);
}

View File

@ -129,7 +129,8 @@ 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_avl_get(column->avl, idx);
value_b = obi_avl_group_get(column->avl, idx);
return obi_obibytes_to_str(value_b);
}