diff --git a/python/obitools3/obiimport.py b/python/obitools3/obiimport.py index 921329f..99580a1 100644 --- a/python/obitools3/obiimport.py +++ b/python/obitools3/obiimport.py @@ -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 diff --git a/src/obiavl.c b/src/obiavl.c index 6263ad7..e9dc24c 100644 --- a/src/obiavl.c +++ b/src/obiavl.c @@ -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; } diff --git a/src/obiavl.h b/src/obiavl.h index 663d61b..2e83fc1 100644 --- a/src/obiavl.h +++ b/src/obiavl.h @@ -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_ */ diff --git a/src/obidmscolumn_seq.c b/src/obidmscolumn_seq.c index ffc2abe..236018c 100644 --- a/src/obidmscolumn_seq.c +++ b/src/obidmscolumn_seq.c @@ -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); } diff --git a/src/obidmscolumn_str.c b/src/obidmscolumn_str.c index 5a6fdad..92c057a 100644 --- a/src/obidmscolumn_str.c +++ b/src/obidmscolumn_str.c @@ -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); }