Esempio n. 1
0
void getNB(HashGraph* G, int v, int distance, hash_set<int>& result, vector<bool>& mark)
{
	assert(distance==1 || distance==2);
	
	EdgeMap* p_neighbors=G->getNeighbors(v);
	EdgeMap::iterator pnb;
    for (pnb=p_neighbors->begin(); pnb!=p_neighbors->end(); pnb++)
    {
            UINT w=pnb->first;
            if(!mark[w])
            	result.insert(w);
    }
	
	if(distance==1)
		return;
	
	hash_set<int>::iterator p;
	vector<int> temp;
	for(p=result.begin(); p!=result.end(); p++)
		temp.push_back(*p);
	int imnb_size=result.size();
	//result.clear();
	for(int i=0; i<imnb_size; i++)
	{
		p_neighbors=G->getNeighbors(temp[i]);
		for (pnb=p_neighbors->begin(); pnb!=p_neighbors->end(); pnb++)
		{
			UINT w=pnb->first;
			if(!mark[w]) 
				result.insert(w); //automatically handel duplication.
		}
	}
	for(int i=0; i<imnb_size; i++)
		result.erase(temp[i]);
}
Esempio n. 2
0
static void updateHelper (SLE::ref entry,
    hash_set< uint256 >& seen,
    OrderBookDB::IssueToOrderBook& destMap,
    OrderBookDB::IssueToOrderBook& sourceMap,
    hash_set< Issue >& XDVBooks,
    int& books)
{
    if (entry->getType () == ltDIR_NODE &&
        entry->isFieldPresent (sfExchangeRate) &&
        entry->getFieldH256 (sfRootIndex) == entry->getIndex())
    {
        Book book;
        book.in.currency.copyFrom (entry->getFieldH160 (sfTakerPaysCurrency));
        book.in.account.copyFrom (entry->getFieldH160 (sfTakerPaysIssuer));
        book.out.account.copyFrom (entry->getFieldH160 (sfTakerGetsIssuer));
        book.out.currency.copyFrom (entry->getFieldH160 (sfTakerGetsCurrency));

        uint256 index = getBookBase (book);
        if (seen.insert (index).second)
        {
            auto orderBook = std::make_shared<OrderBook> (index, book);
            sourceMap[book.in].push_back (orderBook);
            destMap[book.out].push_back (orderBook);
            if (isXDV(book.out))
                XDVBooks.insert(book.in);
            ++books;
        }
    }
}
Esempio n. 3
0
int main(int iArgc, char* apcArgv[])
{
	assert(iArgc >= 3);

	{
		_getcwd(g_acBuffer, 2048);
		_chdir(apcArgv[2]);
		_getcwd(g_acSave, 2048);
		_chdir(g_acBuffer);
		_chdir(apcArgv[1]);
		_getcwd(g_acLoad, 2048);

		char acBuffer[2048];
		_getcwd(acBuffer, 2048);
		printf_s("Working directory is: %s\n", acBuffer);
	}

	tm_sep.insert('*');
	tm_sep.insert(',');
	tm_sep.insert(' ');
	tm_sep.insert('\t');

	func_Type["return"] = FUNC_RETURN;
	func_Type["param"] = FUNC_PARAM;

	spec_Type["define:"] = SPEC_DEFINE;
	spec_Type["enum:"] = SPEC_ENUM;
	spec_Type["passthru:"] = SPEC_PASSTHRU;
	spec_Type["passend:"] = SPEC_PASSTHRU;

	trans["class"] = "class1";

	g_kTypeMap["LPCSTR"] = "LPCSTR";

	vector<const char*> kNameList;

	kNameList.clear();
	kNameList.push_back("enum.spec");
	kNameList.push_back("enumext.spec");
	kNameList.push_back("gl.spec");
	Generate("gl", kNameList);
	kNameList.clear();
	kNameList.push_back("glxenum.spec");
	kNameList.push_back("glxenumext.spec");
	kNameList.push_back("glxext.spec");
	kNameList.push_back("glx.spec");
	Generate("glX", kNameList);
	kNameList.clear();
	kNameList.push_back("wglenum.spec");
	kNameList.push_back("wglenumext.spec");
	kNameList.push_back("wgl.spec");
	kNameList.push_back("wglext.spec");
	Generate("wgl", kNameList);
	
	return 0;
}
Esempio n. 4
0
int fun(){
    ut i, t;
    Node one = {0}, next;
    tab.clear();
    for(i=0;i<SIZ;i++){
        cin>>t;
        if(t){
            one.m |= (1<<i);
            one.s++;
        } 
    }
    priority_queue<Node, vector<Node>, Node::cmp> q;
    q.push(one);
    while(!q.empty()){
        one=q.top(); q.pop();
        if(one.m == 0)
            break;
        for(i=0;i<SIZ;i++){
            next = one;
            next.o |= (1<<i);
            set(next,i);
            if(tab.find(next.m) == tab.end()){
                q.push(next);
                tab.insert(next.m);
            }
        }
    }
    output(one.o);
    return 0;
}
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();
  }
}
Esempio n. 6
0
string		square_anagram(string s1, string s2)
{
    int			len = s1.length(), i;
    string		ret;

    for (i = 0; i < len; i++)
        if ((s1[i] >= 'A' && s1[i] <= 'Z'))
            break;
    if (i == len)
    {
        if (squares.find(s1) != squares.end() && squares.find(s2) != squares.end())
        {
            if (s1 > s2)
                return s1;
            return s2;
        }
        return "";
    }
    for (char c = '9'; c >= (i == 0 ? '1' : '0'); c--)
    {
        char save = s1[i];
        if (used.find(c) != used.end())
            continue;
        replace_all(s1, s2, s1[i], c);
        used.insert(c);
        if ((ret = square_anagram(s1, s2)) != "")
            return ret;
        used.erase(c);
        replace_all(s1, s2, c, save);
    }
    return "";
}
void ReadNum(ifstream &input,hash_set<long> &myset)
{
	long num;
	while(!input.fail()){
		input>>num;
		myset.insert(num);
	}
}
Esempio n. 8
0
 static_string () {
     if (!s_static_string_set) {
         s_static_string_set = VNEW hash_set<string>;
     }
     string value ( "" );
     const string &v = s_static_string_set->insert ( value );
     m_str = v.c_str();
 }
Esempio n. 9
0
/// ComputeNodesReacahbleFrom - Compute the set of nodes in the specified
/// inverse graph that are reachable from N.  This is a simple depth first
/// search.
///
static void ComputeNodesReachableFrom(DSNode *N,
                            std::set<std::pair<DSNode*,DSNode*> > &InverseGraph,
                                      hash_set<const DSNode*> &Reachable) {
  if (!Reachable.insert(N).second) return;  // Already visited!
  
  std::set<std::pair<DSNode*,DSNode*> >::iterator I = 
    InverseGraph.lower_bound(std::make_pair(N, (DSNode*)0));
  for (; I != InverseGraph.end() && I->first == N; ++I)
    ComputeNodesReachableFrom(I->second, InverseGraph, Reachable);
}
Esempio n. 10
0
int main(){
    
    for(int i=0;i<100;i++){
        tab.insert(2*i + 1);
    }
    for(hash_set<int>::iterator iter = tab.begin();
            iter!=tab.end();
            iter++){
        cout<<(*iter)<<" ";
    }
    cout<<endl;

	return 0;
}
Esempio n. 11
0
void TDDataStructures::markReachableFunctionsExternallyAccessible(DSNode *N,
                                                   hash_set<DSNode*> &Visited) {
  if (!N || Visited.count(N)) return;
  Visited.insert(N);

  for (unsigned i = 0, e = N->getNumLinks(); i != e; ++i) {
    DSNodeHandle &NH = N->getLink(i);
    if (DSNode *NN = NH.getNode()) {
      std::vector<const Function*> Functions;
      NN->addFullFunctionList(Functions);
      ArgsRemainIncomplete.insert(Functions.begin(), Functions.end());
      markReachableFunctionsExternallyAccessible(NN, Visited);
    }
  }
}
Esempio n. 12
0
    static_string ( const char *str ) {
		euint32 hash_value = calc_hashnr ( str, _strlen ( str ) );
		xhn::hash_set<string>::bucket& b = s_static_string_set.get_bucket(hash_value);
		{
			SpinLock::Instance inst = b.m_lock.Lock();
			xhn::list<xhn::string>::iterator iter = b.begin();
			xhn::list<xhn::string>::iterator end = b.begin();
			for (; iter != end; iter++) {
				if (*iter == str) {
					m_str = (*iter).c_str();
					return;
				}
			}
		}
		string value ( str );
		const string &v = s_static_string_set.insert ( value );
		m_str = v.c_str();
    }
Esempio n. 13
0
void TDDataStructures::ComputePostOrder(const Function* F,
                                        hash_set<DSGraph*> &Visited,
                                        std::vector<DSGraph*> &PostOrder) {
  if (F->isDeclaration()) return;
  DSGraph* G = getOrFetchDSGraph(F);
  if (Visited.count(G)) return;
  Visited.insert(G);

  // Recursively traverse all of the callee graphs.
  for (DSGraph::fc_iterator CI = G->fc_begin(), CE = G->fc_end(); CI != CE; ++CI){
    Instruction *CallI = CI->getCallSite().getInstruction();
    for (calleeTy::iterator I = callee.begin(CallI),
           E = callee.end(CallI); I != E; ++I)
      ComputePostOrder(*I, Visited, PostOrder);
  }

  PostOrder.push_back(G);
}
Esempio n. 14
0
void solve()
{
    int op,x;
    for( f>>N; N; --N )
    {
        f>>op>>x;
        switch( op )
        {
        case 1 :
            H.insert(x);
            break;
        case 2 :
            H.erase(x);
            break;
        case 3 :
            g<< ( H.find(x)!=H.end() ) <<"\n";
        }
    }
}
bool containsArrayOps(const ASTNode& n, hash_set<int> & visited)
{
        if (n.GetIndexWidth() > 0)
            return true;

        if (n.Degree() ==0)
            return false;

        if (visited.find(n.GetNodeNum()) != visited.end())
            return false;

        visited.insert(n.GetNodeNum());

	for (int i =0; i < n.Degree();i++)
		if (containsArrayOps(n[i],visited))
			return true;

	return false;
}
Esempio n. 16
0
// counts the number of reads. Shortcut when we get to the limit.
void numberOfReadsLessThan(const ASTNode& n, hash_set<int>& visited, int& soFar,
                           const int limit)
{
  if (n.isAtom())
    return;

  if (visited.find(n.GetNodeNum()) != visited.end())
    return;

  if (n.GetKind() == READ)
    soFar++;

  if (soFar > limit)
    return;

  visited.insert(n.GetNodeNum());

  for (size_t i = 0; i < n.Degree(); i++)
    numberOfReadsLessThan(n[i], visited, soFar, limit);
}
Esempio n. 17
0
int PE098()
{
    ifstream	fs;
    string		line;
    int			count = 0;

    fs.open("C:\\Users\\Karthik\\words2.txt", ifstream::in);
    getline(fs, line);
    istringstream ss(line);

    while (ss)
    {
        string		word, sig;
        if (!getline(ss, word, ','))
            break;
        sig = string_signature(word);
        if (anagrams.find(sig) != anagrams.end())
            anagrams[sig].push_back(word);
        else
        {
            vector<string> v(1, word);
            anagrams[sig] = v;
        }
    }
    for (long long i = 1; i * i <= MAX; i++)
        squares.insert(convert2string(i * i));
    for (map<string, vector<string> >::iterator it = anagrams.begin(); it != anagrams.end(); it++)
    {
        vector<string>		v = (*it).second;
        string				ret;

        if (v.size() == 2 && v[0].length() >= 4)
        {
            used.clear();
            if ("" != (ret = square_anagram(v[0], v[1])))
                cout << v[0] << "; " << v[1] << " == > " << ret << endl;
        }
    }
    fs.close();
    return 0;
}
Esempio n. 18
0
 void support(const ast &t, std::set<std::string> &res, hash_set<ast> &memo){
     if(memo.find(t) != memo.end()) return;
     memo.insert(t);
 
     int nargs = num_args(t);
     for(int i = 0; i < nargs; i++)
         support(arg(t,i),res,memo);
 
     switch(op(t)){
     case Uninterpreted:
         if(nargs == 0 || !is_tree) {
             std::string name = string_of_symbol(sym(t));
             res.insert(name);
         }
         break;
     case Forall:
     case Exists:
         support(get_quantifier_body(t),res,memo);
         break;
     default:;
     }
 }
Esempio n. 19
0
    static_string ( const char *str ) {
        if (!s_static_string_set) {
            s_static_string_set = VNEW hash_set<string>;
        }

		euint32 hash_value = calc_hashnr ( str, strlen ( str ) );
		xhn::hash_set<string>::bucket& b = s_static_string_set->get_bucket(hash_value);
		{
			SpinLock::Instance inst = b.m_lock.Lock();
			xhn::list<xhn::string>::iterator iter = b.begin();
			xhn::list<xhn::string>::iterator end = b.end();
			for (; iter != end; iter++) {
				if (strcmp(iter->c_str(),str) == 0) {
					m_str = iter->c_str();
					return;
				}
			}
		}

		string value ( str );
		const string &v = s_static_string_set->insert ( value );
		m_str = v.c_str();
    }
Esempio n. 20
0
void FilterIndex::eval(const Event* ev, hash_set<NodeID>& affectedNodes) {
	for (vector<HashIndexType*>::iterator hash_it = _index.begin();
		hash_it != _index.end(); ++hash_it) {
		hash_set<HashIndexIDType*>* pIDSet;
		hash_map<EventID, Instance*>* pInstSet;
		(*hash_it)->eval(ev->getBody(),pIDSet);

		if (pIDSet) {
			for (hash_set<HashIndexIDType*>::iterator it = pIDSet->begin();
				it != pIDSet->end(); ++it) {
				HashIndexIDType* pThisID = *it;

				Node* pCurNode = Node::_nodes[pThisID->first];

				//assert (pCurNode->getNodeType() != typeid(StartNode));
				if (pCurNode->getNodeType() == typeid(StartNode)) {
					affectedNodes.insert(pCurNode->getID());
					continue;
				}

				IntermediateNode* pCurIntNode 
					= (IntermediateNode*)pCurNode;
				//if the node is not active, skip it
				if(!pCurIntNode->hasInstance()) {
					continue;
				}

				if(pCurIntNode->_pFilter->_pDNF) {
					//evaluate the unindexed static predicates in clause 
					//pThisID->second 
					bool staSatisfied = pCurIntNode->_pFilter->_pDNF->
										_clauses[pThisID->second]->
										evalStatic(ev);
					if(!staSatisfied) {
						continue;
					}
				
					//evaluate the dynamic predicates.
					//first check whether there is dynamic index
					bool isDynIndexed = pCurIntNode->isClauseDynIndexed
						(pThisID->second);
					if(isDynIndexed) {					
						pCurIntNode->getDynFilterPredIndex()->
								eval(ev->getBody(), pInstSet);
						for (hash_map<EventID, Instance*>::iterator inst_it 
							= pInstSet->begin();
							inst_it != pInstSet->end(); 
							++inst_it) {
							Instance* pInst = inst_it->second;
							assert (pInst->getEndTime() < ev->getEndTime());

							//if this event overlaps with the time interval of the 
							//instance, cannot concatenate them
							if (pInst->getEndTime() >= ev->getStartTime()) {
								continue;
							}

							bool ret;											
							ConjunctiveClause* pThisClause = pCurIntNode->_pFilter
											->_pDNF->_clauses[pThisID->second];
							ret = pThisClause->evalDynamic(ev, pInst);					
							if (!ret) {
								continue;
							}
							else {						
								affectedNodes.insert(pCurNode->getID());
								pCurIntNode->
									_affectedInstances.insert(
									make_pair(inst_it->first, pInst));
							}
						}				
						continue;
					}
				}

				//if there is no dynamic predicate index. 
				//sequentially evaluate the dynamic filter predicate on
				//each instance under the node
				for (list<Instance*>::iterator inst_it 
					= pCurIntNode->_instances.begin();
					inst_it != pCurIntNode->_instances.end(); 
				++inst_it) {
					Instance* pInst = *inst_it;
					//luoluo 4-11
					// the following  statement maybe have some logic problem.
					//write just for processing .
					if (pInst->getStartTime()>ev->getStartTime())break;


					//Bug fix on 06.06.07
					//According to the way we process events (by epoches), 
					//the end time of the instance should always be less 
					//than the end time of the current event, since 
					//otherwise the instance should not be visible by the 
					//current event -- that instance will be put in pending 
					//list,not current list of its associated state.
	//				assert (pInst->getEndTime() < ev->getEndTime());
					//luoluo 4-13
					//the above sentence  have been changed .(be deleted )

					//if this event overlaps with the time interval of the 
					//instance, cannot concatenate them
					if (pInst->getEndTime() >= ev->getStartTime()) {
						continue;
					}

					bool ret;
					if (pCurIntNode->_pFilter->_pDNF == NULL) {
						ret = true;
					}
					else {
						ConjunctiveClause* pThisClause = pCurIntNode->_pFilter
							->_pDNF->_clauses[pThisID->second];
						ret = pThisClause->evalDynamic(ev, pInst);
					}
					if (!ret) {
						continue;
					}
					else {						
						affectedNodes.insert(pCurNode->getID());
						pCurIntNode->
							_affectedInstances.insert(
							make_pair(pInst->getID(), pInst));
					}
				}
			}
		}
	}

}
Esempio n. 21
0
void Query::mapNodesHelp(vector<Neighborhood>& nbs, HashGraph* Gdb, OrthologInfoList* pOrthinfolist_db, vector<int>& Vq, vector<int>& Vdb, GraphMatch* gm, Queue& Q, hash_set<int>& nodesInQ, vector<bool>& mark, vector<bool>& dbmark)
{
	vector<Neighborhood> dbnbh;
	bool* qvisit=new bool[Vq.size()];
	bool* dbvisit=new bool[Vdb.size()];
	for(unsigned int j=0; j<Vdb.size(); j++)
	{
		dbvisit[j]=false;
		Neighborhood nbh;
		nbh.degree=Gdb->degree(Vdb[j]);
		
		getNeighborhood(Gdb, (*pOrthinfolist_db), Vdb[j], nbh);
		dbnbh.push_back(nbh);
	}
	vector<MappingIndex> mcand;
	for(unsigned int i=0; i<Vq.size(); i++)
	{
		qvisit[i]=false;
		Neighborhood& nbh=nbs[Vq[i]];
		for(unsigned int j=0; j<Vdb.size(); j++)
		{
			MappingIndex m;
			m.indexv=i;
			m.indexw=j;
			if( getScore(nbh, dbnbh[j], m.score) )
				mcand.push_back(m);
		}
	}
	
	std::sort(mcand.begin(), mcand.end(), orderMappingIndexByScore);
	
	for(unsigned int i=0; i<mcand.size(); i++)
	{
		int vi=mcand[i].indexv;
		int wi=mcand[i].indexw;
		float score=mcand[i].score;
		if(!qvisit[vi] && !dbvisit[wi])
		{
			NodeMapping nm;
			nm.source=Vq[vi];
			nm.target=Vdb[wi];
				
			if(nodesInQ.find(Vq[vi])==nodesInQ.end())//Vq[vi] has no mapping in Q) 
			{
				qvisit[vi]=true;
				dbvisit[wi]=true;
				Q.insert(nm);
				nodesInQ.insert(nm.source);
				dbmark[nm.target]=true;
			}else
			{
				//find the mapping in Q
				Queue::iterator p;
				for(p=Q.begin(); p!=Q.end(); p++)
					if(p->source==Vq[vi])
						break;
				if( score < p->score )
				{
					qvisit[vi]=true;
					dbvisit[wi]=true;
					dbmark[p->target]=false;
					Q.erase(p);//edge tm= remove the mapping of m.source from Q 
					Q.insert(nm);
					//nodesInQ.insert(nm.source);
					dbmark[nm.target]=true;
				}else
				{
					qvisit[vi]=true;
				}
			}			
		}
	}
	
	delete [] dbvisit;
	delete [] qvisit;
}
Esempio n. 22
0
 static_string ( const char *str ) {
     string value ( str );
     const string &v = s_static_string_set.insert ( value );
     m_str = v.c_str();
 }
Esempio n. 23
0
 static_string () {
     string value ( "" );
     const string &v = s_static_string_set.insert ( value );
     m_str = v.c_str();
 }
Esempio n. 24
0
/*!	\brief Returns lists of applications to be asked to quit on shutdown.

	\param userApps List of RosterAppInfos identifying the user applications.
		   Those will be ask to quit first.
	\param systemApps List of RosterAppInfos identifying the system applications
		   (like Tracker and Deskbar), which will be asked to quit after the
		   user applications are gone.
	\param vitalSystemApps A set of team_ids identifying teams that must not
		   be terminated (app server and registrar).
	\return \c B_OK, if everything went fine, another error code otherwise.
*/
status_t
TRoster::GetShutdownApps(AppInfoList& userApps, AppInfoList& systemApps,
	AppInfoList& backgroundApps, hash_set<team_id>& vitalSystemApps)
{
	BAutolock _(fLock);

	status_t error = B_OK;

	// get the vital system apps:
	// * ourself
	// * kernel team
	// * app server
	// * debug server

	// ourself
	vitalSystemApps.insert(be_app->Team());

	// kernel team
	team_info teamInfo;
	if (get_team_info(B_SYSTEM_TEAM, &teamInfo) == B_OK)
		vitalSystemApps.insert(teamInfo.team);

	// app server
	RosterAppInfo* info
		= fRegisteredApps.InfoFor("application/x-vnd.haiku-app_server");
	if (info != NULL)
		vitalSystemApps.insert(info->team);

	// debug server
	info = fRegisteredApps.InfoFor("application/x-vnd.haiku-debug_server");
	if (info != NULL)
		vitalSystemApps.insert(info->team);

	// populate the other groups
	for (AppInfoList::Iterator it(fRegisteredApps.It());
			RosterAppInfo* info = *it; ++it) {
		if (vitalSystemApps.find(info->team) == vitalSystemApps.end()) {
			RosterAppInfo* clonedInfo = info->Clone();
			if (clonedInfo) {
				if (_IsSystemApp(info)) {
					if (!systemApps.AddInfo(clonedInfo))
						error = B_NO_MEMORY;
				} else if (info->flags & B_BACKGROUND_APP) {
					if (!backgroundApps.AddInfo(clonedInfo))
						error = B_NO_MEMORY;
				} else {
					if (!userApps.AddInfo(clonedInfo))
						error = B_NO_MEMORY;
				}

				if (error != B_OK)
					delete clonedInfo;
			} else
				error = B_NO_MEMORY;
		}

		if (error != B_OK)
			break;
	}

	// Special case, we add the input server to vital apps here so it is
	// not excluded in the lists above
	info = fRegisteredApps.InfoFor("application/x-vnd.Be-input_server");
	if (info != NULL)
		vitalSystemApps.insert(info->team);

	// clean up on error
	if (error != B_OK) {
		userApps.MakeEmpty(true);
		systemApps.MakeEmpty(true);
	}

	return error;
}