示例#1
0
文件: 1354.cpp 项目: ZhouWeikuan/zoj
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();
  }
}
示例#3
0
// Alínea D
int Aposta::calculaCertos(const hash_set<int> &sorteio) const{
	hash_set<int>::iterator it;
	int c =0;
	for (it=numeros.begin(); it!=numeros.end(); it++)
		if (sorteio.find(*it)!=sorteio.end()) c++;
	return c;
}
示例#4
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;
        }
    }
}
示例#5
0
void print(hash_set &S) {
  iterator_t p = S.begin();
  while(p!=S.end()) {
    cout << S.retrieve(p) << " ";
    p = S.next(p);
  }
  cout << endl;
}
示例#6
0
int GetCount(int a, int b) {
    int qres = a + b + 1, n = 1;
    while (primes.find(qres) != primes.end()) {
        n += 1;
        qres = n*n + n*a + b;
    }
    return n;
}
示例#7
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;
}
void LinearSNNClassifier::checkgradRowSparse(const vector<Example>& examples, mat& Wd, const mat& gradWd, const string& mark, int iter,
        const hash_set<int>& sparseRowIndexes, const mat& ft) {
    //Random randWdRowcheck = new Random(iter + "Row".hashCode() + hash));
    int charseed = mark.length();
    for (int i = 0; i < mark.length(); i++) {
        charseed = (int) (mark[i]) * 5 + charseed;
    }
    srand(iter + charseed);
    std::vector<int> idRows, idCols;
    idRows.clear();
    idCols.clear();
    if (sparseRowIndexes.empty()) {
        for (int i = 0; i < Wd.n_rows; ++i)
            idRows.push_back(i);
    } else {
        hash_set<int>::iterator it;
        for (it = sparseRowIndexes.begin(); it != sparseRowIndexes.end(); ++it)
            idRows.push_back(*it);
    }

    for (int idx = 0; idx < Wd.n_cols; idx++)
        idCols.push_back(idx);

    random_shuffle(idRows.begin(), idRows.end());
    random_shuffle(idCols.begin(), idCols.end());

    int check_i = idRows[0], check_j = idCols[0];

    double orginValue = Wd(check_i, check_j);

    Wd(check_i, check_j) = orginValue + 0.001;
    double lossAdd = 0.0;
    for (int i = 0; i < examples.size(); i++) {
        Example oneExam = examples[i];
        lossAdd += computeScore(oneExam);
    }

    Wd(check_i, check_j) = orginValue - 0.001;
    double lossPlus = 0.0;
    for (int i = 0; i < examples.size(); i++) {
        Example oneExam = examples[i];
        lossPlus += computeScore(oneExam);
    }

    double mockGrad = (lossAdd - lossPlus) / (0.002 * ft(check_i, check_j));
    mockGrad = mockGrad / examples.size();
    double computeGrad = gradWd(check_i, check_j);

    printf("Iteration %d, Checking gradient for %s[%d][%d]:\t", iter, mark.c_str(), check_i, check_j);
    printf("mock grad = %.18f, computed grad = %.18f\n", mockGrad, computeGrad);

    Wd(check_i, check_j) = orginValue;
}
示例#9
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;
}
示例#10
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 "";
}
示例#11
0
int trim_entropy_filter(vector<string>* keep_words, hash_set<string>& cad_words_set, WordInfoMap& wordinfo_map)
{
    keep_words->reserve(cad_words_set.size());
    for (hash_set<string>::iterator it = cad_words_set.begin(); it != cad_words_set.end(); ++it) {
        WordInfoMap::iterator it_map = wordinfo_map.find(*it);
        if (it_map == wordinfo_map.end()) {
            fprintf(stderr, "WARNING, word[%s] in cad_word, not in word_info", it->c_str());
            continue;
        }
        if (it_map->first.size() <= WORD_LEN - 4 && it_map->second.calc_is_keep()) {
            keep_words->push_back(*it);
        }
    }
    return 0;
}
示例#12
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);
    }
  }
}
void ReadNum(ifstream &input,hash_set<long> &myset)
{
	long num;
	while(!input.fail()){
		input>>num;
		myset.insert(num);
	}
}
示例#14
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();
 }
示例#15
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();
    }
示例#16
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);
}
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;
}
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";
        }
    }
}
示例#19
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);
}
示例#20
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);
}
示例#21
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;
}
示例#22
0
文件: query.cpp 项目: renqHIT/Tale
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]);
}
示例#23
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:;
     }
 }
示例#24
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();
    }
示例#25
0
文件: query.cpp 项目: renqHIT/Tale
void Query::mapNodes(vector<Neighborhood>& nbs, HashGraph* Gdb, OrthologInfoList* pOrthinfolist_db, hash_set<int>& Sq, hash_set<int>& Sdb, GraphMatch* gm, Queue& Q, hash_set<int>& nodesInQ, vector<bool>& mark, vector<bool>& dbmark)
{
	hash_set<int>::iterator p;
	hash_map< int, vector<int>, inthash > lmap_q, lmap_db;
	for(p=Sq.begin(); p!=Sq.end(); p++)
	{
		for(unsigned int i=0; i<(*pOrthinfolist)[*p].size(); i++)
		{
			if((*pOrthinfolist)[*p][i]==0)
				continue;
			lmap_q[(*pOrthinfolist)[*p][i]].push_back(*p);
		}
	}
	
	for(p=Sdb.begin(); p!=Sdb.end(); p++)
	{
		if(!dbmark[*p])
		{
			for(unsigned int i=0; i<(*pOrthinfolist_db)[*p].size(); i++)
			{
				if((*pOrthinfolist_db)[*p][i]==0)
					continue;
				lmap_db[(*pOrthinfolist_db)[*p][i]].push_back(*p);
			}
		}
	}
		
	hash_map<int, vector<int>, inthash>::iterator iter, iter2;
	for(iter=lmap_q.begin(); iter!=lmap_q.end(); iter++)
	{
		iter2=lmap_db.find(iter->first);
		if(iter2==lmap_db.end())
			continue;
		else
			mapNodesHelp(nbs, Gdb, pOrthinfolist_db, iter->second, iter2->second, gm, Q, nodesInQ, mark, dbmark);	
	}
}
示例#26
0
int gen_trim_entropy(hash_set<string>& cad_words_set, WordInfoMap* wordinfo_map)
{
    for (WordInfoMap::iterator it = wordinfo_map->begin(); it != wordinfo_map->end(); ++it) {
        string& word = const_cast<string&>(it->first);
        uint32_t freq = it->second.freq;
        if (word.length() >= 3 * 2) {//三个汉字,abc,插入词bc's left trim a,插入词ab's right trim c
            string left_trim(word.begin(), word.begin() + 2);
            string right_part(word.begin() + 2, word.end());
            if (cad_words_set.find(right_part) != cad_words_set.end()) {
                WordInfoMap::iterator it_r = wordinfo_map->find(right_part);
                if (it_r == wordinfo_map->end()) {
                    fprintf(stderr, "WARNING, word[%s] in cad word, not in word_info", right_part.c_str());
                    continue;
                }
                it_r->second.left_trim[left_trim] += freq;
#ifdef DEBUG
                fprintf(stderr, "DEBUG, word[%s],left_trim[%s]\n", word.c_str(), left_trim.c_str());
#endif
            }
            string right_trim(word.end() - 2, word.end());
            string left_part(word.begin(), word.end() - 2);
            if (cad_words_set.find(left_part) != cad_words_set.end()) {
                WordInfoMap::iterator it_l = wordinfo_map->find(left_part);
                if (it_l == wordinfo_map->end()) {
                    fprintf(stderr, "WARNING, word[%s] in cad_word, not in word_info", left_part.c_str());
                    continue;
                }
                it_l->second.right_trim[right_trim] += freq;
#ifdef DEBUG
                fprintf(stderr, "DEBUG, word[%s],right_trim[%s]\n", word.c_str(), right_trim.c_str());
#endif
            }
        }
    }
    return 0;
}
示例#27
0
void GetTmWorld(const char* pcBuffer, char* pcLeft, char* pcRight)
{
	while(*pcBuffer != '\0')
	{
		if(tm_sep.find(*pcBuffer) == tm_sep.end() || ((*pcBuffer) == ' '))
		{
			*pcLeft = *pcBuffer;
			++pcLeft;
			++pcBuffer;
		}
		else
		{
			break;
		}
	}
	*pcLeft = '\0';

	while(tm_sep.find(*pcBuffer) != tm_sep.end())
	{
		++pcBuffer;
	}

	while(*pcBuffer != '\0')
	{
		if(tm_sep.find(*pcBuffer) == tm_sep.end() || ((*pcBuffer) == ' ') || ((*pcBuffer) == '*'))
		{
			*pcRight = *pcBuffer;
			++pcRight;
			++pcBuffer;
		}
		else
		{
			break;
		}
	}
	*pcRight = '\0';
}
int main(int argc, char** argv) {
  SatProblem cnf;
  cnf.parse(stdin);

  size_t count = 0;

  while (count < 100) {
    cerr << "count = " << count << endl;

    equivalences.clear();
    implications.clear();
    for (size_t i = 0; i < cnf.clauses.size(); ++i) {
      if (cnf.clauses[i].size() == 0) {
        abort();
      } else if (cnf.clauses[i].size() == 1) {
        addEquivalence(cnf.clauses[i][0], TRUE);
        addEquivalence(invert(cnf.clauses[i][0]), FALSE);
      } else if (cnf.clauses[i].size() == 2) {
        implications[invert(cnf.clauses[i][0])].push_back(cnf.clauses[i][1]);
        implications[invert(cnf.clauses[i][1])].push_back(cnf.clauses[i][0]);
      } else {
        // Do nothing
      }
    }

    done.clear();
    for (hash_map<Lit, vector<Lit> >::const_iterator i = implications.begin();
         i != implications.end(); ++i) {
      vector<Lit> stack;
      // cerr << "Exploring " << i->first << endl;
      explore(i->first, stack);
    }

    vector<Clause> oldClauses = cnf.clauses;
    cnf.clauses.clear();

    for (size_t i = 0; i < oldClauses.size(); ++i) {
      Clause cl = oldClauses[i];
      for (size_t j = 0; j < cl.size(); ++j) {
        cl[j] = normalize(cl[j]);
      }
      cnf.addClause(cl);
    }

    for (size_t i = 0; i < cnf.interfaceVariables.size(); ++i) {
      InterfaceVariable& iv = cnf.interfaceVariables[i];
      for (size_t j = 0; j < iv.second.size(); ++j) {
        Lit oldLit = iv.second[j];
        Lit newLit = normalize(oldLit);
        iv.second[j] = newLit;
      }
    }

    if (equivalences.empty()) break; // No changes

    ++count;
  }

  cnf.unparse(stdout);

  return 0;
}
示例#29
0
 static_string () {
     string value ( "" );
     const string &v = s_static_string_set.insert ( value );
     m_str = v.c_str();
 }
示例#30
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;
}