diff --git a/helpers/helpers_common.c b/helpers/helpers_common.c index 000a2b7..a4d66f1 100644 --- a/helpers/helpers_common.c +++ b/helpers/helpers_common.c @@ -310,24 +310,20 @@ static void handle_event(queue_entry_t event, thread_argument_t * arg) return; } DIR * thread_directory = NULL; - for (int i = 0; i < arg->hash_table->size; i++) + + hash_item_t * hi = arg->hash_table->node; + while (hi != NULL) { - if (NULL != hash_table_search_item(arg->hash_table, i, NULL)) + thread_directory = opendir(hi->value); + if (thread_directory && !backup_helpers_find_file(cur_event_filename, thread_directory)) + { + hi = hi->previous; + continue; + } + else if (thread_directory) { - thread_directory = opendir(arg->hash_table->table[i]->value); - if (NULL != thread_directory) - { - if (false == backup_helpers_find_file(cur_event_filename, thread_directory)) - { - continue; - } - else - { - // path to file founded successfully, refresh - arg->path_to_dir = arg->hash_table->table[i]->value; - break; - } - } + arg->path_to_dir = hi->value; + break; } } cur_event_file_or_dir = HELPERS_FILE; @@ -609,4 +605,4 @@ char * parser_read_conf() while (fread(buffer, sizeof(char), HELPERS_FILE_STROKE_MAX_LEN * lines, cp)); return buffer; -} \ No newline at end of file +} diff --git a/helpers/helpers_hash_table.c b/helpers/helpers_hash_table.c index bedd3f8..0511529 100644 --- a/helpers/helpers_hash_table.c +++ b/helpers/helpers_hash_table.c @@ -37,7 +37,7 @@ static hash_item_t * __hash_item_create(char * value) memset(hash_item->value, 0, sizeof(char) * value_len); strncpy(hash_item->value, value, value_len); - hash_t key = __hash_key_generator(value); + hash_t key = __hash_key_generator(value); if (key >= 0 && key <= 1.1) { printf("Error: This path to file is too big !\n"); @@ -45,7 +45,10 @@ static hash_item_t * __hash_item_create(char * value) } else { - hash_item->key = key; + hash_item->key = key; + hash_item->previous = NULL; + hash_item->next = NULL; + return hash_item; } } @@ -62,6 +65,7 @@ hash_table_t * hash_table_create(hash_table_size_t size) { this->table[i] = NULL; } + this->node = NULL; return this; } @@ -118,9 +122,20 @@ unsigned int hash_table_insert_item(hash_table_t * this, char * value) } hash_item_t ** head = &this->table[key]; - if (!(*head)) + if (head && !(*head)) { *head = item; + if (NULL == this->node) + { + this->node = (void *)*head; + } + else + { + this->node->next = (void *)item; + item->previous = this->node; + this->node = (void *)item; + } + ++this->count; } else if ((*head)->key == key) @@ -175,4 +190,4 @@ int test1() printf("[1] = %d:%s\n", HI->key, HI->value); hash_table_free(HT); } -#endif \ No newline at end of file +#endif diff --git a/helpers/helpers_logger.c b/helpers/helpers_logger.c index e9531e0..14953b2 100644 --- a/helpers/helpers_logger.c +++ b/helpers/helpers_logger.c @@ -31,4 +31,4 @@ int logger(char * message) fclose(fptr); return LOGGER_NORMAL_EXIT; -} \ No newline at end of file +} diff --git a/include/helpers/helpers_hash_table.h b/include/helpers/helpers_hash_table.h index aa23407..affdaa5 100644 --- a/include/helpers/helpers_hash_table.h +++ b/include/helpers/helpers_hash_table.h @@ -16,13 +16,18 @@ typedef enum typedef struct hash_item_s { - hash_t key; - char * value; + hash_t key; + char * value; + + void * previous; + void * next; } hash_item_t; typedef struct hash_table_s { hash_item_t ** table; + hash_item_t * node; + hash_table_size_t size; int count; } hash_table_t; @@ -32,4 +37,4 @@ unsigned int hash_table_insert_item(hash_table_t * this, char * value); hash_table_t * hash_table_create(hash_table_size_t size); void hash_table_free(hash_table_t * this); -#endif // HELPERS_HASH_TABLE_H \ No newline at end of file +#endif // HELPERS_HASH_TABLE_H