本文整理汇总了C++中Tuple::getTokenFromPairAt方法的典型用法代码示例。如果您正苦于以下问题:C++ Tuple::getTokenFromPairAt方法的具体用法?C++ Tuple::getTokenFromPairAt怎么用?C++ Tuple::getTokenFromPairAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tuple
的用法示例。
在下文中一共展示了Tuple::getTokenFromPairAt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: solvedQueryToString
string Relation::solvedQueryToString(vector<Token>& inputTokens)
{
string out;
vector<Token> noStrings = removeStrings(inputTokens);
vector<std::pair<Token, vector<int> > > myMap;
for(int i = 0; i < noStrings.size(); i++)
{
bool inserted = false;
for(int j = 0; j < myMap.size(); j++)
{
if(myMap[j].first.getTokensValue() == noStrings[i].getTokensValue())
{
myMap[j].second.push_back(i);
inserted = true;
}
}
if(!inserted && noStrings[i].getTokenType() == ID)
{
vector<int> newVec;
newVec.push_back(i);
myMap.push_back(pair<Token, vector<int> >(noStrings[i], newVec) );
}
}
for(set<Tuple>::iterator it = tuples->begin(); it != tuples->end(); it++)
{
int firstInMapVector = 0;
Tuple thisTuple = (*it);
if(thisTuple.toString() != "")
{
out += "\n ";
}
for(int i = 0; i < myMap.size(); i++)
{
if(myMap[i].first.getTokenType() == ID)
{
out += myMap[i].first.getTokensValue() + "=";
out += thisTuple.getTokenFromPairAt(myMap[i].second[firstInMapVector]).getTokensValue();
if(i + 1 != myMap.size())
{
out += ", ";
}
}
}
}
return out;
}
示例2: select
Relation Relation::select(vector<Token>& inputTokens)
{
Relation newRelation = (*this);
set<Tuple>* newTuples = new set<Tuple>();
map<Token, vector<int> > myMap;
for(int i = 0; i < inputTokens.size(); i++)
{
if(inputTokens[i].getTokenType() == ID)
{
bool inserted = false;
for(map<Token, vector<int> >::iterator it = myMap.begin(); it != myMap.end(); it++)
{
if(it->first.getTokensValue() == inputTokens[i].getTokensValue())
{
it->second.push_back(i);
inserted = true;
}
}
if(!inserted)
{
vector<int> newVec;
newVec.push_back(i);
myMap.insert(pair<Token, vector<int> >(inputTokens[i], newVec) );
}
}
}
//Goes through all Tuples in THIS relation, checks if all query strings match, and adds matching tuples to the returned relation
for(set<Tuple>::iterator it = tuples->begin(); it != tuples->end(); it++) //for all tuples in THIS
{
bool isTrue = true;
Tuple tempTuple = (*it);
Tuple thisTuple = tempTuple;
for(int j = 0; j < thisTuple.getPairVectorSize(); j++) //for all pairs in this tuple
{
for(int i = 0; i < inputTokens.size(); i++) //for all parameters in the query
{
//CHECKS FOR TUPLES WITH CORRECT STRING COMBINATIONS
if(inputTokens[i].getTokenType() == STRING && j == i) //if this parameter is the placeholder string
{
if(inputTokens[i].getTokensValue() != thisTuple.getTokenFromPairAt(j).getTokensValue()) //if the values don't match
{
isTrue = false; //do not add to the new relation
}
}
//CHECK FOR TUPLES WITH DUPLICATE VALUES FOR DUPLICATE IDs IN QUERY
else if(inputTokens[i].getTokenType() == ID)
{
for(map<Token, vector<int> >::iterator mit = myMap.begin(); mit != myMap.end(); mit++)
{
for(int k = 0; k < thisTuple.getPairVectorSize(); k++)
{
for(int h = 0; h < mit->second.size(); h++)
{
if(k == mit->second[h])
{
for(int n = 0; n < mit->second.size(); n++)
{
if(thisTuple.getPairs()[k].second.getTokensValue() != thisTuple.getPairs()[mit->second[n]].second.getTokensValue())
{
isTrue = false;
}
}
}
}
}
}
}
}
}
if(isTrue) //otherwise add the tuple to the new relation
{
newTuples->insert(thisTuple);
}
}
set<Tuple>* deleteSet = newRelation.getTuples();
newRelation.setTuples(newTuples);
delete deleteSet;
return newRelation;
}