From ac4b39e6f5f7424248af8230d3f296ce973f9d67 Mon Sep 17 00:00:00 2001 From: zhengchao Date: Tue, 13 Apr 2021 19:20:41 +0800 Subject: [PATCH] =?UTF-8?q?Maat=5Fhierarchy=5Fregion=5Fcompile=E6=8C=89?= =?UTF-8?q?=E7=85=A7=E7=94=A8=E6=88=B7=E4=BC=A0=E5=85=A5=E7=9A=84=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E6=95=B0=E9=87=8F=E7=94=B3=E8=AF=B7=E7=BC=93=E5=AD=98?= =?UTF-8?q?=EF=BC=8C=E5=BD=93bool=20mactcher=E8=BF=94=E5=9B=9E=E7=9A=84?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E4=B8=AD=E5=8C=85=E5=90=AB=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E5=91=BD=E4=B8=AD=E8=BF=87=E7=9A=84compile=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=20=E5=8F=AF=E8=83=BD=E5=AF=BC=E8=87=B4bool=20matcher=E6=9C=AA?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=85=A8=E9=83=A8=E7=9A=84=E5=91=BD=E4=B8=AD?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/bool_matcher.h | 18 +++++------------- src/entry/Maat_hierarchy.cpp | 10 ++++------ src/entry/bool_matcher.cpp | 34 +++++++++++++--------------------- 3 files changed, 22 insertions(+), 40 deletions(-) diff --git a/inc/bool_matcher.h b/inc/bool_matcher.h index 33457de..195d78c 100644 --- a/inc/bool_matcher.h +++ b/inc/bool_matcher.h @@ -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); diff --git a/src/entry/Maat_hierarchy.cpp b/src/entry/Maat_hierarchy.cpp index 1db7500..81170ef 100644 --- a/src/entry/Maat_hierarchy.cpp +++ b/src/entry/Maat_hierarchy.cpp @@ -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; icompile_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) { diff --git a/src/entry/bool_matcher.cpp b/src/entry/bool_matcher.cpp index f868d3f..01ceaa1 100644 --- a/src/entry/bool_matcher.cpp +++ b/src/entry/bool_matcher.cpp @@ -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; ibool_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(imulti_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]; jmapped_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>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