Compare commits
2 Commits
multiple_a
...
always_rem
Author | SHA1 | Date | |
---|---|---|---|
eaf5fd940a | |||
86071d30c9 |
280
src/obiavl.c
280
src/obiavl.c
@ -30,159 +30,6 @@
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
////crc crcTable[256];
|
||||
//static crc crcTable[] = {
|
||||
//0x00, 0xd8, 0x68, 0xb0, 0xd0, 0x8, 0xb8, 0x60, 0x78, 0xa0, 0x10, 0xc8, 0xa8, 0x70, 0xc0, 0x18, 0xf0, 0x28, 0x98, 0x40, 0x20, 0xf8, 0x48, 0x90, 0x88, 0x50, 0xe0, 0x38, 0x58, 0x80, 0x30, 0xe8, 0x38, 0xe0, 0x50, 0x88, 0xe8, 0x30, 0x80, 0x58, 0x40, 0x98, 0x28, 0xf0, 0x90, 0x48, 0xf8, 0x20, 0xc8, 0x10, 0xa0, 0x78, 0x18, 0xc0, 0x70, 0xa8, 0xb0, 0x68, 0xd8, 0, 0x60, 0xb8, 0x8, 0xd0, 0x70, 0xa8, 0x18, 0xc0, 0xa0, 0x78, 0xc8, 0x10, 0x8, 0xd0, 0x60, 0xb8, 0xd8, 0, 0xb0, 0x68, 0x80, 0x58, 0xe8, 0x30, 0x50, 0x88, 0x38, 0xe0, 0xf8, 0x20, 0x90, 0x48, 0x28, 0xf0, 0x40, 0x98, 0x48, 0x90, 0x20, 0xf8, 0x98, 0x40, 0xf0, 0x28, 0x30, 0xe8, 0x58, 0x80, 0xe0, 0x38, 0x88, 0x50, 0xb8, 0x60, 0xd0, 0x8, 0x68, 0xb0, 0, 0xd8, 0xc0, 0x18, 0xa8, 0x70, 0x10, 0xc8, 0x78, 0xa0, 0xe0, 0x38, 0x88, 0x50, 0x30, 0xe8, 0x58, 0x80, 0x98, 0x40, 0xf0, 0x28, 0x48, 0x90, 0x20, 0xf8, 0x10, 0xc8, 0x78, 0xa0, 0xc0, 0x18, 0xa8, 0x70, 0x68, 0xb0, 0, 0xd8, 0xb8, 0x60, 0xd0, 0x8, 0xd8, 0, 0xb0, 0x68, 0x8, 0xd0, 0x60, 0xb8, 0xa0, 0x78, 0xc8, 0x10, 0x70, 0xa8, 0x18, 0xc0, 0x28, 0xf0, 0x40, 0x98, 0xf8, 0x20, 0x90, 0x48, 0x50, 0x88, 0x38, 0xe0, 0x80, 0x58, 0xe8, 0x30, 0x90, 0x48, 0xf8, 0x20, 0x40, 0x98, 0x28, 0xf0, 0xe8, 0x30, 0x80, 0x58, 0x38, 0xe0, 0x50, 0x88, 0x60, 0xb8, 0x8, 0xd0, 0xb0, 0x68, 0xd8, 0, 0x18, 0xc0, 0x70, 0xa8, 0xc8, 0x10, 0xa0, 0x78, 0xa8, 0x70, 0xc0, 0x18, 0x78, 0xa0, 0x10, 0xc8, 0xd0, 0x8, 0xb8, 0x60, 0, 0xd8, 0x68, 0xb0, 0x58, 0x80, 0x30, 0xe8, 0x88, 0x50, 0xe0, 0x38, 0x20, 0xf8, 0x48, 0x90, 0xf0, 0x28, 0x98, 0x40
|
||||
//};
|
||||
//
|
||||
//
|
||||
//void crcInit(void)
|
||||
//{
|
||||
// crc remainder;
|
||||
//
|
||||
// fprintf(stderr, "\n");
|
||||
//
|
||||
// /*
|
||||
// * Compute the remainder of each possible dividend.
|
||||
// */
|
||||
// for (int dividend = 0; dividend < 256; ++dividend)
|
||||
// {
|
||||
// /*
|
||||
// * Start with the dividend followed by zeros.
|
||||
// */
|
||||
// remainder = dividend << (WIDTH - 8);
|
||||
//
|
||||
// /*
|
||||
// * Perform modulo-2 division, a bit at a time.
|
||||
// */
|
||||
// for (uint8_t bit = 8; bit > 0; --bit)
|
||||
// {
|
||||
// /*
|
||||
// * Try to divide the current data bit.
|
||||
// */
|
||||
// if (remainder & TOPBIT)
|
||||
// {
|
||||
// remainder = (remainder << 1) ^ POLYNOMIAL;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// remainder = (remainder << 1);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// * Store the result into the table.
|
||||
// */
|
||||
// crcTable[dividend] = remainder;
|
||||
// fprintf(stderr, "%#x, ", remainder);
|
||||
// }
|
||||
//
|
||||
//} /* crcInit() */
|
||||
//
|
||||
//
|
||||
//crc crcFast(uint8_t const message[], int nBytes)
|
||||
//{
|
||||
// uint8_t data;
|
||||
// crc remainder = 0;
|
||||
//
|
||||
//
|
||||
// /*
|
||||
// * Divide the message by the polynomial, a byte at a time.
|
||||
// */
|
||||
// for (int byte = 0; byte < nBytes; ++byte)
|
||||
// {
|
||||
// data = message[byte] ^ (remainder >> (WIDTH - 8));
|
||||
// remainder = crcTable[data] ^ (remainder << 8);
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// * The final remainder is the CRC.
|
||||
// */
|
||||
// return (remainder);
|
||||
//
|
||||
//} /* crcFast() */
|
||||
//
|
||||
//
|
||||
//crc compute_crc(const char* s)
|
||||
//{
|
||||
// crc c;
|
||||
// //uint8_t cache;
|
||||
//
|
||||
// //cache = 15;
|
||||
//
|
||||
//// crcInit();
|
||||
//
|
||||
// c = crcFast(s, strlen(s));
|
||||
//
|
||||
// //fprintf(stderr, "\nlen = %d", strlen(argv[1]));
|
||||
//
|
||||
// //fprintf(stderr, "\ncrc = %u\n\n", c);
|
||||
// //fprintf(stderr, "\ncrc mod 8 = %u\n\n", c%8);
|
||||
//
|
||||
// c = c >> 3;
|
||||
// //fprintf(stderr, "\nshifted crc = %u\n\n", c);
|
||||
//
|
||||
// //c = c & cache;
|
||||
// //c = c % 32;
|
||||
//
|
||||
// //fprintf(stderr, "\ncrc = %u\n\n", c);
|
||||
//
|
||||
// return (c & 7);
|
||||
//}
|
||||
|
||||
static unsigned char crc8_table[] = {
|
||||
0x00, 0x3e, 0x7c, 0x42, 0xf8, 0xc6, 0x84, 0xba, 0x95, 0xab, 0xe9, 0xd7,
|
||||
0x6d, 0x53, 0x11, 0x2f, 0x4f, 0x71, 0x33, 0x0d, 0xb7, 0x89, 0xcb, 0xf5,
|
||||
0xda, 0xe4, 0xa6, 0x98, 0x22, 0x1c, 0x5e, 0x60, 0x9e, 0xa0, 0xe2, 0xdc,
|
||||
0x66, 0x58, 0x1a, 0x24, 0x0b, 0x35, 0x77, 0x49, 0xf3, 0xcd, 0x8f, 0xb1,
|
||||
0xd1, 0xef, 0xad, 0x93, 0x29, 0x17, 0x55, 0x6b, 0x44, 0x7a, 0x38, 0x06,
|
||||
0xbc, 0x82, 0xc0, 0xfe, 0x59, 0x67, 0x25, 0x1b, 0xa1, 0x9f, 0xdd, 0xe3,
|
||||
0xcc, 0xf2, 0xb0, 0x8e, 0x34, 0x0a, 0x48, 0x76, 0x16, 0x28, 0x6a, 0x54,
|
||||
0xee, 0xd0, 0x92, 0xac, 0x83, 0xbd, 0xff, 0xc1, 0x7b, 0x45, 0x07, 0x39,
|
||||
0xc7, 0xf9, 0xbb, 0x85, 0x3f, 0x01, 0x43, 0x7d, 0x52, 0x6c, 0x2e, 0x10,
|
||||
0xaa, 0x94, 0xd6, 0xe8, 0x88, 0xb6, 0xf4, 0xca, 0x70, 0x4e, 0x0c, 0x32,
|
||||
0x1d, 0x23, 0x61, 0x5f, 0xe5, 0xdb, 0x99, 0xa7, 0xb2, 0x8c, 0xce, 0xf0,
|
||||
0x4a, 0x74, 0x36, 0x08, 0x27, 0x19, 0x5b, 0x65, 0xdf, 0xe1, 0xa3, 0x9d,
|
||||
0xfd, 0xc3, 0x81, 0xbf, 0x05, 0x3b, 0x79, 0x47, 0x68, 0x56, 0x14, 0x2a,
|
||||
0x90, 0xae, 0xec, 0xd2, 0x2c, 0x12, 0x50, 0x6e, 0xd4, 0xea, 0xa8, 0x96,
|
||||
0xb9, 0x87, 0xc5, 0xfb, 0x41, 0x7f, 0x3d, 0x03, 0x63, 0x5d, 0x1f, 0x21,
|
||||
0x9b, 0xa5, 0xe7, 0xd9, 0xf6, 0xc8, 0x8a, 0xb4, 0x0e, 0x30, 0x72, 0x4c,
|
||||
0xeb, 0xd5, 0x97, 0xa9, 0x13, 0x2d, 0x6f, 0x51, 0x7e, 0x40, 0x02, 0x3c,
|
||||
0x86, 0xb8, 0xfa, 0xc4, 0xa4, 0x9a, 0xd8, 0xe6, 0x5c, 0x62, 0x20, 0x1e,
|
||||
0x31, 0x0f, 0x4d, 0x73, 0xc9, 0xf7, 0xb5, 0x8b, 0x75, 0x4b, 0x09, 0x37,
|
||||
0x8d, 0xb3, 0xf1, 0xcf, 0xe0, 0xde, 0x9c, 0xa2, 0x18, 0x26, 0x64, 0x5a,
|
||||
0x3a, 0x04, 0x46, 0x78, 0xc2, 0xfc, 0xbe, 0x80, 0xaf, 0x91, 0xd3, 0xed,
|
||||
0x57, 0x69, 0x2b, 0x15};
|
||||
|
||||
|
||||
unsigned crc8(unsigned char *data, size_t len)
|
||||
{
|
||||
unsigned char *end;
|
||||
unsigned crc;
|
||||
|
||||
crc = 0;
|
||||
|
||||
crc ^= 0xff;
|
||||
end = data + len;
|
||||
do {
|
||||
crc = crc8_table[crc ^ *data++];
|
||||
} while (data < end);
|
||||
return crc ^ 0xff;
|
||||
}
|
||||
|
||||
crc compute_crc(const char* s)
|
||||
{
|
||||
unsigned c;
|
||||
|
||||
c = crc8(s, strlen(s));
|
||||
//fprintf(stderr, "%02x\n", c);
|
||||
return (c & 7);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* D E C L A R A T I O N O F T H E P R I V A T E F U N C T I O N S
|
||||
@ -561,7 +408,13 @@ size_t get_avl_header_size()
|
||||
|
||||
size_t get_initial_avl_size()
|
||||
{
|
||||
return getpagesize() * 1;
|
||||
size_t s;
|
||||
size_t m;
|
||||
|
||||
m = 1;
|
||||
s = getpagesize() * m;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@ -583,7 +436,13 @@ size_t get_avl_data_header_size()
|
||||
|
||||
size_t get_initial_avl_data_size()
|
||||
{
|
||||
return getpagesize() * 1;
|
||||
size_t s;
|
||||
size_t m;
|
||||
|
||||
m = 1;
|
||||
s = getpagesize() * m;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@ -618,23 +477,25 @@ int grow_avl(OBIDMS_avl_p avl) // TODO Lock when needed
|
||||
size_t new_data_size;
|
||||
size_t header_size;
|
||||
int avl_file_descriptor;
|
||||
char* avl_file_name;
|
||||
// char* avl_file_name;
|
||||
|
||||
// Get the avl file name
|
||||
avl_file_name = build_avl_file_name((avl->header)->avl_name);
|
||||
if (avl_file_name == NULL)
|
||||
return -1;
|
||||
// // Get the avl file name
|
||||
// avl_file_name = build_avl_file_name((avl->header)->avl_name);
|
||||
// if (avl_file_name == NULL)
|
||||
// return -1;
|
||||
//
|
||||
// // Open the avl file
|
||||
// avl_file_descriptor = openat(avl->dir_fd, avl_file_name, O_RDWR);
|
||||
// if (avl_file_descriptor < 0)
|
||||
// {
|
||||
// obi_set_errno(OBI_AVL_ERROR);
|
||||
// obidebug(1, "\nError opening an AVL tree file");
|
||||
// free(avl_file_name);
|
||||
// return -1;
|
||||
// }
|
||||
// free(avl_file_name);
|
||||
|
||||
// Open the avl file
|
||||
avl_file_descriptor = openat(avl->dir_fd, avl_file_name, O_RDWR);
|
||||
if (avl_file_descriptor < 0)
|
||||
{
|
||||
obi_set_errno(OBI_AVL_ERROR);
|
||||
obidebug(1, "\nError opening an AVL tree file");
|
||||
free(avl_file_name);
|
||||
return -1;
|
||||
}
|
||||
free(avl_file_name);
|
||||
avl_file_descriptor = avl->avl_fd;
|
||||
|
||||
// Calculate the new file size
|
||||
old_data_size = (avl->header)->avl_size;
|
||||
@ -683,7 +544,7 @@ int grow_avl(OBIDMS_avl_p avl) // TODO Lock when needed
|
||||
// Set the new avl size
|
||||
(avl->header)->avl_size = new_data_size;
|
||||
|
||||
close(avl_file_descriptor);
|
||||
//close(avl_file_descriptor);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -696,23 +557,25 @@ int grow_avl_data(OBIDMS_avl_p avl) // TODO Lock when needed
|
||||
index_t new_data_size;
|
||||
size_t header_size;
|
||||
int avl_data_file_descriptor;
|
||||
char* avl_data_file_name;
|
||||
// char* avl_data_file_name;
|
||||
//
|
||||
// // Get the avl data file name
|
||||
// avl_data_file_name = build_avl_data_file_name((avl->header)->avl_name);
|
||||
// if (avl_data_file_name == NULL)
|
||||
// return -1;
|
||||
//
|
||||
// // Open the avl data file
|
||||
// avl_data_file_descriptor = openat(avl->dir_fd, avl_data_file_name, O_RDWR);
|
||||
// if (avl_data_file_descriptor < 0)
|
||||
// {
|
||||
// obi_set_errno(OBI_AVL_ERROR);
|
||||
// obidebug(1, "\nError opening an AVL tree data file");
|
||||
// free(avl_data_file_name);
|
||||
// return -1;
|
||||
// }
|
||||
// free(avl_data_file_name);
|
||||
|
||||
// Get the avl data file name
|
||||
avl_data_file_name = build_avl_data_file_name((avl->header)->avl_name);
|
||||
if (avl_data_file_name == NULL)
|
||||
return -1;
|
||||
|
||||
// Open the avl data file
|
||||
avl_data_file_descriptor = openat(avl->dir_fd, avl_data_file_name, O_RDWR);
|
||||
if (avl_data_file_descriptor < 0)
|
||||
{
|
||||
obi_set_errno(OBI_AVL_ERROR);
|
||||
obidebug(1, "\nError opening an AVL tree data file");
|
||||
free(avl_data_file_name);
|
||||
return -1;
|
||||
}
|
||||
free(avl_data_file_name);
|
||||
avl_data_file_descriptor = avl->data_fd;
|
||||
|
||||
// Calculate the new file size
|
||||
old_data_size = ((avl->data)->header)->data_size_max;
|
||||
@ -758,12 +621,10 @@ int grow_avl_data(OBIDMS_avl_p avl) // TODO Lock when needed
|
||||
// Set new data size
|
||||
((avl->data)->header)->data_size_max = new_data_size;
|
||||
|
||||
//fprintf(stderr, "\nGrowing AVL, new data size = %lld, count = %ld\n", new_data_size, (avl->header)->nb_items);
|
||||
|
||||
// Initialize new data to 0
|
||||
memset(((avl->data)->data)+old_data_size, 0, new_data_size - old_data_size);
|
||||
|
||||
close(avl_data_file_descriptor);
|
||||
//close(avl_data_file_descriptor);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1131,24 +992,6 @@ OBIDMS_avl_p obi_avl(OBIDMS_p dms, const char* avl_name)
|
||||
}
|
||||
|
||||
|
||||
OBIDMS_avl_p* obi_create_avl_in_64_parts(OBIDMS_p dms, const char* avl_name)
|
||||
{
|
||||
OBIDMS_avl_p* avls;
|
||||
char* avl_name_with_idx;
|
||||
uint8_t i;
|
||||
|
||||
avls = (OBIDMS_avl_p*) malloc(64*sizeof(OBIDMS_avl_p));
|
||||
|
||||
for (i=0; i < 64; i++)
|
||||
{
|
||||
asprintf(&avl_name_with_idx,"%s_%u", avl_name, i);
|
||||
avls[i] = obi_create_avl(dms, avl_name_with_idx);
|
||||
}
|
||||
|
||||
return avls;
|
||||
}
|
||||
|
||||
|
||||
OBIDMS_avl_p obi_create_avl(OBIDMS_p dms, const char* avl_name)
|
||||
{
|
||||
char* avl_file_name;
|
||||
@ -1251,7 +1094,7 @@ OBIDMS_avl_p obi_create_avl(OBIDMS_p dms, const char* avl_name)
|
||||
// Initialize all bits to 0
|
||||
memset(avl_data->data, 0, (avl_data->header)->data_size_max);
|
||||
|
||||
close(avl_data_file_descriptor);
|
||||
//close(avl_data_file_descriptor);
|
||||
|
||||
|
||||
// Create the AVL tree file
|
||||
@ -1351,7 +1194,10 @@ OBIDMS_avl_p obi_create_avl(OBIDMS_p dms, const char* avl_name)
|
||||
(avl->header)->creation_date = time(NULL);
|
||||
strcpy((avl->header)->avl_name, avl_name);
|
||||
|
||||
close(avl_file_descriptor);
|
||||
//close(avl_file_descriptor);
|
||||
|
||||
avl->avl_fd = avl_file_descriptor;
|
||||
avl->data_fd = avl_data_file_descriptor;
|
||||
|
||||
// Add in the list of opened AVL trees
|
||||
*(((dms->opened_avls)->avls)+((dms->opened_avls)->nb_opened_avls)) = avl;
|
||||
@ -1458,7 +1304,7 @@ OBIDMS_avl_p obi_open_avl(OBIDMS_p dms, const char* avl_name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
close(avl_data_file_descriptor);
|
||||
//close(avl_data_file_descriptor);
|
||||
|
||||
|
||||
// Open the AVL tree file
|
||||
@ -1544,7 +1390,9 @@ OBIDMS_avl_p obi_open_avl(OBIDMS_p dms, const char* avl_name)
|
||||
avl->directory = dms->avl_directory;
|
||||
avl->dir_fd = avl_dir_file_descriptor;
|
||||
|
||||
close(avl_file_descriptor);
|
||||
//close(avl_file_descriptor);
|
||||
avl->avl_fd = avl_file_descriptor;
|
||||
avl->data_fd = avl_data_file_descriptor;
|
||||
|
||||
// Add in the list of opened AVL trees
|
||||
*(((dms->opened_avls)->avls)+((dms->opened_avls)->nb_opened_avls)) = avl;
|
||||
@ -1596,6 +1444,9 @@ int obi_close_avl(OBIDMS_avl_p avl)
|
||||
ret_val = -1;
|
||||
}
|
||||
|
||||
close(avl->avl_fd);
|
||||
close(avl->data_fd);
|
||||
|
||||
free(avl);
|
||||
}
|
||||
|
||||
@ -1672,10 +1523,7 @@ index_t obi_avl_add(OBIDMS_avl_p avl, byte_t* value)
|
||||
next = current_node->right_child;
|
||||
else if (comp == 0)
|
||||
// Value already stored
|
||||
{
|
||||
//fprintf(stderr, "\n>>>ALREADY IN, %s, %lld\n", obi_obibytes_to_seq(value), (avl->header)->nb_items);
|
||||
return current_node->value;
|
||||
}
|
||||
|
||||
depth++;
|
||||
}
|
||||
@ -1788,7 +1636,7 @@ byte_t* obi_str_to_obibytes(char* value)
|
||||
*((int32_t*)(value_b+1)) = length;
|
||||
|
||||
// Store the initial length (in bytes) of the decoded value (same as encoded for character strings)
|
||||
*((int64_t*)(value_b+5)) = length;
|
||||
*((int32_t*)(value_b+5)) = length;
|
||||
|
||||
// Store the character string
|
||||
strcpy(value_b+BYTE_ARRAY_HEADER_SIZE, value);
|
||||
|
13
src/obiavl.h
13
src/obiavl.h
@ -130,6 +130,12 @@ typedef struct OBIDMS_avl {
|
||||
int dir_fd; /**< The file descriptor of the directory entry
|
||||
* usable to refer and scan the AVL tree directory.
|
||||
*/
|
||||
int avl_fd; /**< The file descriptor of the file
|
||||
* to refer and scan the AVL tree.
|
||||
*/
|
||||
int data_fd; /**< The file descriptor of the file
|
||||
* to refer and scan the data referred to by the AVL tree.
|
||||
*/
|
||||
size_t counter; /**< Indicates by how many threads/programs (TODO) the AVL tree is used.
|
||||
*/
|
||||
} OBIDMS_avl_t, *OBIDMS_avl_p;
|
||||
@ -340,12 +346,5 @@ byte_t* obi_seq_to_obibytes(char* seq);
|
||||
const char* obi_obibytes_to_seq(byte_t* value_b);
|
||||
|
||||
|
||||
OBIDMS_avl_p* obi_create_avl_in_64_parts(OBIDMS_p dms, const char* avl_name);
|
||||
|
||||
typedef uint8_t crc;
|
||||
|
||||
crc compute_crc(const char* s);
|
||||
|
||||
|
||||
#endif /* OBIAVL_H_ */
|
||||
|
||||
|
@ -521,7 +521,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
OBIDMS_column_p new_column;
|
||||
OBIDMS_column_directory_p column_directory;
|
||||
OBIDMS_column_header_p header;
|
||||
OBIDMS_avl_p* avl;
|
||||
OBIDMS_avl_p avl;
|
||||
size_t file_size;
|
||||
obiversion_t version_number;
|
||||
char* column_file_name;
|
||||
@ -723,7 +723,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
// If the data type is OBI_STR or OBI_SEQ, the associated obi_avl is opened or created
|
||||
if ((returned_data_type == OBI_STR) || (returned_data_type == OBI_SEQ))
|
||||
{
|
||||
avl = obi_create_avl_in_64_parts(dms, avl_name);
|
||||
avl = obi_avl(dms, avl_name);
|
||||
if (avl == NULL)
|
||||
{
|
||||
obidebug(1, "\nError opening or creating the aVL tree associated with a column");
|
||||
@ -732,7 +732,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
free(new_column);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(new_column->avl, avl, 64*sizeof(OBIDMS_avl_p));
|
||||
new_column->avl = avl;
|
||||
strncpy(header->avl_name, avl_name, AVL_MAX_NAME);
|
||||
}
|
||||
|
||||
@ -886,7 +886,7 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
free(column);
|
||||
return NULL;
|
||||
}
|
||||
//column->avl = avl; TODO
|
||||
column->avl = avl;
|
||||
}
|
||||
|
||||
close(column_file_descriptor);
|
||||
@ -1020,12 +1020,12 @@ int obi_close_column(OBIDMS_column_p column)
|
||||
}
|
||||
}
|
||||
|
||||
// If the data type is OBI_STR or OBI_SEQ, the associated AVL tree is closed TODO
|
||||
// if (((column->header)->returned_data_type == OBI_STR) || ((column->header)->returned_data_type == OBI_SEQ))
|
||||
// {
|
||||
// if (obi_close_avl(column->avl) < 0)
|
||||
// return -1;
|
||||
// }
|
||||
// If the data type is OBI_STR or OBI_SEQ, the associated AVL tree is closed
|
||||
if (((column->header)->returned_data_type == OBI_STR) || ((column->header)->returned_data_type == OBI_SEQ))
|
||||
{
|
||||
if (obi_close_avl(column->avl) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Munmap data
|
||||
if (munmap(column->data, (column->header)->data_size) < 0)
|
||||
|
@ -98,7 +98,7 @@ typedef struct OBIDMS_column {
|
||||
*/
|
||||
OBIDMS_column_header_p header; /**< A pointer to the header of the column.
|
||||
*/
|
||||
OBIDMS_avl_p avl[64]; /**< A pointer to the group of AVL trees associated with the column if there is one.
|
||||
OBIDMS_avl_p avl; /**< A pointer to the AVL tree associated with the column if there is one.
|
||||
*/
|
||||
void* data; /**< A `void` pointer to the beginning of the data.
|
||||
*
|
||||
|
@ -61,13 +61,8 @@ int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb,
|
||||
if (value_b == NULL)
|
||||
return -1;
|
||||
|
||||
if (strlen(value_b) == 0)
|
||||
fprintf(stderr, "\nPOUIC");
|
||||
|
||||
//fprintf(stderr, "\n>%s||%s", value, obi_obibytes_to_seq(value_b));
|
||||
|
||||
// Add in the AVL tree
|
||||
idx = obi_avl_add((column->avl)[compute_crc(value)], value_b);
|
||||
idx = obi_avl_add(column->avl, value_b);
|
||||
if (idx == -1)
|
||||
return -1;
|
||||
|
||||
@ -135,7 +130,7 @@ 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_get(column->avl, idx);
|
||||
return obi_obibytes_to_seq(value_b);
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obiview.h"
|
||||
@ -60,8 +61,32 @@ int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb,
|
||||
if (value_b == NULL)
|
||||
return -1;
|
||||
|
||||
if (!(line_nb%100000))
|
||||
{
|
||||
//fprintf(stderr, "\nbleeeh");
|
||||
// Unmap and remap the AVL
|
||||
if (munmap((column->avl)->tree, ((((column->avl)->header)->nb_items_max) * sizeof(AVL_node_t))) < 0)
|
||||
return -1;
|
||||
if (munmap(((column->avl)->data)->data, (((column->avl)->data)->header)->data_size_max) < 0)
|
||||
return -1;
|
||||
(column->avl)->tree = mmap(NULL,
|
||||
(((column->avl)->header)->nb_items_max) * sizeof(AVL_node_t), // TODO store avl_size_max
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
(column->avl)->avl_fd,
|
||||
((column->avl)->header)->header_size
|
||||
);
|
||||
((column->avl)->data)->data = mmap(NULL,
|
||||
(((column->avl)->data)->header)->data_size_max,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
(column->avl)->data_fd,
|
||||
(((column->avl)->data)->header)->header_size
|
||||
);
|
||||
}
|
||||
|
||||
// Add in the AVL tree
|
||||
idx = obi_avl_add((column->avl)[compute_crc(value)], value_b);
|
||||
idx = obi_avl_add(column->avl, value_b);
|
||||
if (idx == -1)
|
||||
return -1;
|
||||
|
||||
@ -129,7 +154,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_avl_get(column->avl, idx);
|
||||
value_b = obi_avl_get(column->avl, idx);
|
||||
return obi_obibytes_to_str(value_b);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user