Maat_hierarchy_region_compile按照用户传入的结果数量申请缓存,当bool mactcher返回的结果中包含之前命中过的compile时, 可能导致bool matcher未返回全部的命中结果。
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* All rights reserved
|
||||
*
|
||||
* Written by: LIU YANBING (liuyanbing@iie.ac.cn)
|
||||
* Last modification: 2021-01-01
|
||||
* Last modification: 2018-12-31
|
||||
*
|
||||
* This code is the exclusive and proprietary property of IIE-CAS and NELIST.
|
||||
* Usage for direct or indirect commercial advantage is not allowed without
|
||||
@@ -25,35 +25,27 @@ extern "C"
|
||||
#endif
|
||||
#define MAX_ITEMS_PER_BOOL_EXPR 8
|
||||
|
||||
/* not_flag=0表示布尔项item_id必须出现;not_flag=1表示布尔项item_id不能出现 */
|
||||
/*not_flag=0表示布尔项item_id必须出现;not_flag=1表示布尔项item_id不能出现*/
|
||||
struct bool_item
|
||||
{
|
||||
unsigned long long item_id;
|
||||
unsigned char not_flag;
|
||||
};
|
||||
|
||||
/* At least one item's not_flag should be 0. */
|
||||
/*注意:不支持布尔项全“非”的情形*/
|
||||
struct bool_expr
|
||||
{
|
||||
unsigned long long expr_id;
|
||||
void * user_tag;
|
||||
size_t item_num;
|
||||
struct bool_item items[MAX_ITEMS_PER_BOOL_EXPR];
|
||||
};
|
||||
|
||||
struct bool_expr_match
|
||||
{
|
||||
unsigned long long expr_id;
|
||||
void * user_tag;
|
||||
};
|
||||
|
||||
struct bool_matcher;
|
||||
|
||||
/* The elements in exprs array will be swapped to different indexes. */
|
||||
/*注意:本函数调用会交换bool_exprs中元素的位置*/
|
||||
struct bool_matcher * bool_matcher_new(struct bool_expr * exprs, size_t expr_num, unsigned int max_thread_num, size_t * mem_size);
|
||||
|
||||
/* Returned results are sorted by expr_id in descending order. */
|
||||
int bool_matcher_match(struct bool_matcher * matcher, unsigned int thread_id, const unsigned long long * item_ids, size_t item_num, struct bool_expr_match * results, size_t n_result);
|
||||
int bool_matcher_match(struct bool_matcher * matcher, unsigned int thread_id, const unsigned long long * item_ids, size_t item_num, void ** result, size_t size);
|
||||
|
||||
void bool_matcher_free(struct bool_matcher * matcher);
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ struct Maat_hierarchy
|
||||
int thread_num;
|
||||
struct Maat_garbage_bin* garbage_bin;
|
||||
void* logger;
|
||||
struct bool_expr_match *expr_match_buff;
|
||||
void **expr_match_buff;
|
||||
};
|
||||
|
||||
int compare_literal_id(const void *pa, const void *pb)
|
||||
@@ -297,7 +297,7 @@ struct Maat_hierarchy* Maat_hierarchy_new(int thread_num, void* mesa_handle_logg
|
||||
hier->hash_literal_by_id=NULL;
|
||||
hier->hash_region_by_id=NULL;
|
||||
|
||||
hier->expr_match_buff=ALLOC(struct bool_expr_match, thread_num*MAX_SCANNER_HIT_NUM);
|
||||
hier->expr_match_buff=ALLOC(void*, thread_num*MAX_SCANNER_HIT_NUM);
|
||||
|
||||
ret=igraph_empty(&hier->group_graph, 0, IGRAPH_DIRECTED);
|
||||
assert(ret==IGRAPH_SUCCESS);
|
||||
@@ -899,7 +899,6 @@ static struct bool_matcher* Maat_hierarchy_build_bool_matcher(struct Maat_hierar
|
||||
//some compile may have zero groups, e.g. default policy.
|
||||
if(j==(size_t)compile->declared_clause_num&&j>0)
|
||||
{
|
||||
bool_expr_array[expr_cnt].expr_id=compile->compile_id;
|
||||
bool_expr_array[expr_cnt].user_tag=compile;
|
||||
bool_expr_array[expr_cnt].item_num=j;
|
||||
expr_cnt++;
|
||||
@@ -1343,7 +1342,7 @@ int Maat_hierarchy_region_compile(struct Maat_hierarchy_compile_mid* mid, int is
|
||||
int bool_match_ret=0, i=0;
|
||||
struct Maat_hierarchy* hier=mid->ref_hier;
|
||||
struct Maat_hierarchy_compile* compile_array=NULL;
|
||||
struct bool_expr_match *expr_match=hier->expr_match_buff+mid->thread_num*MAX_SCANNER_HIT_NUM;
|
||||
void **expr_match=hier->expr_match_buff+mid->thread_num*MAX_SCANNER_HIT_NUM;
|
||||
|
||||
size_t r_in_c_cnt=0, this_scan_region_hits=mid->this_scan_region_hit_cnt;
|
||||
size_t ud_result_cnt=0;
|
||||
@@ -1358,8 +1357,7 @@ int Maat_hierarchy_region_compile(struct Maat_hierarchy_compile_mid* mid, int is
|
||||
expr_match, MAX_SCANNER_HIT_NUM);
|
||||
for(i=0; i<bool_match_ret && ud_result_cnt<ud_array_sz; i++)
|
||||
{
|
||||
compile_array=(struct Maat_hierarchy_compile*)expr_match[i].user_tag;
|
||||
assert((unsigned long long)compile_array->compile_id==expr_match[i].expr_id);
|
||||
compile_array=(struct Maat_hierarchy_compile*)expr_match[i];
|
||||
r_in_c_cnt=Maat_hierarchy_compile_mid_update_by_compile(mid, compile_array);
|
||||
if(compile_array->not_clause_cnt>0 && !is_last_compile)
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ struct thread_local_data_t
|
||||
{
|
||||
unsigned int mapped_ids[MAX_ARRAY_SIZE];
|
||||
unsigned int used_cells[MAX_ARRAY_SIZE];
|
||||
bool_expr_match cached_results[MAX_ARRAY_SIZE];
|
||||
void * cached_results[MAX_ARRAY_SIZE];
|
||||
unsigned char * multiexpr_bitmap;
|
||||
unsigned int * singlexpr_bitmap;
|
||||
};
|
||||
@@ -22,7 +22,7 @@ struct bool_matcher
|
||||
unsigned int max_thread_num;
|
||||
unsigned int bool_expr_num;
|
||||
unsigned int multi_expr_num;
|
||||
bool_expr_match * bool_expr_ids;
|
||||
void ** bool_expr_ids;
|
||||
unsigned char * multi_expr_size;
|
||||
unsigned char * multi_expr_mask;
|
||||
unsigned int bool_item_id_num;
|
||||
@@ -78,8 +78,8 @@ struct bool_matcher * bool_matcher_new(struct bool_expr * exprs, size_t expr_num
|
||||
matcher->bool_expr_num=(unsigned int)expr_num;
|
||||
matcher->multi_expr_num=I;
|
||||
|
||||
matcher->bool_expr_ids=new bool_expr_match[expr_num];
|
||||
mem_bytes+=(unsigned int)expr_num*sizeof(bool_expr_match);
|
||||
matcher->bool_expr_ids=new void *[expr_num];
|
||||
mem_bytes+=(unsigned int)expr_num*sizeof(void *);
|
||||
|
||||
matcher->multi_expr_size=new unsigned char[matcher->multi_expr_num+1];
|
||||
mem_bytes+=(matcher->multi_expr_num+1)*sizeof(unsigned char);
|
||||
@@ -105,8 +105,7 @@ struct bool_matcher * bool_matcher_new(struct bool_expr * exprs, size_t expr_num
|
||||
unsigned int count=0;
|
||||
for(unsigned int i=0; i<expr_num; i++)
|
||||
{
|
||||
matcher->bool_expr_ids[i].expr_id=exprs[i].expr_id;
|
||||
matcher->bool_expr_ids[i].user_tag=exprs[i].user_tag;
|
||||
matcher->bool_expr_ids[i]=exprs[i].user_tag;
|
||||
if(i<matcher->multi_expr_num)
|
||||
{
|
||||
matcher->multi_expr_size[i]=(unsigned int)exprs[i].item_num;
|
||||
@@ -161,14 +160,7 @@ struct bool_matcher * bool_matcher_new(struct bool_expr * exprs, size_t expr_num
|
||||
return matcher;
|
||||
}
|
||||
|
||||
int res_comp(const void * lhs, const void * rhs)
|
||||
{
|
||||
bool_expr_match * _lhs=(bool_expr_match *)lhs;
|
||||
bool_expr_match * _rhs=(bool_expr_match *)rhs;
|
||||
return (_lhs->expr_id<_rhs->expr_id) ? 1 : -1;
|
||||
}
|
||||
|
||||
int bool_matcher_match(struct bool_matcher * matcher, unsigned int thread_id, const unsigned long long * item_ids, size_t item_num, struct bool_expr_match * results, size_t n_result)
|
||||
int bool_matcher_match(struct bool_matcher * matcher, unsigned int thread_id, const unsigned long long * item_ids, size_t item_num, void ** result, size_t size)
|
||||
{
|
||||
if(matcher==NULL) return -1;
|
||||
if(thread_id>=matcher->max_thread_num) return -1;
|
||||
@@ -194,7 +186,7 @@ int bool_matcher_match(struct bool_matcher * matcher, unsigned int thread_id, co
|
||||
|
||||
for(unsigned int j=matcher->mapped_ptr[h]; j<matcher->mapped_ptr[h+1]; j++)
|
||||
{
|
||||
if(ids_num==MAX_ARRAY_SIZE) continue;
|
||||
if(ids_num==MAX_ARRAY_SIZE) return -1;
|
||||
mapped_ids[ids_num++]=matcher->mapped_ids[j];
|
||||
}
|
||||
}
|
||||
@@ -203,7 +195,7 @@ int bool_matcher_match(struct bool_matcher * matcher, unsigned int thread_id, co
|
||||
unsigned int used_num=0;
|
||||
for(unsigned int i=0; i<ids_num; i++)
|
||||
{
|
||||
if(used_num==MAX_ARRAY_SIZE) continue;
|
||||
if(used_num==MAX_ARRAY_SIZE) return -1;
|
||||
used_cells[used_num++]=(mapped_ids[i]>>3);
|
||||
}
|
||||
|
||||
@@ -246,7 +238,7 @@ int bool_matcher_match(struct bool_matcher * matcher, unsigned int thread_id, co
|
||||
}
|
||||
|
||||
unsigned int r=0;
|
||||
bool_expr_match * cached_results=matcher->thread_data[thread_id].cached_results;
|
||||
void ** cached_results=matcher->thread_data[thread_id].cached_results;
|
||||
|
||||
for(unsigned int i=0; i<used_num; i++)
|
||||
{
|
||||
@@ -268,15 +260,15 @@ int bool_matcher_match(struct bool_matcher * matcher, unsigned int thread_id, co
|
||||
}
|
||||
}
|
||||
|
||||
qsort(cached_results, r, sizeof(bool_expr_match), res_comp);
|
||||
sort(cached_results, cached_results+r);
|
||||
|
||||
int I=0;
|
||||
for(unsigned int J=0; J<r; ++J)
|
||||
{
|
||||
if(I==0 || cached_results[J].expr_id!=results[I-1].expr_id)
|
||||
if(I==0 || cached_results[J]!=result[I-1])
|
||||
{
|
||||
if(I==(int)n_result) return I;
|
||||
results[I++]=cached_results[J];
|
||||
if(I==(int)size) return I;
|
||||
result[I++]=cached_results[J];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user