MySet<WebPage*> SearchEng::one_word_search(std::string word){//word is lowercase
	MySet<WebPage*> cand_search_result;

	MySet<WebPage*> match_search = word_to_setofwps[word];

	//go through all the wps that match and add their outgoing and incoming links into the new set
	MySet<WebPage*>::iterator it;
	for(it = match_search.begin(); it != match_search.end(); ++it){
		cand_search_result.insert(*it);

		MySet<WebPage*> outgoingSet = (*it)->outgoing_links();
		MySet<WebPage*>::iterator itOut;
		for(itOut = outgoingSet.begin(); itOut != outgoingSet.end(); ++itOut){
			cand_search_result.insert(*itOut);
		}

		MySet<WebPage*> incomingSet = (*it)->incoming_links();
		MySet<WebPage*>::iterator itIn;
		for(itIn = incomingSet.begin(); itIn != incomingSet.end(); ++itIn){
			cand_search_result.insert(*itIn);
		}
	}

	return cand_search_result;
}	
MySet<WebPage*> SearchEng::OR_command(std::vector<std::string> words_to_search){
	MySet<WebPage*> cand_search_result;

	MySet<WebPage*> match_search;
	for(unsigned int i = 0; i< words_to_search.size(); i++){
		if(word_to_setofwps.count(words_to_search[i] ) ){// word in search exists in our map
			match_search = match_search.set_union( word_to_setofwps[words_to_search[i] ] );
		}
	}

	//go through all the wps that match and add their outgoing and incoming links into the new set
	MySet<WebPage*>::iterator it;
	for(it = match_search.begin(); it != match_search.end(); ++it){
		cand_search_result.insert(*it);

		MySet<WebPage*> outgoingSet = (*it)->outgoing_links();
		MySet<WebPage*>::iterator itOut;
		for(itOut = outgoingSet.begin(); itOut != outgoingSet.end(); ++itOut){
			cand_search_result.insert(*itOut);
		}

		MySet<WebPage*> incomingSet = (*it)->incoming_links();
		MySet<WebPage*>::iterator itIn;
		for(itIn = incomingSet.begin(); itIn != incomingSet.end(); ++itIn){
			cand_search_result.insert(*itIn);
		}
	}

	return cand_search_result;
} 
MySet<WebPage*> SearchEng::AND_command(std::vector<std::string> words_to_search){
	MySet<WebPage*> cand_search_result;

	MySet<WebPage*> match_search;
	if(word_to_setofwps.count(words_to_search[0] ) ){
		match_search = word_to_setofwps[words_to_search[0] ];
	}
	if(words_to_search.size() > 1){//search has more than one word
		for(unsigned int i = 1; i< words_to_search.size(); ++i){
			if(word_to_setofwps.count(words_to_search[i] ) ){// word in search exists in our map
				match_search = match_search.set_intersection( word_to_setofwps[words_to_search[i] ] );
			}else{//word is not in our map, return empty set
				match_search.clear();
				return match_search;
			}
		}
	}

	//go through all the wps that match and add their outgoing and incoming links into the new set
	MySet<WebPage*>::iterator it;
	for(it = match_search.begin(); it != match_search.end(); ++it){
		cand_search_result.insert(*it);

		MySet<WebPage*> outgoingSet = (*it)->outgoing_links();
		MySet<WebPage*>::iterator itOut;
		for(itOut = outgoingSet.begin(); itOut != outgoingSet.end(); ++itOut){
			cand_search_result.insert(*itOut);
		}

		MySet<WebPage*> incomingSet = (*it)->incoming_links();
		MySet<WebPage*>::iterator itIn;
		for(itIn = incomingSet.begin(); itIn != incomingSet.end(); ++itIn){
			cand_search_result.insert(*itIn);
		}
	}


	return cand_search_result;
	
}
Beispiel #4
0
int main(int argc, char** argv) {
    std::string s = "transformers";
    
    printf("Old string is: %s \n", s.c_str());
    
    std::transform(s.begin(), s.end(), s.begin(), ::toupper);
    
    printf("New string is: %s \n", s.c_str());
    
    typedef std::map<int, double> MyMap;
    std::map<int, double> M;
    
    typedef std::set<int> MySet;
    MySet S;
    
    typedef std::set<double> MySet2;
    MySet2 S2;
    
    
    M[1] = 452.334;
    M[3] = 15.35;
    M[178] = 16.28;
    M[32] = 478.6789;
    
    // The bind method is the equivalent of select1st 
    // (which is only avail via SGI STL)
    std::transform(M.begin(), M.end(), std::inserter(S, S.begin()), 
            std::bind(&MyMap::value_type::first, _1));
    
    
    printf("======== dump keys ======= \n");
    std::for_each(S.begin(), S.end(), printVal);
    
    std::transform(M.begin(), M.end(), std::inserter(S2, S2.begin()), 
            std::bind(&MyMap::value_type::second, _1));
    printf("======== dump values with for_each== \n");
    std::for_each(S2.begin(), S2.end(), printVal2);
    
    MySet2::iterator it = S2.begin();
    
    printf("======== dump values with loop=== \n");
    while (it != S2.end()) {
        printf("%f \n", *it);
        it++;
    }
    printf("========\n");
    
    return 0;
    
}