/*============================================================================= # Filename: ResultFilter.cpp # Author: Jiaqi, Chen # Mail: chenjiaqi93@163.com # Last Modified: 2016-05-03 15:36 # Description: implement functions in ResultFilter.h =============================================================================*/ #include "ResultFilter.h" using namespace std; void ResultFilter::addVar(string var) { if (this->result_filter.count(var) == 0) this->result_filter.insert(make_pair(var, make_pair(0, vector(this->MAX_SIZE, 0)))); } void ResultFilter::changeResultHashTable(SPARQLquery &query, int value) { long tv_begin = Util::get_cur_time(); for (int i = 0; i < query.getBasicQueryNum(); i++) { BasicQuery &basicquery = query.getBasicQuery(i); vector &basicquery_result =basicquery.getResultList(); int result_num = basicquery_result.size(); int var_num = basicquery.getVarNum(); for (int j = 0; j < var_num; j++) this->addVar(basicquery.getVarName(j)); vector* > refer; for (int j = 0; j < var_num; j++) { this->result_filter[basicquery.getVarName(j)].first += value; refer.push_back(&this->result_filter[basicquery.getVarName(j)].second); } for (int j = 0; j < result_num; j++) for (int k = 0; k < var_num; k++) { (*refer[k])[this->hash(basicquery_result[j][k])] += value; } } long tv_end = Util::get_cur_time(); printf("after ResultFilter::change, used %d ms.\n", tv_end - tv_begin); } void ResultFilter::candFilterWithResultHashTable(BasicQuery &basicquery) { for (int j = 0; j < basicquery.getVarNum(); j++) { map > >::iterator iter = this->result_filter.find(basicquery.getVarName(j)); if (iter != this->result_filter.end() && iter->second.first != 0) { vector &col = iter->second.second; IDList &idlist = basicquery.getCandidateList(j); IDList new_idlist; printf("candFilter on %s\n", basicquery.getVarName(j).c_str()); printf("before candFilter, size = %d\n", idlist.size()); long tv_begin = Util::get_cur_time(); for (int k = 0; k < idlist.size(); k++) { int id = idlist.getID(k); if (col[hash(id)] > 0) { new_idlist.addID(id); } } idlist = new_idlist; long tv_end = Util::get_cur_time(); printf("after candFilter, size = %d, used %d ms.\n", idlist.size(), tv_end - tv_begin); } } }