예제 #1
0
std::vector<std::multimap<ReducedFraction, MidiChord>::const_iterator>
findChordsForTimeRange(
            int voice,
            const ReducedFraction &onTime,
            const ReducedFraction &offTime,
            const std::multimap<ReducedFraction, MidiChord> &chords,
            const ReducedFraction &maxChordLength)
      {
      std::vector<std::multimap<ReducedFraction, MidiChord>::const_iterator> result;

      if (chords.empty())
            return result;

      auto it = chords.lower_bound(offTime);
      if (it == chords.begin())
            return result;
      --it;

      while (it->first + maxChordLength > onTime) {
            const MidiChord &chord = it->second;
            if (chord.voice == voice) {
                  const auto chordInterval = std::make_pair(it->first, maxNoteOffTime(chord.notes));
                  const auto durationInterval = std::make_pair(onTime, offTime);

                  if (MidiTuplet::haveIntersection(chordInterval, durationInterval))
                        result.push_back(it);
                  }
            if (it == chords.begin())
                  break;
            --it;
            }

      return result;
      }
예제 #2
0
int get_shortest_stamp(std::multimap<addr_type, int> & ongoing_requests) {
    int t;

    std::multimap<addr_type, int>::iterator it;
    for (it = ongoing_requests.begin(); it != ongoing_requests.end(); it++) {
        if (it == ongoing_requests.begin())
            t = it->second;
        if (it->second < t)
            t = it->second;
    }

    return t;
}
예제 #3
0
void ImageView::setFeatures(const std::multimap<int, cv::KeyPoint> & refWords, const QColor & color)
{
	qDeleteAll(_features);
	_features.clear();

	rtabmap::KeypointItem * item = 0;
	for(std::multimap<int, cv::KeyPoint>::const_iterator i = refWords.begin(); i != refWords.end(); ++i )
	{
		const cv::KeyPoint & r = (*i).second;
		int id = (*i).first;
		QString info = QString( "WordRef = %1\n"
								"Laplacian = %2\n"
								"Dir = %3\n"
								"Hessian = %4\n"
								"X = %5\n"
								"Y = %6\n"
								"Size = %7").arg(id).arg(1).arg(r.angle).arg(r.response).arg(r.pt.x).arg(r.pt.y).arg(r.size);
		float radius = r.size/2.0f;
		item = new rtabmap::KeypointItem(r.pt.x-radius, r.pt.y-radius, radius*2, info, color);

		scene()->addItem(item);
		_features.insert(id, item);
		item->setVisible(_showFeatures->isChecked());
		item->setZValue(1);
	}
}
예제 #4
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);
      }

  }
예제 #5
0
std::multimap<float, std::vector<int> > HuffmanCoder::Merge(std::multimap<float, std::vector<int> >& mapOne, std::multimap<float, std::vector<int> >& mapTwo) {
    std::multimap<float, std::vector<int> > newMap(mapOne);
    for (std::multimap<float, std::vector<int> >::iterator it = mapTwo.begin(); it != mapTwo.end(); it++) {
        newMap.insert(*it);
    }
    return newMap;
}
예제 #6
0
파일: World.cpp 프로젝트: mstram/dfhack-40d
void World::GetPersistentData(std::vector<PersistentDataItem> *vec, const std::string &key, bool prefix)
{
    vec->clear();

    if (!BuildPersistentCache())
        return;

    auto eqrange = persistent_index.equal_range(key);

    if (prefix)
    {
        if (key.empty())
        {
            eqrange.first = persistent_index.begin();
            eqrange.second = persistent_index.end();
        }
        else
        {
            std::string bound = key;
            if (bound[bound.size()-1] != '/')
                bound += "/";
            eqrange.first = persistent_index.lower_bound(bound);

            bound[bound.size()-1]++;
            eqrange.second = persistent_index.lower_bound(bound);
        }
    }

    for (auto it = eqrange.first; it != eqrange.second; ++it)
    {
        auto hfig = df::historical_figure::find(-it->second);
        if (hfig && hfig->name.has_name)
            vec->push_back(dataFromHFig(hfig));
    }
}
예제 #7
0
netCDF::NcVar NetCDFFile::getVariable(const std::string &variableName) const
{
    if( variableName.empty() == true )
    {
        /// returns a null object
        return netCDF::NcVar();
    }
    
    const std::multimap< std::string, netCDF::NcVar > vars = file.getVars();
    
    for( std::multimap< std::string, netCDF::NcVar >::const_iterator it = vars.begin();
        it != vars.end();
        ++it )
    {
        const std::string varName       = (*it).first;
        
        if( varName == variableName )
        {
            const netCDF::NcVar var         = (*it).second;
            return var;
        }
    }
    
    /// returns a null object
    return netCDF::NcVar();
}
예제 #8
0
 ~mapper()
 {
   for( auto c = callbacks.begin(); c != callbacks.end(); ++c )
   {
     delete c->second;
   }
 }
예제 #9
0
    virtual void Run()
    {
        now = v8::base::OS::TimeCurrentMillis();

        while (1)
        {
            AsyncEvent *p;
            std::multimap<double, AsyncEvent *>::iterator e;

            wait();

            now = v8::base::OS::TimeCurrentMillis();

            while (1)
            {
                p = s_acSleep.get();
                if (p == NULL)
                    break;

                s_tms.insert(std::make_pair(now + p->result(), p));
            }

            while (1)
            {
                e = s_tms.begin();
                if (e == s_tms.end())
                    break;
                if (e->first > now)
                    break;

                e->second->apost(0);
                s_tms.erase(e);
            }
        }
    }
예제 #10
0
      void dispatch_callbacks() const
      {
        mappedinput input = current_mappedinput;

        for( auto it = callbacks.begin(); it != callbacks.end(); ++it )
          ( *it->second )( input );
      }
예제 #11
0
bool ltr_int_broadcast_pose(linuxtrack_full_pose_t &pose)
{
    pthread_mutex_lock(&send_mx);
    std::multimap<std::string, int>::iterator i;
    int res;
    bool checkSlaves = false;
    //Send updated pose to all clients
    //printf("Master: %g  %g  %g\n", pose.pose.raw_pitch, pose.pose.raw_yaw, pose.pose.raw_roll);
    for(i = slaves.begin(); i != slaves.end();) {
        res = ltr_int_send_data(i->second, &pose);
        if(res == -EPIPE) {
            ltr_int_log_message("Slave @socket %d left!\n", i->second);
            close(i->second);
            i->second = -1;
            slaves.erase(i++);
            checkSlaves = true;
        } else {
            ++i;
        }
    }
    if(checkSlaves && (slaves.size() == 0)) {
        no_slaves = true;
    }
    pthread_mutex_unlock(&send_mx);
    return true;
}
예제 #12
0
 bool DumbRelayConsumer::check_authentication(const std::multimap<std::string, std::string> &params) {
     // Construct the data for the post.
     std::ostringstream data;
     CURL *curl = new_curl_handle();
     data << "openid.mode=check_authentication";
     for(std::multimap<std::string, std::string>::const_iterator iter = params.begin();
         iter != params.end();
         ++iter) {
         if(iter->first.compare("openid.mode") == 0) continue;
         
         char *tmp;
         tmp = curl_easy_escape(curl, iter->first.c_str(), iter->first.size());
         data << "&" << tmp << "=";
         curl_free(tmp);
         
         tmp = curl_easy_escape(curl, iter->second.c_str(), iter->second.size());
         data << tmp;
         curl_free(tmp);
     }
     // Clean up after curl.
     curl_easy_cleanup(curl);
     
     // Prepare the curl handle.
     std::string content = contact_openid_provider(data.str());
     
     // Check to see if we can find the is_valid:true response.
     return content.find("\nis_valid:true\n") != content.npos;
 }
예제 #13
0
 void flush_immediate_sync() {
   auto seq_no = processor_.max_finished_seq_no();
   for (auto it = immediate_sync_promises_.begin(), end = immediate_sync_promises_.end();
        it != end && it->first <= seq_no; it = immediate_sync_promises_.erase(it)) {
     do_immediate_sync(std::move(it->second));
   }
 }
예제 #14
0
void NetCDFFile::PrintAllVariables(std::ostream & output) const
{
    /// retrieves all the variables
    const std::multimap< std::string, netCDF::NcVar > vars = file.getVars();
    
    for( std::multimap< std::string, netCDF::NcVar >::const_iterator it = vars.begin();
        it != vars.end();
        ++it )
    {
        const std::string varName       = (*it).first;
        
        std::vector< std::size_t > dimensions;
        GetVariableDimensions( dimensions, varName ),
        
        output << varName << " = " << "(";
        
        for( std::size_t k = 0; k < dimensions.size(); k++ )
        {
            output << dimensions[k];
            
            if( k < dimensions.size() - 1 )
            {
                output << ",";
            }
        }
        output << ")" << std::endl;
        
    }
    
}
예제 #15
0
 void deactivateAll()
 {
     for (iter_t i = ev.begin(); i != ev.end(); ++i)
     {
         i->second->activate_cmd(0);
     }
 }
예제 #16
0
void GroupTransformer::putData(RddPartition* output,
    std::multimap<PbMessagePtr, PbMessagePtr, idgs::store::less>& localCache) {
  if (!localCache.empty()) {
    PbMessagePtr key;
    std::vector<PbMessagePtr> values;
    for (auto it = localCache.begin(); it != localCache.end(); ++it) {
      if (idgs::store::equals_to()(const_cast<PbMessagePtr&>(it->first), key)) {
        values.push_back(it->second);
      } else {
        if (!values.empty()) {
          output->put(key, values);
          values.clear();
        }
        values.clear();
        key = it->first;
        values.push_back(it->second);
      }
    }
    if (!values.empty()) {
      output->put(key, values);
      values.clear();
    }

    localCache.clear();
  }
}
예제 #17
0
파일: fbFiber.cpp 프로젝트: cwyiu/fibjs
    static void PASCAL Timer(unsigned int uTimerID, unsigned int uMsg,
                             DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
    {
        AsyncEvent *p;
        double tm;
        std::multimap<double, AsyncEvent *>::iterator e;

        while (1)
        {
            p = s_acSleep.get();
            if (p == NULL)
                break;

            tm = s_time + s_now + p->result();
            s_tms.insert(std::make_pair(tm, p));
        }

        atom_xchg(&s_now, (int)(v8::internal::OS::TimeCurrentMillis() - s_time));

        while (1)
        {
            e = s_tms.begin();
            if (e == s_tms.end())
                break;
            if (e->first > s_time + s_now)
                break;

            e->second->apost(0);
            s_tms.erase(e);
        }
    }
예제 #18
0
netCDF::NcGroupAtt NetCDFFile::getAttribute(const std::string &attributeName) const
{    
    if( attributeName.empty() == true )
    {
        /// returns a null object
        return netCDF::NcGroupAtt();
    }
    
    const std::multimap< std::string, netCDF::NcGroupAtt > attributes = file.getAtts();
    
    for( std::multimap< std::string, netCDF::NcGroupAtt >::const_iterator it = attributes.begin();
        it != attributes.end();
        ++it )
    {
        const std::string attrName      = (*it).first;
        
        if( attrName == attributeName )
        {
            const netCDF::NcGroupAtt att    = (*it).second;
            
            return att;
        }
    }
    
    return netCDF::NcGroupAtt();
}
예제 #19
0
void setBarIndexes(
            std::multimap<ReducedFraction, MidiChord> &chords,
            const ReducedFraction &basicQuant,
            const ReducedFraction &lastTick,
            const TimeSigMap *sigmap)
      {
      if (chords.empty())
            return;
      auto it = chords.begin();
      for (int barIndex = 0;; ++barIndex) {       // iterate over all measures by indexes
            const auto endBarTick = ReducedFraction::fromTicks(sigmap->bar2tick(barIndex + 1, 0));
            if (endBarTick <= it->first)
                  continue;
            for (; it != chords.end(); ++it) {
                  const auto onTime = Quantize::findQuantizedChordOnTime(*it, basicQuant);
#ifdef QT_DEBUG
                  const auto barStart = ReducedFraction::fromTicks(sigmap->bar2tick(barIndex, 0));
                  Q_ASSERT_X(!(it->first >= barStart && onTime < barStart),
                             "MChord::setBarIndexes", "quantized on time cannot be in previous bar");
#endif
                  if (onTime < endBarTick) {
                        it->second.barIndex = barIndex;
                        continue;
                        }
                  break;
                  }
            if (it == chords.end() || endBarTick > lastTick)
                  break;
            }

      Q_ASSERT_X(areBarIndexesSet(chords),
                 "MChord::setBarIndexes", "Not all bar indexes were set");
      Q_ASSERT_X(areBarIndexesSuccessive(chords),
                 "MChord::setBarIndexes", "Bar indexes are not successive");
      }
예제 #20
0
netCDF::NcDim NetCDFFile::getDimension(const std::string &dimensionName) const
{
    if( dimensionName.empty() == true )
    {
        /// returns a null object
        return netCDF::NcDim();
    }
    
    const std::multimap< std::string, netCDF::NcDim > dims = file.getDims();
    
    for( std::multimap< std::string, netCDF::NcDim >::const_iterator it = dims.begin();
        it != dims.end();
        ++it )
    {
        const std::string dimName = (*it).first;
        
        if( dimName == dimensionName )
        {
            const netCDF::NcDim dim   = (*it).second;
            return dim;
        }
        
    }
    
    /// returns a null object
    return netCDF::NcDim();
}
예제 #21
0
파일: sbcs.cpp 프로젝트: Pat61/hyperserv
	void deinitCs()
	{
		for(std::multimap<std::string, char *>::iterator it = event_dict.begin();it != event_dict.end();++it)
		{
			free(it->second);
		}
	}
예제 #22
0
파일: sniffex.c 프로젝트: achanda/fCache
std::set<u_int> get_keys(std::multimap<u_int,record> map) {
	std::set<u_int> temp;
	std::multimap<u_int,record>::iterator it;
	for(it = map.begin(); it != map.end(); ++it)
		temp.insert(it->first);
	return temp;
}
예제 #23
0
ColouredGraph::ColouredGraph(const std::multimap<const Object*, const Object*>& symmetrical_objects)
{
	std::set<const Object*> processed_objects;
	
	for (std::multimap<const Object*, const Object*>::const_iterator ci =  symmetrical_objects.begin(); ci != symmetrical_objects.end(); ++ci)
	{
		const Object* lhs_object = (*ci).first;
		
		if (processed_objects.count(lhs_object) != 0)
		{
			continue;
		}
		processed_objects.insert(lhs_object);
		
		ColouredGraphNodeObjects* cgno = new ColouredGraphNodeObjects();
		all_object_edges_.push_back(cgno);
		
		std::pair<std::multimap<const Object*, const Object*>::const_iterator, std::multimap<const Object*, const Object*>::const_iterator> m_ci = symmetrical_objects.equal_range(lhs_object);
		for (std::multimap<const Object*, const Object*>::const_iterator ci = m_ci.first; ci != m_ci.second; ++ci)
		{
			cgno->addObject(*(*ci).second);
			mapped_objects_.insert(std::make_pair((*ci).second, cgno));
		}
	}
}
예제 #24
0
/**
    \brief This function calculates the number of duplicates based from the filenames and their sizes.
    \param files The file structure consisting of a map of file size and file name.
    \return An unsigned int equal to the number of duplicates found.
**/
unsigned int DuplicateFinder::DuplicateComparison( const std::multimap<unsigned int, std::wstring> & files )
{
    unsigned int numDupes = 0;
    //check to see if a file's size has other matching files' sizes
    auto mit = files.begin(); //mit is an iterator through the file list
    while( mit != files.end() ) //while searching through the list
    {
        //checking the file immediately after the currently iterated file
        if( ( std::next( mit ) != files.end() ) )
        {
            if( ( std::next( mit ) )->first == mit->first ) // if filesize is same as next's:
            {
                //open the iterated entry
                boost::filesystem::ifstream original( mit->second, std::ios::binary );
                if( original.is_open() ) //if we opened it...
                {
                    //open the next file to compare
                    boost::filesystem::ifstream checking( ( std::next( mit ) )->second,
                                                            std::ios::binary );
                    if( checking.is_open() ) //if successfully opened,
                    {
                        char originalByte; //for original's same byte
                        char nextByte; //for next's same byte
                        //start by reading check's first byte
                        checking.read( &nextByte, sizeof( char ) );
                        //start by reading original's first byte
                        original.read( &originalByte, sizeof( char ) );

                        //while we're not at the end of the files
                        while( !checking.eof() || !original.eof() )
                        {
                            //check to make sure the bytes are not different
                            if( nextByte != originalByte )
                            {
                                break; //move on to the next file
                            }

                            //read in the next bytes
                            checking.read( &nextByte, sizeof( char ) );
                            original.read( &originalByte, sizeof( char ) );
                        }
                        //if we were at the end of both files, we report a duplicate into the
                        //duplicate list and add an extra entry to "numberOfDuplicates"
                        if( checking.eof() && original.eof() )
                        {
                            duplicates.push_back( next( mit )->second +
                                                  std::wstring( L" is a duplicate of ") +
                                                  mit->second);
                            ++numDupes;
                        }
                    }
                }
            }
        }
        ++mit;
    }

    return numDupes;
}
예제 #25
0
 ~Loop()
 {
     //TODO: send these events to a recycling queue, don't erase them
     for (iter_t i = ev.begin(); i != ev.end(); ++i)
     {
         delete i->second;
     }
 }
예제 #26
0
/*
* Insert a mapping of key/value pairs
*/
void Data_Store::add(const std::multimap<std::string, std::string>& in)
   {
   std::multimap<std::string, std::string>::const_iterator i = in.begin();
   while(i != in.end())
      {
      m_contents.insert(*i);
      ++i;
      }
   }
예제 #27
0
 void Semantic::displaySymbol(){
 	cout<<"\n";
 	for ( mi = Symbols.begin() ; mi != Symbols.end(); mi++ )
    {   
        cout<<mi->first<<":";
        cout<<mi->second.type<<":";
        cout<<mi->second.scope<<":";   
        cout<<"\n";
    }
 }
예제 #28
0
int MinCost(const std::multimap<unsigned, unsigned> &data, const unsigned &targetMilk)
{
	unsigned accumSum = 0, accumMilk = 0;

	for(auto it = data.begin(); accumMilk < targetMilk && it != data.end(); ++it)
		for(unsigned k = 1; k <= it->second && accumMilk < targetMilk; ++k, ++accumMilk)
			accumSum += it->first;

	return accumSum;
}
예제 #29
0
    void print(std::multimap<int, int> &m) {
        std::multimap<int, int>::iterator iter;

        printf("   multimap [ ");
        for (iter = m.begin(); iter != m.end(); iter++) {
            printf("%d ", iter->first);
        }
        printf("]\n");
        fflush(stdout);
    }
예제 #30
0
    void wait()
    {
        std::multimap<double, AsyncEvent *>::iterator e;

        e = s_tms.begin();
        if (e != s_tms.end())
            m_sem.TimedWait((int32_t)(e->first - now));
        else
            m_sem.Wait();
    }