2016-09-18 20:01:57 +08:00
|
|
|
/*=============================================================================
|
|
|
|
# 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)
|
|
|
|
{
|
2016-09-25 22:14:36 +08:00
|
|
|
if (this->result_filter.count(var) == 0)
|
|
|
|
this->result_filter.insert(make_pair(var, make_pair(0, vector<int>(this->MAX_SIZE, 0))));
|
2016-09-18 20:01:57 +08:00
|
|
|
}
|
|
|
|
|
2016-09-25 22:14:36 +08:00
|
|
|
void ResultFilter::changeResultHashTable(SPARQLquery &query, int value)
|
2016-09-18 20:01:57 +08:00
|
|
|
{
|
2016-09-25 22:14:36 +08:00
|
|
|
long tv_begin = Util::get_cur_time();
|
2016-09-18 20:01:57 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < query.getBasicQueryNum(); i++)
|
|
|
|
{
|
2016-09-25 22:14:36 +08:00
|
|
|
BasicQuery &basicquery = query.getBasicQuery(i);
|
2017-03-24 20:10:43 +08:00
|
|
|
vector<unsigned*> &basicquery_result =basicquery.getResultList();
|
2016-09-18 20:01:57 +08:00
|
|
|
int result_num = basicquery_result.size();
|
|
|
|
int var_num = basicquery.getVarNum();
|
|
|
|
|
|
|
|
for (int j = 0; j < var_num; j++)
|
|
|
|
this->addVar(basicquery.getVarName(j));
|
|
|
|
|
2016-09-25 22:14:36 +08:00
|
|
|
vector<vector<int>* > refer;
|
2016-09-18 20:01:57 +08:00
|
|
|
for (int j = 0; j < var_num; j++)
|
2016-09-25 22:14:36 +08:00
|
|
|
{
|
|
|
|
this->result_filter[basicquery.getVarName(j)].first += value;
|
|
|
|
refer.push_back(&this->result_filter[basicquery.getVarName(j)].second);
|
|
|
|
}
|
2016-09-18 20:01:57 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2016-09-25 22:14:36 +08:00
|
|
|
|
|
|
|
long tv_end = Util::get_cur_time();
|
|
|
|
printf("after ResultFilter::change, used %d ms.\n", tv_end - tv_begin);
|
2016-09-18 20:01:57 +08:00
|
|
|
}
|
|
|
|
|
2016-09-25 22:14:36 +08:00
|
|
|
void ResultFilter::candFilterWithResultHashTable(BasicQuery &basicquery)
|
2016-09-18 20:01:57 +08:00
|
|
|
{
|
2016-09-25 22:14:36 +08:00
|
|
|
for (int j = 0; j < basicquery.getVarNum(); j++)
|
2016-09-18 20:01:57 +08:00
|
|
|
{
|
2016-09-25 22:14:36 +08:00
|
|
|
map<string, pair<int, vector<int> > >::iterator iter = this->result_filter.find(basicquery.getVarName(j));
|
|
|
|
if (iter != this->result_filter.end() && iter->second.first != 0)
|
2016-09-18 20:01:57 +08:00
|
|
|
{
|
2016-09-25 22:14:36 +08:00
|
|
|
vector<int> &col = iter->second.second;
|
|
|
|
|
|
|
|
IDList &idlist = basicquery.getCandidateList(j);
|
|
|
|
IDList new_idlist;
|
2016-09-18 20:01:57 +08:00
|
|
|
|
2016-09-25 22:14:36 +08:00
|
|
|
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();
|
2016-09-18 20:01:57 +08:00
|
|
|
|
2016-09-25 22:14:36 +08:00
|
|
|
for (int k = 0; k < idlist.size(); k++)
|
|
|
|
{
|
|
|
|
int id = idlist.getID(k);
|
|
|
|
if (col[hash(id)] > 0)
|
2016-09-18 20:01:57 +08:00
|
|
|
{
|
2016-09-25 22:14:36 +08:00
|
|
|
new_idlist.addID(id);
|
2016-09-18 20:01:57 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-25 22:14:36 +08:00
|
|
|
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);
|
2016-09-18 20:01:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-24 20:10:43 +08:00
|
|
|
|