Exemplo n.º 1
0
Arquivo: 源.cpp Projeto: ladfaa/CCF
	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]);
			}
		}
	}
Exemplo n.º 2
0
  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);
      }

  }
void explore(Lit l, vector<Lit>& stack) {
  if (find(stack.begin(), stack.end(), l) != stack.end()) {
    // Found cycle
    // cerr << "Found cycle from " << l << endl;
    for (vector<Lit>::const_iterator i = find(stack.begin(), stack.end(), l);
         ++i != stack.end(); ) {
      addEquivalence(l, *i);
      addEquivalence(invert(l), invert(*i));
      // cerr << ".. containing " << *i << endl;
    }
    // cerr << "End of cycle" << endl;
  } else if (find(stack.begin(), stack.end(), invert(l)) != stack.end()) {
    // We have not(l) -> l, so l is true
    addEquivalence(normalize(l), TRUE);
    addEquivalence(normalize(invert(l)), FALSE);
    // cerr << "Found known true literal " << l << endl;
  } else if (done.find(l) != done.end()) {
    // Nothing
  } else if (implications.find(l) == implications.end()) {
    // cerr << "Found pure literal " << l << endl;
  } else {
    done.insert(l);
    stack.push_back(l);
    for (size_t i = 0; i < implications[l].size(); ++i) {
      explore(implications[l][i], stack);
    }
    stack.pop_back();
  }
}
Exemplo n.º 4
0
Arquivo: 源.cpp Projeto: ladfaa/CCF
	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;
		}
	}
Exemplo n.º 5
0
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);
}
Exemplo n.º 6
0
Value VarExpression::Compute(const hash_map<string, Value>& vars) const
{
	if (vars.find(name) == vars.end())
		throw UnknownIdentifierException(name);

	return vars.find(name)->second;
}
void UpdateBest(string& str, int& best)
{
	if(f.find(str)!=f.end())
	{
		best=max(best,f[str]);
	}
}
Exemplo n.º 8
0
void read_words(const string filename) {
	assert(!open_word_list);

	ifstream fin(filename.c_str());
	assert(fin.is_open());

	_all_words.clear();

	word_list.clear();
	word_list.push_back("");
	assert(word_list.at(NO_WORD) == "");
	word_map.clear();
	word_map[""] = NO_WORD;		// FIXME: Don't use [] operator

	unsigned i;
	string word;
	while(!fin.eof()) {
		fin >> i >> ws >> word >> ws;

		word_list.push_back(word);
		assert(word_list.at(i) == word);
		word_map[word] = i;	// FIXME: Don't use [] operator
		_all_words.push_back(i);

//		if (word == "*content*") _Word_CONTENT = i;
	}
	assert(word_list.size() == word_map.size());

	cerr << "Read " << word_list.size()-1 << " words from '" << filename << "'\n";

	fin.close();
	open_word_list = true;
}
Exemplo n.º 9
0
bool process(state* astate, queue<state*>& bfsq)
{
	if(astate->clocks == ten9)
	{
		return print(astate);
	}
	
	for(int i=0; i<9; i++)
	{
		newstate.set(astate);
		newstate.inc(config[i]);
		//cout<<"trying state: "<<newstates[i].getnum()<<", foundsz="<<answers.size()<<endl;

		if(visited.find(newstate.clocks) == visited.end())
		{
			state *ns = new state();
			ns->clocks = newstate.clocks;
			ns->prevop = i+1;
		    ns->prevstate = astate;
			bfsq.push(ns);
			visited[ns->clocks] = true;
			nobj++;
		}
	}
	return true;
}
Exemplo n.º 10
0
  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();
  }
Exemplo n.º 11
0
/*
 * 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);
}
Exemplo n.º 12
0
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);
}
Exemplo n.º 13
0
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;
}
Exemplo n.º 14
0
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);
}
 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)));
   }
 }
Exemplo n.º 16
0
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 );

        }
         
      } 
      
    }
    
  }

}
Exemplo n.º 17
0
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();
}
Exemplo n.º 18
0
    //добавить переменную в таблицу символов
    static void add_var(const string& name)
    {
        if (table.find(name)!= table.end()) error("duplicate variable");
        else{
            if (table.size() > SIZEVART) error("too many variables");
            else table[name] = 0.0;
        }

    }
Exemplo n.º 19
0
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;
  }
}
Exemplo n.º 20
0
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;
    }
  }
}
Exemplo n.º 21
0
inline void* unparseAndIntern(SgAsmExpression* e) {
  hash_map<SgAsmExpression*, void*>::const_iterator i = unparseAndInternTable.find(e);
  if (i == unparseAndInternTable.end()) {
    void* sPtr = intern(unparseX86Expression(e, NULL));
    unparseAndInternTable.insert(std::make_pair(e, sPtr));
    return sPtr;
  } else {
    return i->second;
  }
}
Exemplo n.º 22
0
 // static.
 float oskmeans::enorm(const hash_map<uint32_t,float,id_hash_uint> &p)
 {
   float enorm = 0.0;
   hash_map<uint32_t,float,id_hash_uint>::const_iterator hit = p.begin();
   while (hit!=p.end())
     {
       enorm += (*hit).second*(*hit).second;
       ++hit;
     }
   return sqrt(enorm);
 }
Exemplo n.º 23
0
Arquivo: 源.cpp Projeto: ladfaa/CCF
	double sim(string follow, string leader){
		if (simMatrix.find(follow + leader) != simMatrix.end()){
			return simMatrix[follow + leader];
		}
		double t1 = getNum(follow, leader) - getNum2(follow, leader);
		double t2 = mylog[leader]->size();
		double t3 = 1 - 1 / sqrt(mylog[leader]->size());
		double res = t1 / t2*t3;
		simMatrix[follow + leader] = res;
		return res;
	}
Exemplo n.º 24
0
//在哈希词典中查找词,若找到,则返回,否则返回
int CDictionary::FindWord(string w)
 {
 if (wordhash.find(w) != wordhash.end())
 {
 return 1;
 }
 else
 {
 return 0;
 }
 }
Exemplo n.º 25
0
int YglIsCached(u32 addr, YglCache * c ) {

  hash_map< u32 , YglCache >::iterator pos =  g_TexHash.find(addr);
  if( pos == g_TexHash.end() )
  {
      return 0;
  }

  c->x=pos->second.x;
  c->y=pos->second.y;

  return 1;
}
void mapSave(string fileName, hash_map<int, int> &feature2kernel)
{
	ofstream outfile;
	outfile.open(fileName);

	for (hash_map<int, int>::iterator iter = feature2kernel.begin(); iter != feature2kernel.end(); iter++)
	{
		outfile << iter->first << " " << iter->second << endl;
	}

	outfile.close();

}
Exemplo n.º 27
0
void _Catalog_locale_map::insert(int key, const locale& L)
{
    // Don't bother to do anything unless we're using a non-default ctype facet
    try {
        typedef ctype<wchar_t> wctype;
        if (typeid(use_facet<wctype>(L)) != typeid(const wctype&)) {
            if (!M)
                M = new hash_map<int, locale>;
            if (M->find(key) == M->end())
                M->insert(pair<const int, locale>(key, L));
        }
    }
    catch(...) {}
}
Exemplo n.º 28
0
/***************************************************************************
 * Set symbol information
 ***************************************************************************/
bool CCilVm::setSymbolInformation( hash_map<wstring, CG_SYMBOL_INFORMATION>& symbolinfo)
{
	if( m_status != VM_EXECUTE_INITIALIZING ) return false;

	hash_map<wstring, CG_SYMBOL_INFORMATION>::iterator it = symbolinfo.begin();

	pair<wstring, CG_SYMBOL_INFORMATION> pair;
	for( ; it != symbolinfo.end(); ++it)
	{
		pair = *it;
		m_SymbolInfoPool[ pair.first ] = pair.second;
	}
	return true;
}
Exemplo n.º 29
0
/*************************************************
* Function: * check_connect_timeout
* Description: * 检测长时间没反应的网络连接,并关闭删除
* Input: *
* Output: *
* Others: *
*************************************************/
void *check_connect_timeout(void* para)
{
    hash_map<int, sockStruct>::iterator it_find;
    for(it_find = sock_map.begin(); it_find!=sock_map.end(); ++it_find){
        if( time((time_t*)0) - (it_find->second).time > 120){                //时间更改


            free((it_find->second).recvBuf);
            sock_map.erase(it_find);

            close(it_find->first);
        }
    }

}
Exemplo n.º 30
0
void InitHatLevData(   // init the global HAT data needed for this pyr level
    const Image& img,  // in
    int          ilev) // in
{
    if (ilev <= HAT_START_LEV) // we use HATs only at upper pyr levs
    {
        hat_g.Init_(img, PatchWidth(ilev));
#if CACHE
        if (TRACE_CACHE) // show results from previous run
            lprintf("[calls %d hitrate %.2f cachesize %d]\n",
                    ncalls_g, double(nhits_g) / ncalls_g, cache_g.size());
        cache_g.clear();
#endif
    }
}