Example #1
0
static inline int64_t next_jobid (const std::map<uint64_t, job_info_t *> &m)
{
    int64_t jobid = -1;
    if (m.empty ())
        jobid = 0;
    else if (m.rbegin ()->first < INT64_MAX)
        jobid = m.rbegin ()->first + 1;
    return jobid;
}
Example #2
0
void printMap(const std::map<T, T>& m, std::ostream& s = std::cout)
{
    for (typename std::map<T, T>::const_reverse_iterator it = m.rbegin(); it != m.rend(); ++it)
    {
        if (it != m.rbegin())
            s << " ";
        s << it->first << " " << it->second;
    }
    s << "\n";
}
void LanguageLatex<Base>::printStaticIndexMatrix(std::ostringstream& os,
                                                 const std::string& name,
                                                 const std::map<size_t, std::map<size_t, size_t> >& values) {
    size_t m = 0;
    size_t n = 0;

    std::map<size_t, std::map<size_t, size_t> >::const_iterator it;
    std::map<size_t, size_t>::const_iterator ity2z;

    if (!values.empty()) {
        m = values.rbegin()->first + 1;

        for (it = values.begin(); it != values.end(); ++it) {
            if (!it->second.empty())
                n = std::max(n, it->second.rbegin()->first + 1);
        }
    }

    os << name << " = \\left\\{";
    size_t x = 0;
    for (it = values.begin(); it != values.end(); ++it) {
        if (it->first != x) {
            while (it->first != x) {
                os << "{},";
                x++;
            }
        }

        os << "{";

        size_t y = 0;
        for (ity2z = it->second.begin(); ity2z != it->second.end(); ++ity2z) {
            if (ity2z->first != y) {
                while (ity2z->first != y) {
                    os << "0,";
                    y++;
                }
            }

            os << ity2z->second;
            if (ity2z->first != it->second.rbegin()->first) os << ",";

            y++;
        }

        os << "}";
        if (it->first != values.rbegin()->first) os << ",";

        x++;
    }
    os << "\\right\\}" << _endEq << "% size: " << m << " x " << n << _endline;
}
void LanguageC<Base>::printStaticIndexMatrix(std::ostringstream& os,
                                             const std::string& name,
                                             const std::map<size_t, std::map<size_t, size_t> >& values) {
    size_t m = 0;
    size_t n = 0;

    std::map<size_t, std::map<size_t, size_t> >::const_iterator it;
    std::map<size_t, size_t>::const_iterator ity2z;

    if (!values.empty()) {
        m = values.rbegin()->first + 1;

        for (it = values.begin(); it != values.end(); ++it) {
            if (!it->second.empty())
                n = std::max(n, it->second.rbegin()->first + 1);
        }
    }

    os << "static " << U_INDEX_TYPE << " const " << name << "[" << m << "][" << n << "] = {";
    size_t x = 0;
    for (it = values.begin(); it != values.end(); ++it) {
        if (it->first != x) {
            while (it->first != x) {
                os << "{},";
                x++;
            }
        }

        os << "{";

        size_t y = 0;
        for (ity2z = it->second.begin(); ity2z != it->second.end(); ++ity2z) {
            if (ity2z->first != y) {
                while (ity2z->first != y) {
                    os << "0,";
                    y++;
                }
            }

            os << ity2z->second;
            if (ity2z->first != it->second.rbegin()->first) os << ",";

            y++;
        }

        os << "}";
        if (it->first != values.rbegin()->first) os << ",";

        x++;
    }
    os << "};\n";
}
Example #5
0
void GL45Backend::derezTextures() const {
    if (GLTexture::getMemoryPressure() < 1.0f) {
        return;
    }

    Lock lock(texturesByMipCountsMutex);
    if (texturesByMipCounts.empty()) {
        // No available textures to derez
        return;
    }

    auto mipLevel = texturesByMipCounts.rbegin()->first;
    if (mipLevel <= 1) {
        // No mips available to remove
        return;
    }

    GL45Texture* targetTexture = nullptr;
    {
        auto& textures = texturesByMipCounts[mipLevel];
        assert(!textures.empty());
        targetTexture = *textures.begin();
    }
    lock.unlock();
    targetTexture->derez();
}
Example #6
0
/**
 * Get the computed average speed
 * @param thr_id int (-1 for all threads)
 */
double stats_get_speed(int thr_id, double def_speed)
{
	uint64_t gpu = thr_id;//device_map[thr_id];

	const uint64_t keymsk = 0xffULL; // last u8 is the gpu
	double speed = 0.0;
	int records = 0;

	std::map<uint64_t, stats_data>::reverse_iterator i = tlastscans.rbegin();
	while (i != tlastscans.rend() && records < opt_statsavg) 
	{
		if (!i->second.ignored)
		if (thr_id == -1 || (keymsk & i->first) == gpu) {
			if (i->second.hashcount > 1000) {
				speed += i->second.hashrate;
				records++;
				// applog(LOG_BLUE, "%d %x %.1f", thr_id, i->second.thr_id, i->second.hashrate);
			}
		}
		++i;
	}

	if (records)
		speed /= (double)(records);
	else
		speed = def_speed;

	if (thr_id == -1)
		speed *= (double)(opt_n_threads);

	return speed;
}
uint32_t FileWriterI::close() {
    if (baseOutfile == NULL) {
		WARNING << "ops::msole::FileWriterI::close() : file already closed";
		return RET_ERR;
    }

    // close all opened files.
    vector <GsfOutput*> :: iterator iter;
    for ( uint32_t i = 0 ; i < openFileHandler.size() ; i++) {
        GsfOutput * output = openFileHandler[i];
        if (output != NULL) {
            gsf_output_close (GSF_OUTPUT (output));
            g_object_unref (G_OBJECT (output));
        }
    }
    openFileHandler.clear();

    // close all opened directories.
    map <std::string, GsfOutput*> :: reverse_iterator rIter;
    for ( rIter = openDirList.rbegin( ) ; rIter != openDirList.rend( ) ; rIter++) {
        GsfOutput * output = openDirList[rIter->first];
        gsf_output_close (GSF_OUTPUT (output));
        g_object_unref (G_OBJECT (output));
    }
    openDirList.clear();

    baseOutfile = NULL;

	DEBUG << "ops::msole::FileWriterI::close() : file closed";

    return RET_OK;
}
Example #8
0
void OKSocialPluginAndroid::getMyProfile(int preferedPictureSize, void *userData, const std::vector<std::string> &additionalFields)
{
    if (!isLoggedIn())
    {
        if (_delegate)
            _delegate->onGetMyProfile({SocialPluginDelegate::Error::Type::NO_LOGIN, 0, ""}, userData, _emptyProfile);
        return;
    }

    std::string fields = "uid,first_name,last_name,email,birthday,gender";
    for (const auto &field : additionalFields)
        fields += "," + field;

    auto picturesMapIterator = _picturesMap.lower_bound(preferedPictureSize);
    const auto &pictureField = (picturesMapIterator == _picturesMap.end()) ? _picturesMap.rbegin()->second : picturesMapIterator->second;
    fields += "," + _pictureIDKey + "," + pictureField;

    cocos2d::JniMethodInfo methodInfo;
    if (cocos2d::JniHelper::getStaticMethodInfo(methodInfo, HELPER_CLASS_NAME, "getMyProfile", "(Ljava/lang/String;JLjava/lang/String;Z)V"))
    {
        jstring jFields = methodInfo.env->NewStringUTF(fields.c_str());
        jstring jPictureField = methodInfo.env->NewStringUTF(pictureField.c_str());
        methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, jFields, (jlong)userData, jPictureField, (jboolean)_debug);
        methodInfo.env->DeleteLocalRef(methodInfo.classID);
//        methodInfo.env->DeleteLocalRef(jFields); // TODO
//        methodInfo.env->DeleteLocalRef(jPictureField); // TODO
    }
}
inline
std::pair<double, double> GetISInterval(double quantile,
                                        const std::map<int, size_t> &is_hist) {
  // First, obtain the sum of the values
  double S = 0;
  for (auto iter : is_hist)
    S += (double) iter.second;

  double lval = S * (1 - quantile) / 2, rval = S * (1 + quantile) / 2;
  double is_min, is_max;

  // Now, find the quantiles
  double cS = 0;
  is_min = is_hist.begin()->first;
  is_max = is_hist.rbegin()->first;
  for (auto iter : is_hist) {
    if (cS <= lval)
      is_min = iter.first;
    else if (cS <= rval)
      is_max = iter.first;
    cS += (double) iter.second;
  }

  return std::make_pair(is_min, is_max);
}
Example #10
0
File: 0061.cpp Project: yuuhik/memo
int solve(const int x,
	  std::map<int, std::vector<int> >& dataset)
{
  int result = 1;

  std::map<int, std::vector<int> >::reverse_iterator it = dataset.rbegin();

  for(; it != dataset.rend(); ++it) {
    bool isIncludeF = false;

    // each vecotr element
    for (int j = 0; j < (*it).second.size(); ++j) {
      //      std::cout << (*it).first << " " << (*it).second[j] << std::endl;
      
      if (((*it).second)[j] == x) {
      	isIncludeF = true;
      	break;
      }
    }
    if (isIncludeF) { break; }
    ++result;
  }

  return result;
}
void inventory_selector::remove_dropping_items( player &u ) const
{
    // We iterate backwards because deletion will invalidate later indices.
    for( auto a = dropping.rbegin(); a != dropping.rend(); ++a ) {
        if( a->first < 0 ) { // weapon or armor, handled separately
            continue;
        }
        const int count = a->second;
        item &tmpit = u.inv.find_item( a->first );
        if( tmpit.count_by_charges() ) {
            long charges = tmpit.charges;
            if( count != -1 && count < charges ) {
                tmpit.charges -= count;
            } else {
                u.inv.remove_item( a->first );
            }
        } else {
            size_t max_count = u.inv.const_stack( a->first ).size();
            if( count != -1 && ( size_t )count < max_count ) {
                max_count = count;
            }
            for( size_t i = 0; i < max_count; i++ ) {
                u.inv.remove_item( a->first );
            }
        }
    }
}
Example #12
0
File: wire.hpp Project: r-lyeh/wire
        string replace_map( const std::map< std::string, std::string > &replacements ) const
        {
            string out;

            for( size_t i = 0; i < this->size(); )
            {
                bool found = false;
                size_t match_length = 0;

                std::map< std::string, std::string >::const_reverse_iterator it;
                for( it = replacements.rbegin(); !found && it != replacements.rend(); ++it )
                {
                    const std::string &target = it->first;
                    const std::string &replacement = it->second;

                    if( match_length != target.size() )
                        match_length = target.size();

                    if( this->size() - i >= target.size() )
                    if( !std::memcmp( &this->at(int(i)), &target.at(0), (int)match_length ) )
                    {
                        i += target.size();

                        out += replacement;

                        found = true;
                    }
                }

                if( !found )
                    out += this->at(int(i++));
            }

           return out;
        }
Example #13
0
std::map<u32,DisassemblyEntry*>::iterator findDisassemblyEntry(std::map<u32,DisassemblyEntry*>& entries, u32 address, bool exact)
{
	if (exact)
		return entries.find(address);

	if (entries.size() == 0)
		return entries.end();

	// find first elem that's >= address
	auto it = entries.lower_bound(address);
	if (it != entries.end())
	{
		// it may be an exact match
		if (isInInterval(it->second->getLineAddress(0),it->second->getTotalSize(),address))
			return it;

		// otherwise it may point to the next
		if (it != entries.begin())
		{
			it--;
			if (isInInterval(it->second->getLineAddress(0),it->second->getTotalSize(),address))
				return it;
		}
	}

	// check last entry manually
	auto rit = entries.rbegin();
	if (isInInterval(rit->second->getLineAddress(0),rit->second->getTotalSize(),address))
	{
		return (++rit).base();
	}

	// no match otherwise
	return entries.end();
}
Example #14
0
cv::Mat MapsManager::generateGridMap(
		const std::map<int, rtabmap::Transform> & poses,
		float & xMin,
		float & yMin,
		float & gridCellSize)
{
	gridCellSize = gridCellSize_;
	cv::Mat map = util3d::create2DMapFromOccupancyLocalMaps(
			poses,
			gridMaps_,
			gridCellSize_,
			xMin, yMin,
			gridSize_,
			gridEroded_);

	// Fill unknown space around the last pose
	if(!map.empty() &&
		laserScanMaxRange_ &&
		laserScanMinAngle_ < laserScanMaxAngle_ &&
		laserScanIncrement_ &&
		poses.size())
	{
		const Transform & pose = poses.rbegin()->second;
		float roll, pitch, yaw;
		pose.getEulerAngles(roll, pitch, yaw);
		cv::Point2i start((pose.x()-xMin)/gridCellSize_ + 0.5f, (pose.y()-yMin)/gridCellSize_ + 0.5f);

		//rotate counterclockwise 180 degrees at the computed step "a" degrees
		cv::Mat rotation = (cv::Mat_<float>(2,2) << cos(laserScanIncrement_), -sin(laserScanIncrement_),
													 sin(laserScanIncrement_), cos(laserScanIncrement_));

		cv::Mat origin(2,1,CV_32F), endFirst(2,1,CV_32F);
		origin.at<float>(0) = pose.x();
		origin.at<float>(1) = pose.y();
		endFirst.at<float>(0) = laserScanMaxRange_;
		endFirst.at<float>(1) = 0;

		yaw += laserScanMinAngle_;
		cv::Mat initRotation = (cv::Mat_<float>(2,2) << cos(yaw), -sin(yaw),
														 sin(yaw), cos(yaw));

		cv::Mat endCurrent = initRotation*endFirst + origin;
		for(float a=laserScanMinAngle_; a<=laserScanMaxAngle_; a+=laserScanIncrement_)
		{
			cv::Point2i end((endCurrent.at<float>(0)-xMin)/gridCellSize_ + 0.5f, (endCurrent.at<float>(1)-yMin)/gridCellSize_ + 0.5f);
			//end must be inside the grid
			end.x = end.x < 0?0:end.x;
			end.x = end.x >= map.cols?map.cols-1:end.x;
			end.y = end.y < 0?0:end.y;
			end.y = end.y >= map.rows?map.rows-1:end.y;
			util3d::rayTrace(start, end, map, true); // trace free space

			// next point
			endCurrent = rotation*(endCurrent - origin) + origin;
		}
	}

	return map;
}
Example #15
0
			static uint64_t addPipeHandler(SignalHandler * handler)
			{
				lock.lock();
				uint64_t const id = sigpipehandlers.size() ?  (sigpipehandlers.rbegin()->first+1) : 0;
				sigpipehandlers[id] = handler;
				lock.unlock();
				return id;
			}
Example #16
0
void find_sector(const std::map<int, double>& m, int s, int& begin, int & end) {
    begin = s;
    while (begin >= m.begin()->first and m.find(begin) == m.end())
        --begin;

    if (begin < m.begin()->first)
        begin = m.begin()->first;
    else
        ++begin;

    end = s + 1;
    while (end <= m.rbegin()->first and m.find(end) == m.end())
        ++end;

    if (end >= m.rbegin()->first)
        end = m.rbegin()->first + 1;
}
Example #17
0
bool RogersGuiApp::removeFromList( MouseEvent event ) {
	if (valueLabels.size())
	{
		valueLabels.erase( valueLabels.rbegin()->first );
		theListControl->update( valueLabels );
		theDropDownControl->update( valueLabels );
	}
    return false;
}
Example #18
0
			static uint64_t addAllHandler(SignalHandler * handler)
			{
				lock.lock();
				uint64_t const pipeid = sigpipehandlers.size() ?  (sigpipehandlers.rbegin()->first+1) : 0;
				uint64_t const hupid = sighuphandlers.size() ?  (sighuphandlers.rbegin()->first+1) : 0;
				uint64_t const termid = sigtermhandlers.size() ?  (sigtermhandlers.rbegin()->first+1) : 0;
				uint64_t const intid = siginthandlers.size() ?  (siginthandlers.rbegin()->first+1) : 0;
				uint64_t const allid = std::max(std::max(pipeid,hupid),std::max(termid,intid));

				siginthandlers[allid] = handler;
				sigtermhandlers[allid] = handler;
				sighuphandlers[allid] = handler;
				sigpipehandlers[allid] = handler;
				
				lock.unlock();
				
				return allid;
			}
static inline void coeffsToDescendingWeights(std::map<unsigned int,unsigned int>& multiSet, unsigned int weights[][2]) {                     
	std::map<unsigned int, unsigned int>::reverse_iterator  rit;
	int i = 0;
	for ( rit=multiSet.rbegin() ; rit != multiSet.rend(); rit++ ) {
		weights[i][0] = (*rit).first;
		weights[i][1] = (*rit).second;
		if(i>0) assert(weights[i-1][0]>weights[i][0]); //For debuging prpous only 
		i++;
	}
}
Example #20
0
 bool thread_pool::get_free_queue(queue_ptr* out_queue) const
 {
     auto finded = std::find_if(queues.rbegin(), queues.rend(), [](const std::pair<queue::priority, queue_ptr>& iterator)
                                  {
                                      return !iterator.second->is_running;
                                  });
     
     bool is_free_queue_exist = (finded != queues.rend());
     if (is_free_queue_exist)
         *out_queue = finded->second;
     
     return  is_free_queue_exist;
 }
Example #21
0
/**
 * Export data for api calls
 */
int hashlog_get_history(struct hashlog_data *data, int max_records)
{
	int records = 0;

	std::map<uint64_t, hashlog_data>::reverse_iterator it = tlastshares.rbegin();
	while (it != tlastshares.rend() && records < max_records) {
		memcpy(&data[records], &(it->second), sizeof(struct hashlog_data));
		data[records].nonce = LO_DWORD(it->first);
		data[records].njobid = (uint32_t) HI_DWORD(it->first);
		records++;
		++it;
	}
	return records;
}
Example #22
0
void LockMythXDisplays(bool lock)
{
    if (lock)
    {
        std::map<Display*, MythXDisplay*>::iterator it;
        for (it = xdisplays.begin(); it != xdisplays.end(); ++it)
            it->second->Lock();
    }
    else
    {
        std::map<Display*, MythXDisplay*>::reverse_iterator it;
        for (it = xdisplays.rbegin(); it != xdisplays.rend(); ++it)
            it->second->Unlock();
    }
}
Example #23
0
u32 MapBlock_HeapLinear(u32 size, u32 operation, u32 permissions) {
    MemoryBlock block;

    block.base_address  = LINEAR_HEAP_VADDR;
    block.size          = size;
    block.operation     = operation;
    block.permissions   = permissions;

    if (heap_linear_map.size() > 0) {
        const MemoryBlock last_block = heap_linear_map.rbegin()->second;
        block.address = last_block.address + last_block.size;
    }
    heap_linear_map[block.GetVirtualAddress()] = block;

    return block.GetVirtualAddress();
}
Example #24
0
std::string map2String(std::map<std::string, double> map)
{ 
  std::string mapToString = "{";
  
  for(std::map<std::string, double>::iterator it = map.begin(); it != map.end(); ++it)
  {
      mapToString += ("\"" + it->first + "\"" + ":" + "\"" + d2String(it->second) + "\"");
      if(it->first != map.rbegin()->first)
      {
        mapToString += ",";
      }
  }
  mapToString += "}";

  return mapToString;
}
Example #25
0
    iterator alloc_oid() {
        OID x;
        if (free_oids.empty()) {
            x = 1 + records.rbegin()->first;
        }
        else {
            auto it = free_oids.begin();
            x = *it;
            free_oids.erase(it);
        }

        auto v = null_entry();
        auto rval = records.insert(std::make_pair(x, v));
        ASSERT(rval.second); // inserted (not already present)
        return rval.first;
        
    }
Example #26
0
/**
 * Export data for api calls
 */
int stats_get_history(int thr_id, struct stats_data *data, int max_records)
{
	const uint64_t gpu = device_map[thr_id];
	const uint64_t keymsk = 0xffULL; // last u8 is the gpu
	int records = 0;

	std::map<uint64_t, stats_data>::reverse_iterator i = tlastscans.rbegin();
	while (i != tlastscans.rend() && records < max_records) 
	{
		if (!i->second.ignored)
			if (thr_id == -1 || (keymsk & i->first) == gpu) {
				memcpy(&data[records], &(i->second), sizeof(struct stats_data));
				records++;
			}
		++i;
	}
	return records;
}
void f_map() {
  std::map<int, int> C;
  std::map<int, int>::iterator MapI1 = C.begin();
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when declaring iterators
  // CHECK-FIXES: auto MapI1 = C.begin();

  std::map<int, int>::reverse_iterator MapI2 = C.rbegin();
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when declaring iterators
  // CHECK-FIXES: auto MapI2 = C.rbegin();

  const std::map<int, int> D;
  std::map<int, int>::const_iterator MapI3 = D.begin();
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when declaring iterators
  // CHECK-FIXES: auto MapI3 = D.begin();

  std::map<int, int>::const_reverse_iterator MapI4 = D.rbegin();
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when declaring iterators
  // CHECK-FIXES: auto MapI4 = D.rbegin();
}
Example #28
0
unsigned int CBRepSurface::GetFreeKey(const std::map<unsigned int,unsigned int>& map)
{
	if( map.empty() ) return 1;
	////////////////
	{
		std::map<unsigned int,unsigned int>::const_reverse_iterator ritr = map.rbegin();
		const unsigned int max_id = ritr->first;
		if( max_id < map.size() * 2 ){ return max_id+1; }
	}
	////////////////
	unsigned int cand = 1;
	std::map<unsigned int,unsigned int>::const_iterator itr = map.begin();
	for(;itr!=map.end();itr++){
		const unsigned int key = itr->first;
		if( key > cand ) return cand;
		cand++;
	}
	return cand;
}
void EmployeeListDialog::ShowEmployeeList( std::map<int, Employee*> &itsEmployees )
{
	QTableWidget *tableWidget = this->ui->tableWidgetEmployeeList;
	int count = 0;
	for ( std::map<int, Employee *>::reverse_iterator it = itsEmployees.rbegin();
		it != itsEmployees.rend();
		++it ) {
			Employee *e = it->second;
			QString strID;

			tableWidget->setItem(count,0,new QTableWidgetItem(QString::number(e->GetEmpId(), 10)));
			tableWidget->setItem(count,1,new QTableWidgetItem(e->GetName().c_str()));
			tableWidget->setItem(count,2,new QTableWidgetItem(e->GetAddress().c_str()));
			tableWidget->setItem(count,3,new QTableWidgetItem("null"));

			++count;
	}

	tableWidget->show();
}
Example #30
0
void CanvasLayout::insertObjects(
    const std::map<int, std::shared_ptr<IObject>>& objects)
{
    if (objects.empty())
        return;

    if (m_objects.empty()) {
        m_objects = objects;
    } else {
        m_objects.insert(objects.begin(), objects.end());
    }

    m_nextID = std::max(m_nextID, objects.rbegin()->first + 1);
    refill();

    if (m_box->isValid()) {
        for (auto it = objects.begin(); it != objects.end(); ++it)
            loadIfNeededNoCheck(m_box, it->second.get());
    }
    updateBox();
}