Exemple #1
0
    void writeMetadataFile( const string coll, boost::filesystem::path outputFile, 
                            map<string, BSONObj> options, multimap<string, BSONObj> indexes ) {
        log() << "\tMetadata for " << coll << " to " << outputFile.string() << endl;

        ofstream file (outputFile.string().c_str());
        uassert(15933, "Couldn't open file: " + outputFile.string(), file.is_open());

        bool hasOptions = options.count(coll) > 0;
        bool hasIndexes = indexes.count(coll) > 0;

        if (hasOptions) {
            file << "{options : " << options.find(coll)->second.jsonString();

            if (hasIndexes) {
                file << ", ";
            }
        } else {
            file << "{";
        }

        if (hasIndexes) {
            file << "indexes:[";
            for (multimap<string, BSONObj>::iterator it=indexes.equal_range(coll).first; it!=indexes.equal_range(coll).second; ++it) {
                if (it != indexes.equal_range(coll).first) {
                    file << ", ";
                }
                file << (*it).second.jsonString();
            }
            file << "]";
        }
        file << "}";
    }
void ReservationTable::readtable()
{
	ifstream fin;
	fin.open("ReservationTable.txt",ifstream::in);
	if(!fin) 
	{
		cerr<<"Cannot open INVENTORY file!"<<endl;
		system("pause");
		exit(1);	
	}
	string str;
	getline(fin,str);
	stages=stoi(str);
	getline(fin,str);
	time=stoi(str);
	int i=0,j;
	cout<<"Reservation Table:\n  ";
	for(j=1; j<=time; ++j)
		cout<<"  "<<j;
	cout<<endl;
	while(!fin.eof())
	{
		getline(fin,str);
		++i;
		j=0;
		cout<<"S"<<i<<" ";
		for (string::iterator it=str.begin(); it!=str.end(); ++it)
		{
			cout<<" ";
			if(*it=='1')
			{ cout<<"X"; rtable.insert(pair<int,int>(i,++j)); }
			else if(*it=='0')
			{ cout<<" "; ++j; }
		}
		cout<<endl;
	}
	fin.close();
	vector<int> row;
	multimap<int,int>::iterator it;
	list<int>::iterator f;
	for(i=1; i<=stages; i++)
    {
		for(it=rtable.equal_range(i).first; it!=rtable.equal_range(i).second; ++it)
		row.push_back((*it).second);
		for(size_t p=0; p<row.size(); ++p)
		for(size_t q=p+1; q<row.size(); ++q)
		{
			f=find(forbidden.begin(),forbidden.end(),row[q]-row[p]);
			if(f==forbidden.end())
			forbidden.push_back(row[q]-row[p]);
		}
		row.clear();
	}
	stable_sort(forbidden.begin(),forbidden.end());
	cout<<"\nForbidden latencies: ";
	for (list<int>::iterator it=forbidden.begin(); it!=forbidden.end(); ++it)
    cout<<" "<<*it;
	cout<<endl;
}
Exemple #3
0
int main()
{
    init();

    rdio(namenum);

    lli n;
    cin >> n;
    if (M.count(n) > 0) {
        for (auto it = M.equal_range(n).first; it != M.equal_range(n).second; ++it) {
            cout << it->second << endl;
        }
    } else cout << "NONE" << endl;

    return 0;
}
Exemple #4
0
void delete_author(multimap<string, string> &books, const string &name){
	auto p = books.equal_range(name);
	if (p.first == p.second)
		cout << "No author named " << name << endl;
	else
		books.erase(p.first, p.second);
}
Exemple #5
0
    void solve(string cur)
    {
        // cout << cur << endl;
        while (true)
        {
            pair<trav_it, trav_it> ret = trav.equal_range(cur);

            if (ret.first == ret.second) break;
            else
            {
                // cout << "\tnot yet" << endl;
                trav_it to_del=ret.first;
                string next = ret.first->second;
                for (trav_it it = ret.first; it != ret.second; ++it)
                {
                    if (it->second < next) 
                    {
                        next = it->second;
                        to_del = it;
                    }
                }
                // cout << "\t" << next << endl;
                
                trav.erase(to_del);
                solve(next);
            }
        }
        ans.push_back(cur);
    }
Exemple #6
0
    void writeMetadataFile( const string coll, boost::filesystem::path outputFile, 
                            map<string, BSONObj> options, multimap<string, BSONObj> indexes ) {
        toolInfoLog() << "\tMetadata for " << coll << " to " << outputFile.string() << std::endl;

        bool hasOptions = options.count(coll) > 0;
        bool hasIndexes = indexes.count(coll) > 0;

        BSONObjBuilder metadata;

        if (hasOptions) {
            metadata << "options" << options.find(coll)->second;
        }

        if (hasIndexes) {
            BSONArrayBuilder indexesOutput (metadata.subarrayStart("indexes"));

            // I'd kill for C++11 auto here...
            const pair<multimap<string, BSONObj>::iterator, multimap<string, BSONObj>::iterator>
                range = indexes.equal_range(coll);

            for (multimap<string, BSONObj>::iterator it=range.first; it!=range.second; ++it) {
                 indexesOutput << it->second;
            }

            indexesOutput.done();
        }

        ofstream file (outputFile.string().c_str());
        uassert(15933, "Couldn't open file: " + outputFile.string(), file.is_open());
        file << metadata.done().jsonString();
    }
Exemple #7
0
 vector<int> query_quad(size_t id) {
     vector<int> ret;
     auto multimap_qry = flat_tree.equal_range(id);
     for(auto it = multimap_qry.first; it != multimap_qry.second; ++it){
         ret.push_back(it->second);
     }
     return ret;
 }
Exemple #8
0
set<InterfaceKey> enabler_inputst::key_translation(EventMatch &match) {
  set<InterfaceKey> bindings;
  pair<multimap<EventMatch,InterfaceKey>::iterator,multimap<EventMatch,InterfaceKey>::iterator> its;
  
  for (its = keymap.equal_range(match); its.first != its.second; ++its.first)
    bindings.insert((its.first)->second);

  return bindings;
}
Exemple #9
0
 void query(Vec2i pos, vector<Transformable*> &result)
 {
     //auto range = buckets.equal_range(Vec2i(pos / resolution));
     auto range = obj_buckets.equal_range(pos);
     for (auto i = range.first; i != range.second; ++i)
     {
         result.push_back(i->second);
     }
 }
	int pick(int target) {
		auto p = mmnums.equal_range(target);
		if (p.first == p.second) return -1;
		vector<int> idxs;
		for (auto it = p.first; it != p.second; ++it) {
			idxs.push_back(it->second);
		}
		return idxs[rand() % idxs.size()];
	}
Exemple #11
0
      void UnifyTraverser::checkPrimitive( multimap<HashKey,PrimitiveSharedPtr> &v, Primitive * p )
      {
        // Unify Primitives of each type
        DP_ASSERT( m_unifyTargets & UT_PRIMITIVE );

        if( !optimizationAllowed( p->getSharedPtr<Primitive>() ) )
        {
          return;
        }

#if CHECK_HASH_RESULTS
        PrimitiveWeakPtr foundPrimitive = nullptr;
#endif

        // look for all Primitives of the same type already encountered, with the same hash String (should not be too many!)
        bool found = false;
        HashKey hashKey = p->getHashKey();
        typedef multimap<HashKey,PrimitiveSharedPtr>::const_iterator I;
        pair<I,I> itp = v.equal_range( hashKey );
        PrimitiveSharedPtr primitive = p->getSharedPtr<Primitive>();
        for ( I it = itp.first ; it != itp.second && !found ; ++it )
        {
          // check if any of those Primitives is equal or equivalent to the currently handled
          found =   ( primitive == it->second )
                ||  p->isEquivalent( it->second, getIgnoreNames(), false );
          if ( found && ( primitive != it->second ) )
          {
            // there is an equivalent Primitive, that's not the same as the currently handled -> store as replacement
            m_replacementPrimitive = it->second;
          }
#if CHECK_HASH_RESULTS
          if ( found )
          {
            foundPrimitive = it->second.getWeakPtr();
          }
#endif
        }

#if CHECK_HASH_RESULTS
        // just to make sure, that we find the same equivalent Primitive with exhaustive search (no hash string usage)
        bool checkFound = false;
        for ( I it = mm.begin() ; it != mm.end() && !checkFound ; ++it )
        {
          checkFound = ( primitive == it->second )
                    || pT->isEquivalent( SharedHandle<T>::Lock(it->second), getIgnoreNames(), false );
          DP_ASSERT( !checkFound || ( primitive == it->second ) || ( foundPrimitive == it->second.getWeakPtr() ) );
        }
        DP_ASSERT( found == checkFound );
#endif

        // if we did not found that Primitive (or an equivalent one) before -> store it for later searches
        if ( ! found )
        {
          v.insert( make_pair( hashKey, primitive ) );
        }
      }
Exemple #12
0
/// find operator with specific string and arity
decltype(opers)::iterator find_oper(const string &str, bool unary)
{
	auto range = opers.equal_range(str);
	auto oit = range.first;
	for (; oit != range.second; ++oit)
	{
		if (oit->second.unary == unary)
			break;
	}
	return oit == range.second ? opers.end() : oit;
}
Exemple #13
0
 vector<int> query(FloatRect rect) {
     vector<int> ret;
     auto qry = get_quad_ids(rect);
     for(auto&a:qry){
         auto multimap_qry = flat_tree.equal_range(a);
         for(auto it = multimap_qry.first; it != multimap_qry.second; ++it){
             ret.push_back(it->second);
         }
     }
     return ret;
 }
bool getOptValues(vector<string>& values, multimap<string,string>& optmap,const string& key){
	values.clear();
	pair<multimap<string,string>::iterator,multimap<string,string>::iterator> findI=optmap.equal_range(key);
	if(findI.first==optmap.end())
		return false;
	
	for(multimap<string,string>::iterator i=findI.first;i!=findI.second;i++)
		values.push_back(i->second);
	
	return true;
}
Exemple #15
0
void printmultimap2(multimap <string, string> &authors)
{
	typedef multimap<string,string>::iterator authors_it;
	pair< authors_it, authors_it > val_type = authors.equal_range("Barth, John");
	//multimap<string,string>::iterator val_type = authors.equal_range("Barth, John");
	while (val_type.first != val_type.second)
	{
		cout << val_type.first->first << "----->" << val_type.first->second << endl;
		++val_type.first;
	}
}
Exemple #16
0
void deleteAuthor(multimap<string, string> &db, string author)
{
    pair<db_iter, db_iter> range = db.equal_range(author);

    if (range.first != range.second) {
        cout << "author: " << author << " found and del" << endl;
    } else {
        cout << "author: " << author << " not found" << endl;
    }

    db.erase(range.first, range.second);
}
Exemple #17
0
void eraseName(multimap<string, string>& m_map)
{
	string authorname;
	cout << "Which author do you want to delete ?" << endl;
	cin >> authorname;
	pair<multimap<string, string>::iterator, multimap<string, string>::iterator> it = m_map.equal_range(authorname);
	if (it.first != it.second){
		m_map.erase(it.first, it.second);
	}
	else
		cout << "Can't find the author !" << endl;
}
 void dfs (string word, int level, multimap<string, string> &from) {
     if (level == 1) {
         result.push_back(trace);
         return;
     }
     auto ret = from.equal_range(word);
     for (auto it = ret.first; it != ret.second; ++it) {
         trace.push_back(it->second);
         dfs (it->second, level - 1, from);
         trace.pop_back();
     }
 }
Exemple #19
0
int main()
{
    int n,flag = 0;
    cin >> n;
    
    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        points.push_back(make_pair(x,y));
    }
    
    for(int i=0;i<points.size();i++){
        for(int j=i+1;j<points.size();j++){
            
            Line line1; line1.a = points[i]; line1.b = points[j];
            
            double slope = findSlope(points[i],points[j]);
            
            //cout << i << " " << j << ": " << slope << endl;
            
            double origSlope = slope;
            
            
            if(slope == 1000002) slope = 0;
            else if(slope == 0) slope = 1000002;
            else slope = -1/slope;
            
            auto iterPair= slopes.equal_range(slope);
            
            auto iter = iterPair.first;
            for(;iter!=iterPair.second;iter++){
                if(iter != slopes.end()){
                    Line line2 = iter->second;
                    if(checkSquare(line1,line2)){
                        cout << 0 << endl;
                        return 0;
                    }
                    if(line1.a == line2.a || line1.a==line2.b 
                       || line1.b == line2.a || line1.b == line2.b){
                        flag = 1;   
                    }
                }
            }
            slopes.insert(make_pair(origSlope,line1));
        }
    }
    
    if(flag) cout << 1 << endl;
    else cout << 2 << endl;
        
    return 0;
}
void display()
{
	 std::cout << "mymm contains:\n";
  for (char ch='a'; ch<='z'; ch++)
  {
    pair <multimap<char,int>::iterator,multimap<char,int>::iterator> ret;
    ret = mymm.equal_range(ch);
    cout << ch << " =>";
    for (it=ret.first; it!=ret.second; ++it)
      cout << ' ' << it->second;
      cout << '\n';
  }
}
void printByKey(multimap<string,string> &mm, string &key)
{
	cout <<"<<---------------------"<<endl;
    
    auto p = mm.equal_range(key);
    
    for(auto it=p.first;it!=p.second;++it)
    {
    	cout <<it->second<<endl;	
    }
    
    cout <<"--------------------->>"<<endl;	
}
Exemple #22
0
void DyckGraph::removeFromWorkList(multimap<DyckVertex*, void*>& list, DyckVertex* v, void* l) {
    typedef multimap<DyckVertex*, void*>::iterator CIT;
    typedef pair<CIT, CIT> Range;
    Range range = list.equal_range(v);
    CIT next = range.first;
    while (next != range.second) {
        if ((next)->second == l) {
            list.erase(next);
            return;
        }
        next++;
    }
}
Exemple #23
0
bool DyckGraph::containsInWorkList(multimap<DyckVertex*, void*>& list, DyckVertex* v, void* l) {
    typedef multimap<DyckVertex*, void*>::iterator CIT;
    typedef pair<CIT, CIT> Range;
    Range range = list.equal_range(v);
    CIT next = range.first;
    while (next != range.second) {
        if ((next)->second == l) {
            return true;
        }
        next++;
    }
    return false;
}
void combination(string &tmp, int cur, string &digits)
{
    if (cur == digits.size()) {
        string elem = tmp;
        result.push_back(elem);
        //cout << elem << endl;
        return;
    }
    auto ret = PhoneMap.equal_range(digits[cur]);
    for (auto iter = ret.first; iter != ret.second; iter++) {
        tmp.push_back(iter->second);
        combination(tmp, cur + 1, digits);
        tmp.pop_back();
    }
}
Exemple #25
0
// Returns the Codon with lowest frequency for that amino acid
float CodonFrequency::findMin(multimap<char, pair<int, float> > AAtoCodonMap, char AA) {

	float min = 100;
	
	pair< multimap<char, pair<int, float> >::iterator, multimap<char, pair<int, float> >::iterator> ret;
	
	ret = AAtoCodonMap.equal_range(AA);

	for (multimap<char, pair<int, float> >::iterator it = ret.first; it != ret.second; ++it) {

		if (min > it->second.second)
			min = it->second.second;
	}
	return min;
}
	void build_path(multimap<string,string> father,string start,string end,vector<string> &CurrPath,vector<vector<string>> &Path){
		CurrPath.push_back(end);
		if(start==end){
			Path.push_back(CurrPath);
			reverse(Path.back().begin(),Path.back().end());
			CurrPath.pop_back();
			return;
		}
		pair<multimap<string,string>::iterator,multimap<string,string>::iterator> pos=father.equal_range(end);
		while(pos.first!=pos.second){
			build_path(father,start,pos.first->second,CurrPath,Path);
			pos.first++;
		}
		CurrPath.pop_back();
    }
Exemple #27
0
// Maps average frequency of codons to each amino acid
vector<float> CodonFrequency::createAvgMap(multimap<char, pair<int, float> > AAtoCodonMap) {
	
//	cout << "------avgFreq------" << endl;
	
	int addressAA;
	int codonPerAA;	// Numbers of codons that code for an amino acid
	float sumFreq;	// Sum of codon frequencies for an amino acid
	float avgFreq;	// sumFreq/codonPerAA to calculate average frequency for an amino acid
	vector<float> avgMap;
	
	for (char AA = 'A'; AA <= 'Z'; AA++) {

		addressAA = AA-65;
		codonPerAA = 0;
		sumFreq = 0;
		avgFreq = 0;

		if (AA == 'B' || AA == 'J' || AA == 'O' || AA == 'U' || AA == 'X') { 
			avgMap.push_back(-1);
//			continue;
		}

		else if (AAtoCodonMap.count(AA) > 1) {
		
			pair< multimap<char, pair<int, float> >::iterator, 
			multimap<char, pair<int, float> >::iterator> ret;
	
			ret = AAtoCodonMap.equal_range(AA);
			
			for (multimap<char, pair<int, float> >::iterator it = ret.first; it != ret.second; ++it) {
//				cout << AA << " " << it->second.second << endl;
				sumFreq += it->second.second;
				codonPerAA++;
			}

			avgFreq = sumFreq/codonPerAA;
//			cout << sumFreq << " / " << codonPerAA << " = " << avgFreq << endl;
			avgMap.push_back(avgFreq);
//			continue;
			
		} else if (AAtoCodonMap.count(AA) == 1) {
			avgMap.push_back(AAtoCodonMap.find(AA)->second.second);
//			continue;
		}
//		cout << addressAA << " " << AA << " " << avgMap[addressAA] << endl;
	}
	return avgMap;
}
Exemple #28
0
/// evaluate postfix expression
num_t evalpostfix(postfix_t in)
{
	stack<num_t> s;
	for (token_t &tok : in)
	{
		if (tok.second == -1) // number
			s.push(stod(tok.first));
		else
		{
			if (s.size() < tok.second)
				throw runtime_error("Not enough arguments (have " + to_string(s.size()) + ") for function '" + tok.first + "' (want " + to_string(tok.second) + ")");
			else
			{
				args_t v;
				for (int i = 0; i < tok.second; i++)
					v.insert(v.begin(), pop(s)); // pop elements for function arguments in reverse order

				auto range = funcs.equal_range(tok.first);
				return_t ret(false, 0);
				for (auto it = range.first; it != range.second; ++it)
				{
					ret = it->second(v);
					if (ret.first) // find a function that can evaluate given parameters
						break;
				}

				if (ret.first)
					s.push(ret.second);
				else
				{
					ostringstream args; // stringstream because to_string adds trailing zeroes
					for (auto vit = v.begin(); vit != v.end(); ++vit) // construct exception argument list
					{
						args << *vit;
						if ((vit + 1) != v.end())
							args << ", ";
					}
					throw runtime_error("Unacceptable arguments (" + args.str() + ") for function '" + tok.first + "'");
				}
			}
		}
	}

	if (s.size() == 1)
		return s.top();
	else
		throw runtime_error("No single result found");
}
Exemple #29
0
void search_and_print(multimap<string,string> &mm , string s) 
{
	auto pos = mm.equal_range(s);
	if(pos.first == pos.second)
		cout << "cann't find author " << s <<endl; 
	else
	{
		while(pos.first != pos.second)
		{
			cout << "author : " << pos.first -> first << "\t";
			cout << "production : " << pos.first -> second << endl;
			pos.first ++ ;
		}
	}

}
Exemple #30
0
	void removeWeight(const K& key)
	{
		auto weightIter =  keyWeightMap_.find(key);
		auto const weight = weightIter->second;
		keyWeightMap_.erase(weightIter);

		auto ret = weightKeyMap_.equal_range(weight);
		for (auto iter=ret.first; iter!=ret.second; ++iter)
			if (iter->second == key)
			{
				weightKeyMap_.erase(iter);
				return;
			}

		assert(false);
	}