当前位置: 首页>>代码示例>>C++>>正文


C++ hash_map类代码示例

本文整理汇总了C++中hash_map的典型用法代码示例。如果您正苦于以下问题:C++ hash_map类的具体用法?C++ hash_map怎么用?C++ hash_map使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了hash_map类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init

	void init(){
		string ff;
		hash_map<int, string> user;
		ifstream fin("in");
		int k = 0;

		while (true){
			if (fin.eof())break;
			fin >> ff;
			vector<string> tmp;
			split(ff, ",", tmp);
			hash_map<string, vector<Node>*>::iterator it = mylog.find(tmp[0]);
			if (it == mylog.end()){
				vector<Node>* newVector = new vector<Node>();
				mylog[tmp[0]] = newVector;
				user[k++] = tmp[0];
			}

			mylog[tmp[0]]->push_back(Node(tmp[0], tmp[1], tmp[2], tmp[3]));
		}
		fin.close();
		hash_map<string, vector<Node>*>::iterator it;
		for (it = mylog.begin(); it != mylog.end(); it++){
			vector<string> v;
			net[it->first] = v;
			for (int i = 0; i < 5; i++){
				int ran = rand() % 9999;
				net[it->first].push_back(user[ran]);
			}
		}
	}
开发者ID:ladfaa,项目名称:CCF,代码行数:31,代码来源:源.cpp

示例2: while

  void query_recommender::merge_recommended_queries(std::multimap<double,std::string,std::less<double> > &related_queries,
      hash_map<const char*,double,hash<const char*>,eqstr> &update)
  {
    hash_map<const char*,double,hash<const char*>,eqstr>::iterator hit;
    std::multimap<double,std::string,std::less<double> >::iterator mit
    = related_queries.begin();
    while(mit!=related_queries.end())
      {
        std::string rquery = (*mit).second;
        if ((hit = update.find(rquery.c_str()))!=update.end())
          {
            (*hit).second = std::min((*mit).first,(*hit).second);
            std::multimap<double,std::string,std::less<double> >::iterator mit2 = mit;
            ++mit;
            related_queries.erase(mit2);
          }
        else ++mit;
      }
    hit = update.begin();
    hash_map<const char*,double,hash<const char*>,eqstr>::iterator chit;
    while(hit!=update.end())
      {
        related_queries.insert(std::pair<double,std::string>((*hit).second,std::string((*hit).first)));
        chit = hit;
        ++hit;
        free_const((*chit).first);
      }

  }
开发者ID:Psycojoker,项目名称:seeks,代码行数:29,代码来源:query_recommender.cpp

示例3: replace

	void replace(string user){

		double min = 1000;
		int minI = -1;
		for (int i = 0; i < net[user].size(); i++){
			double tmp = sim(user, net[user][i]);
			if (min > tmp){
				min = tmp;
				minI = i;
			}
		}
		double max = -10000;
		string kk;
		hash_map<string, vector<Node>*>::iterator it;
		for (it = mylog.begin(); it != mylog.end(); it++){
			if (in(it->first, net[user])){
				continue;
			}
			double tmp = sim(user, it->first);
			if (max < tmp){
				max = tmp;
				kk = it->first;
			}
		}
		if (min < max){
			net[user][minI] = kk;
		}
	}
开发者ID:ladfaa,项目名称:CCF,代码行数:28,代码来源:源.cpp

示例4: GetHatFit

static double GetHatFit( // args same as non CACHE version, see below
    int          x,      // in
    int          y,      // in
    const HatFit hatfit) // in
{
    const double* descbuf = NULL;       // the HAT descriptor
    // for max cache hit rate, x and y should divisible by HAT_SEARCH_RESOL
    CV_DbgAssert(x % HAT_SEARCH_RESOL == 0);
    CV_DbgAssert(y % HAT_SEARCH_RESOL == 0);
    if (TRACE_CACHE)
        ncalls_g++;
    const unsigned key(Key(x, y));
    #pragma omp critical                // prevent OpenMP concurrent access to cache_g
    {
        hash_map<unsigned, VEC>:: const_iterator it(cache_g.find(key));
        if (it != cache_g.end())        // in cache?
        {
            descbuf = Buf(it->second);  // use cached descriptor
            if (TRACE_CACHE)
                nhits_g++;
        }
    }
    if (descbuf == NULL)                // descriptor not in cache?
    {
        const VEC desc(hat_g.Desc_(x, y));
        #pragma omp critical            // prevent OpenMP concurrent access to cache_g
        cache_g[key] = desc;            // remember descriptor for possible re-use
        descbuf = Buf(desc);
    }
    return hatfit(descbuf);
}
开发者ID:GianpaoloR,项目名称:polyphemus,代码行数:31,代码来源:hatdesc.cpp

示例5: Compute

Value VarExpression::Compute(const hash_map<string, Value>& vars) const
{
	if (vars.find(name) == vars.end())
		throw UnknownIdentifierException(name);

	return vars.find(name)->second;
}
开发者ID:stormbreakerbg,项目名称:stormsql,代码行数:7,代码来源:Expression.cpp

示例6: print_tree

  void print_tree(const ast &tree, hash_map<expr*,symbol> &cnames, std::ostream &out){
    hash_map<expr*,symbol>::iterator foo = cnames.find(to_expr(tree.raw()));
    if(foo != cnames.end()){
      symbol nm = foo->second;
      if (is_smt2_quoted_symbol(nm)) {
	out << mk_smt2_quoted_symbol(nm);
      }
      else {
	out << nm;
      }
    }
    else if(op(tree) == And){
      out << "(and";
      int nargs = num_args(tree);
      for(int i = 0; i < nargs; i++){
	out << " ";
	print_tree(arg(tree,i), cnames, out);
      }
      out << ")";
    }
    else if(op(tree) == Interp){
      out << "(interp ";
      print_tree(arg(tree,0), cnames, out);
      out << ")";
    }
    else throw iz3pp_bad_tree();
  }
开发者ID:jackluo923,项目名称:juxta,代码行数:27,代码来源:iz3pp.cpp

示例7: Moca_AddToMap

/*
 * Insert key in map
 * Returns A pointer to the hash_entry corresponding to key
 *         Null in case of error
 * status is set to:
 *         The position of hash_entry in case of success
 *         One of the following in case of errors:
 *          MOCA_HASHMAP_ALREADY_IN_MAP
 *          MOCA_HASHMAP_FULL
 *          MOCA_HASHMAP_ERROR
 */
hash_entry Moca_AddToMap(hash_map map, hash_entry e, int *status)
{
    unsigned long h;
    int ind=0;
    unsigned int nextPos;
    if(!map)
    {
        *status=MOCA_HASHMAP_ERROR;
        return NULL;
    }
    if(map->nbentry==map->tableSize)
    {
        *status=MOCA_HASHMAP_FULL;
        return NULL;
    }
    //Do the insertion
    nextPos=Moca_FindNextAvailPosMap(map);
    MOCA_DEBUG_PRINT("Moca inserting %p ind %d/%lu total %d\n",
            e->key,nextPos,map->tableSize, map->nbentry);
    if(nextPos >= map->tableSize)
    {
        *status=MOCA_HASHMAP_ERROR;
        Moca_Panic("Moca hashmap BUG in AddToMap");
        return NULL;
    }
    //Update the link
    h=hash_ptr(e->key, map->hash_bits);
    ind=map->hashs[h];
    //TODO refactor here
    if(ind<0)
    {
        memcpy(tableElt(map,nextPos),e,map->elt_size);
        tableElt(map,nextPos)->next=MOCA_HASHMAP_END;
        map->hashs[h]=nextPos;
    }
    else
    {
        while(map->comp(tableElt(map,ind),e)!=0 &&
                tableElt(map,ind)->next>=0)
            ind=tableElt(map,ind)->next;
        if(map->comp(tableElt(map,ind),e)==0)
        {
            MOCA_DEBUG_PRINT("Moca %p already in map %p\n", e->key, map);
            *status=MOCA_HASHMAP_ALREADY_IN_MAP;
            //This seems useless
            tableElt(map,nextPos)->key=NULL;
            return tableElt(map,ind);
        }
        MOCA_DEBUG_PRINT("Moca collision in map %p key %p\n", map, e->key);
        //TODO: Use Memcpy
        memcpy(tableElt(map,nextPos),e,map->elt_size);
        tableElt(map,nextPos)->next=MOCA_HASHMAP_END;
        tableElt(map,ind)->next=nextPos;
    }
    ++map->nbentry;
    MOCA_DEBUG_PRINT("Moca Inserted %p in map %p\n", e->key, map);
    *status=nextPos;
    return tableElt(map,nextPos);
}
开发者ID:chubbymaggie,项目名称:MOCA,代码行数:70,代码来源:moca_hashmap.c

示例8: DumpDOT

void DumpDOT(
	char *Filename,
	multimap <OperandPosition,OperandPosition,OperandPositionCompareTrait> &InstructionMap,
	hash_map <ea_t,insn_t> &InstructionHash
)
{
	HANDLE hFile=OpenLogFile(Filename);
	//InstructionMap
	//InstructionHash
	WriteToLogFile(hFile,"digraph g {\r\n\
		graph [\r\n\
		rankdir = \"TB\"\r\n\
		];\r\n\
		node [\r\n\
		fontsize = \"12\"\r\n\
		];\r\n\
		edge [\r\n\
		];\r\n");

	//shape = \"ellipse\"\r\n\

	hash_map <ea_t,insn_t>::iterator InstructionHashIter;
	//Write Node Data
	for(InstructionHashIter=InstructionHash.begin();InstructionHashIter!=InstructionHash.end();InstructionHashIter++)
	{
		ea_t address=InstructionHashIter->first;
		char op_buffer[100]={0,};
		ua_mnem(address,op_buffer,sizeof(op_buffer));

		WriteToLogFile(hFile,"\"%X\" [\r\n\tlabel=\"%s",address,op_buffer);
		for(int i=0;i<UA_MAXOP;i++)
		{
			if(InstructionHashIter->second.Operands[i].type>0)
			{
				char operand_str[MAXSTR]={0,};
				ua_outop(address,operand_str,sizeof(operand_str)-1,i);
				tag_remove(operand_str,operand_str,0);
				char *escaped_operand_str=EscapeString(operand_str);
				if(escaped_operand_str)
				{
					WriteToLogFile(hFile,"|<f%u>%s",i,escaped_operand_str);
					free(escaped_operand_str);
				}
			}
		}
		WriteToLogFile(hFile,"\"\r\n\tshape=\"record\"\r\n];\r\n\r\n");
	}

	multimap <OperandPosition,OperandPosition,OperandPositionCompareTrait>::iterator InstructionMapIter;
	for(InstructionMapIter=InstructionMap.begin();InstructionMapIter!=InstructionMap.end();InstructionMapIter++)
	{
		WriteToLogFile(hFile,"\"%X\":f%u -> \"%X\":f%u\r\n",
			InstructionMapIter->first.Address,
			InstructionMapIter->first.Index,
			InstructionMapIter->second.Address,
			InstructionMapIter->second.Index);
	}
	CloseLogFile(hFile);
}
开发者ID:BwRy,项目名称:DarunGrim,代码行数:59,代码来源:IDAAnalysis.cpp

示例9: normalize

Lit normalize(Lit a) {
  while (true) {
    hash_map<Lit, Lit>::const_iterator i = equivalences.find(a);
    if (i == equivalences.end()) break;
    a = i->second;
  }
  return a;
}
开发者ID:Federico2014,项目名称:edg4x-rose,代码行数:8,代码来源:binaryClauseSimplify.C

示例10: GetSuitableField

Field VarExpression::GetSuitableField(const string& fieldName, const hash_map<string, Field>& v) const
{
	if (v.find(name) == v.end())
		throw UnknownIdentifierException(name);

	Field f = v.find(name)->second;
	return Field(fieldName.c_str(), f.type, f.size);
}
开发者ID:stormbreakerbg,项目名称:stormsql,代码行数:8,代码来源:Expression.cpp

示例11: set_replicating_map

 void ReplicateInfoMessage::set_replicating_map(const hash_map<uint32_t, ReplBlock*>& src)
 {
   hash_map<uint32_t, ReplBlock*>::const_iterator it = src.begin();
   for (; it != src.end(); ++it)
   {
     replicating_map_.insert(REPL_BLOCK_MAP::value_type(it->first, *(it->second)));
   }
 }
开发者ID:qqiangwu,项目名称:annotated-tfs,代码行数:8,代码来源:server_status_message.cpp

示例12: countPairs

void countPairs(vector<Event*> &events){

  for( vector<Event*>::iterator fst = events.begin();
       fst != events.end(); fst++){
    
    for( vector<Event*>::iterator snd = fst;
         snd != events.end() && snd - fst < THRESHOLD; snd++){

      if( (*fst)->thread != (*snd)->thread ){

        string fString = (*fst)->btString();
        string sString = (*snd)->btString();
      
        bool found = false;

        pthread_rwlock_rdlock( &histoLock );
        if( histo.find( fString ) != histo.end() ){
          
          if( histo[fString].find( sString ) != histo[fString].end() ){
            found = true;
            histo[fString][sString][snd-fst]++;
          }

        }
        pthread_rwlock_unlock( &histoLock );

        if( !found ){

          pthread_rwlock_wrlock( &histoLock );

          if( (histo.find( fString )) == histo.end() ){
            histo.insert(
              std::pair<string,
                        hash_map<string, vector<unsigned long> > >(fString,
                                                                   hash_map<string, vector<unsigned long> >()));
          }

          if( histo[fString].find(sString) == histo[fString].end() ){
            histo[fString].insert(std::pair<string,
                                            vector<unsigned long> >(sString,
                                                                    vector<unsigned long>()));
            for(int i = 0; i < THRESHOLD; i++ ){
              histo[fString][sString].push_back(0);
            }
          } 
          assert(snd - fst < THRESHOLD);
          histo[fString][sString][snd-fst]++;
          pthread_rwlock_unlock( &histoLock );

        }
         
      } 
      
    }
    
  }

}
开发者ID:blucia0a,项目名称:Aviso,代码行数:58,代码来源:computePairHistogram.cpp

示例13: lookup

locale _Catalog_locale_map::lookup(int key) const
{
    if (M) {
        hash_map<int, locale>::iterator i = M->find(key);
        return i != M->end() ? (*i).second : locale::classic();
    }
    else
        return locale::classic();
}
开发者ID:bencz,项目名称:OrangeC,代码行数:9,代码来源:message_facets.cpp

示例14: addColor

int addColor(const string & s) {
  hash_map<string, int>::iterator found = colorMap.find(s);
  if (found == colorMap.end()) {
    colorMap[s] = totalColors;
    return totalColors++;
  } else {
    return found->second;
  }
}
开发者ID:pavel-zeman,项目名称:CodeJam,代码行数:9,代码来源:B2.cpp

示例15: CheckIfHaveCreative

void AdGroupPool::CheckIfHaveCreative(hash_map<Ice::Long, AdGroupPtr> & group_pool) {
  for (hash_map<Ice::Long, AdGroupPtr>::iterator git = group_pool.begin(); git != group_pool.end();) {
    if (!git->second->HasCreatives()) {
//      MCE_DEBUG("AdGroupPool::Init --> because obj->HasCreatives is false so erase it  groupid = " << git->first);
      group_pool.erase(git++);
    } else{
      ++git;
    }
  }
}
开发者ID:bradenwu,项目名称:oce,代码行数:10,代码来源:AdCache.cpp


注:本文中的hash_map类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。