From 177788a6ff1a94a00f20d695ae122c54343cc895 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 26 Jul 2020 02:57:15 +0800 Subject: [PATCH] update HRD_analy --- src/engine/HRD_analy.cpp | 81 ++++++++++++++++++++++++++++++++++++++++ src/engine/HRD_analy.h | 4 +- 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/src/engine/HRD_analy.cpp b/src/engine/HRD_analy.cpp index 55c4a9c..30447fc 100644 --- a/src/engine/HRD_analy.cpp +++ b/src/engine/HRD_analy.cpp @@ -100,6 +100,87 @@ void HRD_analy::Output_Graph(unsigned long long code, unsigned int square_width, cout << endl; } +bool HRD_analy::Get_Path(vector target, string File_name) { + Case_cal *address; + unsigned int i, j, k, num; + struct Highlight_point { + bool flag; + unsigned int index; + }; + vector < vector > Highlight; + Highlight.resize(Layer.size()); // 同步Layer的结构 + for (i = 0; i < Highlight.size(); i++) { + Highlight[i].resize(Layer[i].size()); + for (j = 0; j < Layer[i].size(); j++) { + Highlight[i][j].flag = false; + } + } + for (i = 0; i < target.size(); i++) { + if (!Search_Case(target[i], address)) {return false;} + Highlight[address->layer_num][address->layer_index].flag = true; + } + vector *case_list; + for (i = Layer.size() - 1; i > 0; i--) { // 反向遍历除第一层外的所有层 + num = 0; + for (j = 0; j < Layer[i].size(); j++) { // 遍历层内元素 + if (Highlight[i][j].flag) { // 若该元素被标识 + case_list = Layer[i][j]->source_case; + for (k = 0; k < case_list->size(); k++) { // 遍历其下一步 + Highlight[i - 1][(*case_list->at(k)).layer_index].flag = true; // 标识 + } + Highlight[i][j].index = num; + num++; + } + } + } + Highlight[0][0].index = 0; + ofstream output; + output.open(File_name); + output << "[Target]" << endl; + for (i = 0; i < target.size(); i++) { + output << Change_str(target[i]) << endl; + } + output << "[Layer]" << endl; + for (i = 0; i < Layer.size(); i++) { // 反向遍历除第一层外的所有层 + if (Layer[i].size() == 0) {break;} + for (j = 0; j < Layer[i].size(); j++) { // 遍历层内元素 + if (Highlight[i][j].flag) { + output << "(" << i << "," << Highlight[i][j].index << ") = " << Change_str(Layer[i][j]->code) << endl; + } + } + } + output << "[Next]" << endl; + for (i = 0; i < Layer.size(); i++) { // 反向遍历除第一层外的所有层 + if (Layer[i].size() == 0) {break;} + for (j = 0; j < Layer[i].size(); j++) { // 遍历层内元素 + if (Highlight[i][j].flag) { + output << "(" << i << "," << Highlight[i][j].index << ") ->"; + case_list = Layer[i][j]->next_case; + for (k = 0; k < case_list->size(); k++) { // 遍历其下一步 + if (Highlight[i + 1][(*case_list->at(k)).layer_index].flag) { + output << " (" << i + 1 << "," << Highlight[i + 1][(*case_list->at(k)).layer_index].index << ")"; + } + } + output << endl; + } + } + } + output.close(); + return true; +} + +bool HRD_analy::Search_Case(unsigned long long code, Case_cal* &dat) { + unsigned int i; + int hash_index = 0xffff & (code >> 16); // 取得哈希索引 + for (i = 0; i < Layer_hash[hash_index].size(); i++) { // 遍历索引内容 + if (Layer_hash[hash_index][i]->code == code) { // 发现目标 + dat = Layer_hash[hash_index][i]; + return true; + } + } + return false; +} + void HRD_analy::Output_Detail(string File_name) { // 输出分析结果到文件 unsigned int i, j, k; ofstream output; diff --git a/src/engine/HRD_analy.h b/src/engine/HRD_analy.h index b96e4c1..ae52c7a 100644 --- a/src/engine/HRD_analy.h +++ b/src/engine/HRD_analy.h @@ -18,7 +18,7 @@ class HRD_analy { vector *source_case; vector *next_case; }; - vector > Layer; // 储存全部层数据的节点 + vector < vector > Layer; // 储存全部层数据的节点 Case_cal Parse_dat; bool quiet = false; // true -> 静默模式 false -> 输出运算情况 // 布局的基本参数 @@ -39,6 +39,7 @@ class HRD_analy { bool Is_Mirror(unsigned long long code); void Analyse_Case(unsigned long long code); void Output_Detail(string File_name); + bool Get_Path(vector target, string File_name); void Free_Data(); void Output_Graph(unsigned long long code, unsigned int square_width, unsigned int square_gap, char str[2]); @@ -53,6 +54,7 @@ class HRD_analy { void Find_Next_Case(Case_cal &dat_raw); void Add_Case(Case_cal *dat); void Calculate(unsigned long long code); + bool Search_Case(unsigned long long code, Case_cal* &dat); }; #endif