Exemple #1
0
   // Return a root with variable v.
   // If root does not exist, create it.
 void ForceTree(const Variable & v,SFSGNode *& result) {
   if(!FindTree(v,result)) {
     result = new SFSGNode(v);
     pair<const Variable,SFSGNode *> pr(v,result);
     d_tree_map.insert(pr);
   };
 }; 
Exemple #2
0
 ///function to insert shuffled values one by one into the Map
 void insert_random() {
     long i = 0;
     while ( i < n ) {
         hashmap.insert ( PAIR ( data[i], 2 * data[i] ) );
         i++;
     }
 }
    void
    verify_MultimapIters()  ///< @see IterTools_test#verify_filterRepetitions
    {
        MAP testMap;
        for (uint i=0; i<NUM_ELMS; ++i)
        {
            uint n = 1 + rand() % 100;
            do testMap.insert (make_pair (i,n));
            while (--n);
        }
        CHECK (NUM_ELMS < testMap.size(), "no repetition in test data??");

        IntIter keys = eachDistinctKey (testMap);

        cout << "distinct_keys";
        CHECK (keys);
        pullOut (keys);
        CHECK (!keys);

        cout << "values_4_key";
        IntIter vals = eachValForKey (testMap, NUM_ELMS); // non-existent key
        CHECK (!vals);

        vals = eachValForKey (testMap, 0);
        CHECK (vals);
        pullOut (vals); // should produce anything between 1 and 100 entries
        CHECK (!vals);
    }
		static CSession*		New( const CSocket& sock, DWORD dwMask, IProtocol* pProtocol = NULL ){
			CSession*	pSession	= new CSession(sock, dwMask, pProtocol);
			if( pSession ){
				m_Sessions.insert( PAIR(sock.GetHandle(), pSession) );
				return pSession;
			}
			return NULL;
		}
Exemple #5
0
  void operator+=(simple_poly const &p1) {    
    for(const_iterator i(p1.terms.begin());i!=p1.terms.end();++i) {      
      iterator j = terms.find(i->first);
      if(j != terms.end()) {
	j->second += i->second;
      } else {
	terms.insert(std::make_pair(i->first,i->second));
      }
    }
  }
int main()
{
	typedef map<string, int> MAP;
	MAP removal;
	string removal_word = "Anna";
	removal.insert(MAP::value_type(removal_word, 47)); 
 	if (removal.erase(removal_word))
 		cout << "Ok," << removal_word << " removed" << endl;
	else
		cout << "oops" <<removal_word << "not found!" <<endl;
	
	return 0;
}
int main(){
	MAP member;
	member.insert(make_pair(1000000000,1));		//使用strength做key关键字,因为题目已经给出了 实力值不可能相等 的条件
	int strength,id;							//也可使用id做key关键字,但这样每一次都需要完整遍历一次map,容易造成TLE
	int n;
	int low,high;
	cin >> n;
	while(n--){
		cin >> id >> strength;
		member.insert(make_pair(strength,id));
		MAP::iterator i,j,k;
		i = member.find(strength);
		if(i != member.end()){
			if(i == member.begin()){
				j = i;
				j++;
				cout << i->second << " " << j->second << endl;
			}
			else{
				j = i;
				k = i;
				j++;
				k--;
				low = i->first - k->first;
				high = j->first - i->first;
				if(low <= high){
					cout << i->second << " " << k->second << endl;
				}
				else{
					cout << i->second << " " << j->second << endl;
				}
			}
		}
		else continue;
	}
	return 0;
}
// [[Rcpp::export]]
SEXP map_AddKeyVal(SEXP m, SEXP k, SEXP val) {
    MAP* list = (MAP*)R_ExternalPtrAddr(m);
    if (!list) return R_NilValue;
    
    if (!Rf_isString(k)) 
        return R_NilValue;
    
    std::string keystr = as<std::string>(k);
    
    if (!__map_hasKey(m,k))
        list->insert(pair<string,unsigned long>(keystr,local_getPtr(val)));
    else 
        return R_NilValue; 
    
    return m;
    
}
Exemple #9
0
void ConfigHandler::setParametersInternal(string configFile, MAP& configMap) {

	ifstream ifs(configFile.c_str(), ifstream::in);

	const char *delimiter = Const::CFG_DELIMITERS.c_str();

	string line;
	while (getline(ifs, line)) {

		string remains = Const::toString(line);
		if (remains.empty())
			continue;

		size_t found = remains.find(delimiter);

		if (found != string::npos) {

			string one = Const::toString(remains.substr(0, int(found)));
			string two = Const::toString(remains.substr(int(found) + 1));

			if (one.empty() || two.empty())
				continue;

			if (one.substr(0, 1) == "#") //starts with #, means comment
				continue;

			string name = one;
			string value = two;

			if (!name.empty() && !value.empty()) {

				ConfigEntry ce(name, value);
				configMap.insert(PAIR(ce.toString(), ce)); //todo: use hash code to reduce size of key/value pair.
			}
		}
	}

	ifs.close();
}
Exemple #10
0
void ConfHandler::setParametersInternal(string configFile, MAP& configMap) {

    ifstream ifs(configFile.c_str(), ifstream::in);

    const char *delimiter = Const::CONF_DELIMITERS.c_str();

    string line;
    while (getline(ifs, line)) {

        string remains = line;

        if (remains.empty())
            continue;

        if (remains.substr(0, 1) == "#") //starts with #, means comment
            continue;

        StrTokenizer strtok(remains);

        string one;
        string two;

        if (strtok.has_more_tokens())
            one = strtok.next_token();

        if (strtok.has_more_tokens())
            two = strtok.next_token();

        if (one.empty())
            continue;

        ConfEntry ce(one, two);
        configMap.insert(PAIR(ce.toString(), ce)); //todo: use hash code to reduce size of key/value pair.
    }

    ifs.close();
}
Exemple #11
0
 void insert(unsigned int n, xy_term const &t) {
   terms.insert(std::make_pair(simple_poly_term(t.xpower,t.ypower),n)); 
 }
Exemple #12
0
 simple_poly(unsigned int n, unsigned int x, unsigned int y) {
   if(x > 0 || y > 0) { terms.insert(std::make_pair(simple_poly_term(x,y),n)); }
 }
Exemple #13
0
 simple_poly(xy_term const &t) {
   if(t.xpower > 0 || t.ypower > 0) { terms.insert(std::make_pair(simple_poly_term(t.xpower,t.ypower),1)); }
 }
Exemple #14
0
	CSession*		Create( UINT id ){
		CSession* pSession = new CSession(id);
		if( pSession )
			m_map.insert( PAIR(id, pSession) );
		return pSession;
	}