Ejemplo n.º 1
0
 void move_close_to(vid_t v) {
     if (curvid >= v) return;
     
     std::map<int,indexentry>::iterator lowerbd_iter = sparse_index.lower_bound(-((int)v));
     int closest_vid = -((int)lowerbd_iter->first);
     assert(closest_vid>=0);
     indexentry closest_offset = lowerbd_iter->second;
     assert(closest_vid <= (int)v);
     if (closest_vid > (int)curvid) {   /* Note: this will fail if we have over 2B vertices! */
         logstream(LOG_DEBUG)
         << "Sliding shard, start: " << range_st << " moved to: " << closest_vid << " " << closest_offset.adjoffset << ", asked for : " << v << " was in: curvid= " << curvid  << " " << adjoffset << std::endl;
         if (curblock != NULL) // Move the pointer - this may invalidate the curblock, but it is being checked later
             curblock->ptr += closest_offset.edataoffset - edataoffset;
         if (curadjblock != NULL)
             curadjblock->ptr += closest_offset.adjoffset - adjoffset;
         curvid = (vid_t)closest_vid;
         adjoffset = closest_offset.adjoffset;
         edataoffset = closest_offset.edataoffset;
         return;
     } else {
         // Do nothing - just continue from current pos.
         return;
     }
     
 }
Ejemplo n.º 2
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();
}
Ejemplo n.º 3
0
const char * AbiWordperfectInputStream::subStreamName(unsigned id)
{
	if (!m_ole)
		m_ole = GSF_INFILE(gsf_infile_msole_new (m_input, NULL)); 
	
	if (!m_ole)
		m_ole = GSF_INFILE(gsf_infile_zip_new (m_input, NULL)); 
	
	if (m_ole)
		{
			if ((int)id >= gsf_infile_num_children(m_ole))
			{
				return 0;
			}
			std::map<unsigned, std::string>::iterator i = m_substreams.lower_bound(id);
			if (i == m_substreams.end() || m_substreams.key_comp()(id, i->first))
				{
					std::string name = gsf_infile_name_by_index(m_ole, (int)id);
					i = m_substreams.insert(i, std::map<unsigned, std::string>::value_type(id, name));
				}
			return i->second.c_str();
		}
	
	return 0;
}
Ejemplo n.º 4
0
//
// Creates an iterator over a collection of ties represented by the
// given map. The values of the pairs in the map represent the values
// of ties, and the keys represent the corresponding neighbors. Only
// neighbors that are greater or equal with the given bound are returned.
//
IncidentTieIterator::IncidentTieIterator(const std::map<int, int> & ties,
		int lowerBound) :
		ITieIterator(), //
		lstart(ties.lower_bound(lowerBound)), //
		lcurrent(lstart), //
		lend(ties.end()) {
}
Ejemplo n.º 5
0
void __stdcall touring_Tier0_CMemAlloc_Free(DWORD * this_ptr, void *pMem)
{
	if(pMem)
	{
		size_t size = SOURCESDK::Get_g_pMemAlloc()->GetSize(pMem); // Make sure GetSize is not called with 0 pointer!

		void * upperBound = (char *)pMem + size;

		std::unique_lock<std::mutex> lock(g_Tier0MemAllocFreeNotifyeesMutex);
		for (std::map<void *, CTier0MemAllocFreeNotifyees>::iterator it = g_Tier0MemAllocFreeNotifyees.lower_bound(pMem); it != g_Tier0MemAllocFreeNotifyees.end(); )
		{
			if (it->first < upperBound)
			{
				it->second.Notify(it->first);

				std::map<void *, CTier0MemAllocFreeNotifyees>::iterator itErase = it;
				++it;

				g_Tier0MemAllocFreeNotifyees.erase(itErase);
			}
			else
				break;
		}
	}

	g_Tier0_CMemAlloc_Free(this_ptr, pMem);
}
Ejemplo n.º 6
0
InstrInfo
get(uint32_t address)
{
   auto info = InstrInfo { 0 };
   auto instrIter = sInstrData.find(address);

   if (instrIter != sInstrData.end()) {
      info.instr = &instrIter->second;
   }

   if (sFuncData.size() > 0) {
      auto funcIter = sFuncData.lower_bound(address);
      auto &func = funcIter->second;

      if (address >= func.start && address < func.end) {
         // The function needs to have an end, or be the first two instructions
         //  since we apply some special display logic to the first two instructions
         //  in a never-ending function...
         if (func.end != 0xFFFFFFFF || (address == func.start || address == func.start + 4)) {
            info.func = &func;
         }
      }
   }

   return info;
}
Ejemplo n.º 7
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
    }
}
template<typename T> void mergeInto(std::map<unsigned, std::vector<T>>& _container, unsigned _number, T&& _data)
{
	assert(!haveItem(_container, _number));
	auto lower = _container.lower_bound(_number);
	if (!_container.empty() && lower != _container.begin())
		--lower;
	if (lower != _container.end() && (lower->first + lower->second.size() == _number))
	{
		// extend existing chunk
		lower->second.emplace_back(_data);

		auto next = lower;
		++next;
		if (next != _container.end() && (lower->first + lower->second.size() == next->first))
		{
			// merge with the next chunk
			std::move(next->second.begin(), next->second.end(), std::back_inserter(lower->second));
			_container.erase(next);
		}

	}
	else
	{
		// insert a new chunk
		auto inserted = _container.insert(lower, std::make_pair(_number, std::vector<T> { _data }));
		auto next = inserted;
		++next;
		if (next != _container.end() && next->first == _number + 1)
		{
			std::move(next->second.begin(), next->second.end(), std::back_inserter(inserted->second));
			_container.erase(next);
		}
	}

}
Ejemplo n.º 9
0
    // Assign value val to interval [keyBegin, keyEnd). 
    // Overwrite previous values in this interval. 
    // Do not change values outside this interval.
    // Conforming to the C++ Standard Library conventions, the interval 
    // includes keyBegin, but excludes keyEnd.
    // If !( keyBegin < keyEnd ), this designates an empty interval, 
    // and assign must do nothing.
    void assign( K const& keyBegin, K const& keyEnd, const V& val) {
        
        using iter_t = std::map<K, V>::const_iterator;

        if (!(keyBegin < keyEnd))
            return;

        const iter_t lower_bound = map_.lower_bound(keyBegin);
        const iter_t upper_bound = map_.upper_bound(keyEnd);
        const iter_t prev = std::prev(lower_bound);
        const iter_t next = std::prev(upper_bound);

        // erase elements in range [lower_bound, upper_bound)
        map_.erase(lower_bound, upper_bound);

        if (!(prev->second == val)) {
            // set new value at the beginning of the range
            map_.insert(upper_bound, std::make_pair(keyBegin, val));
        }

        if (!(next->second == val)) {
            // set next value at the end of the range
            map_.insert(upper_bound, std::make_pair(keyEnd, next->second));
        }
    }
Ejemplo n.º 10
0
unsigned int TxConfirmStats::NewTx(unsigned int nBlockHeight, double val)
{
    unsigned int bucketindex = bucketMap.lower_bound(val)->second;
    unsigned int blockIndex = nBlockHeight % unconfTxs.size();
    unconfTxs[blockIndex][bucketindex]++;
    return bucketindex;
}
Ejemplo n.º 11
0
void LogMonitorHandler::remove_expired_keys(std::map<time_t, StatInfo> &m, time_t expired_time) {
    std::map<time_t, StatInfo>::iterator e_index = m.lower_bound(expired_time);
    if (e_index != m.begin()) {
        m.erase(m.begin(), e_index);
        LOG_DEBUG("has expired record is remove!");
    }
}
Ejemplo n.º 12
0
GlobalOrdinal find_row_for_id(GlobalOrdinal id,
                              const std::map<GlobalOrdinal,GlobalOrdinal>& ids_to_rows)
{
  typename std::map<GlobalOrdinal,GlobalOrdinal>::const_iterator
    iter = ids_to_rows.lower_bound(id);

  if (iter == ids_to_rows.end() || iter->first != id) {
    if (ids_to_rows.size() > 0) {
      --iter;
    }
    else {
      std::cout << "ERROR, failed to map id to row."<<std::endl;
      return -99;
    }
  }

  if (iter->first == id) {
    return iter->second;
  }

  if (iter == ids_to_rows.begin() && iter->first > id) {
    std::cout << "ERROR, id:" << id << ", ids_to_rows.begin(): " << iter->first<<std::endl;
    return -99;
  }

  GlobalOrdinal offset = id - iter->first;

  if (offset < 0) {
    std::cout << "ERROR, negative offset in find_row_for_id for id="<<id<<std::endl;
    return -99;
  }

  return iter->second + offset;
}
Ejemplo n.º 13
0
CTransactionRef RandomOrphan()
{
    std::map<uint256, COrphanTx>::iterator it;
    it = mapOrphanTransactions.lower_bound(GetRandHash());
    if (it == mapOrphanTransactions.end())
        it = mapOrphanTransactions.begin();
    return it->second.tx;
}
Ejemplo n.º 14
0
	static const T &load(const std::string &resourceName, Args... args){
		typename std::map<std::string, T>::iterator p = _resources.lower_bound(resourceName);
		if(p == _resources.end() || p->first != resourceName){
			cout<<"WARNING: Resource: "+resourceName+" not found. Loading..."<<endl;
			p = _resources.emplace_hint(p, std::piecewise_construct, std::forward_as_tuple(resourceName), std::forward_as_tuple(args...));
		}
		return p->second;
	}
Ejemplo n.º 15
0
CTransactionRef RandomOrphan()
{
    std::map<uint256, COrphanTx>::iterator it;
    LOCK(cs_main);
    it = mapOrphanTransactions.lower_bound(InsecureRand256());
    if (it == mapOrphanTransactions.end())
        it = mapOrphanTransactions.begin();
    return it->second.tx;
}
Ejemplo n.º 16
0
  bool is_dummy_address (void *addr) {

    intptr_t ip = intptr_t (addr);
    auto it = absptrmap.lower_bound (ip+1);
    if (it == absptrmap.end()) return false;
    intptr_t lb = it->first;
    intptr_t ub = it->second;

    return (ip >= lb && ip < ub);
  }
Ejemplo n.º 17
0
	char * findPtrForSize(size_t size)
	{
		auto it = freeSize.lower_bound(size);
		if(it != freeSize.end())
		{
			assert(it->second.empty() == false);
			return *(it->second.begin());
		}
		return NULL;
	}
Ejemplo n.º 18
0
	///////////////////////
	/// Devuelve el recurso asociado con el nombre, si no está trata de crearlo usando un constructor por defecto e inicializarlo luego llamando a la funcion f con los parametros args
	//////////////////////
	static const T &loadFromFile(const std::string &fileName){
		typename std::map<std::string, T>::iterator p = _resources.lower_bound(fileName);
		if(p == _resources.end() || p->first != fileName){
			p = _resources.emplace_hint(p, std::piecewise_construct, std::forward_as_tuple(fileName), std::forward_as_tuple());
			if(!p->second.loadFromFile(fileName)){
				cout<<"ERROR: Couldn't load file: "<<fileName<<endl;
			}
		}
		return p->second;
	}
Ejemplo n.º 19
0
static inline void increaseColorUsage(uint32_t color, uint32_t usageCount, std::map<uint32_t, uint32_t> & colorUsage) {
	auto lb = colorUsage.lower_bound(color);
	if (lb != colorUsage.end() && !(colorUsage.key_comp()(color, lb->first))) {
		// Color already in map.
		lb->second += usageCount;
	} else {
		// Insert new color into map.
		colorUsage.insert(lb, std::make_pair(color, usageCount));
	}
}
Ejemplo n.º 20
0
void LogMonitorHandler::get_range_map(std::map<time_t, StatInfo> & origin_map, std::map<time_t, StatInfo> & stat_map, time_t start, time_t end) {
    std::map<time_t, StatInfo>::iterator start_iter = origin_map.lower_bound(start);
    while(start_iter != origin_map.end()){
        if (start_iter->first >= end) {
            break;
        }
        stat_map[start_iter->first] = start_iter->second;
        start_iter++;
    }
}
Ejemplo n.º 21
0
 Individual<Phenotype, Genotype> mutate(Individual<Phenotype, Genotype> i,
                                        const Codec<Phenotype, Genotype>& codec) override
 {
   float p = distribution_(generator_);
   auto it = mutations_.lower_bound(p);
   if (it == mutations_.end()){
     it = mutations_.begin();
   }
   MutationPtr& mutation = it->second;
   return std::move(mutation->mutate(std::move(i), codec));
 }
Ejemplo n.º 22
0
template<typename T> bool haveItem(std::map<unsigned, T>& _container, unsigned _number)
{
	if (_container.empty())
		return false;
	auto lower = _container.lower_bound(_number);
	if (lower != _container.end() && lower->first == _number)
		return true;
	if (lower ==  _container.begin())
		return false;
	--lower;
	return lower->first <= _number && (lower->first + lower->second.size()) > _number;
}
Ejemplo n.º 23
0
static std::pair< std::map< std::string, std::vector<const TestFactory*> >::const_iterator,
                  std::map< std::string, std::vector<const TestFactory*> >::const_iterator >
matching_range( const std::map< std::string, std::vector<const TestFactory*> > & tests, const std::string & group )
{
    assert( !group.empty() );
    assert( *group.rbegin() == '/' );
    std::map< std::string, std::vector<const TestFactory*> >::const_iterator b, e;
    e = b = tests.lower_bound( group );
    while ( e != tests.end() && e->first.find( group ) == 0 )
        ++e;
    return std::make_pair( b, e );
}
Ejemplo n.º 24
0
void TxConfirmStats::Record(int blocksToConfirm, double val)
{
    // blocksToConfirm is 1-based
    if (blocksToConfirm < 1)
        return;
    unsigned int bucketindex = bucketMap.lower_bound(val)->second;
    for (size_t i = blocksToConfirm; i <= curBlockConf.size(); i++) {
        curBlockConf[i - 1][bucketindex]++;
    }
    curBlockTxCt[bucketindex]++;
    curBlockVal[bucketindex] += val;
}
Ejemplo n.º 25
0
float VSRayTracingVisitor::interpolate(const std::map<unsigned, float>& data,
				       float x)
{
  std::map<unsigned, float>::const_iterator itr = 
    data.lower_bound((unsigned)x);

  float x2 = itr->first;
  float y2 = itr->second;
  --itr;
  float x1 = itr->first;
  float y1 = itr->second;
  return y1 + (x-x1)*(y2-y1)/(x2-x1);
}
Ejemplo n.º 26
0
 /**
  *  Send all inventory items that are not known to c and are dated 'after'
  */
 void handle_get_inv( const connection_ptr& c, bitchat_chan_data& cd, const get_inv_message& msg )
 {
    inv_message reply;
    for( auto itr = msg_time_index.lower_bound( fc::time_point(msg.after) ); itr != msg_time_index.end(); ++itr )
    {
       if( cd.known_inv.insert( itr->second ).second )
       {
          reply.items.push_back( itr->second );
          cd.known_inv.insert( itr->second );
       }
    }
    c->send( network::message( reply, chan_id ) );
 }
Ejemplo n.º 27
0
      unsigned getOrCreateDiagID(DiagnosticIDs::Level L, StringRef Message,
                                 DiagnosticIDs &Diags) {
        DiagDesc D(L, Message);
        // Check to see if it already exists.
        std::map<DiagDesc, unsigned>::iterator I = DiagIDs.lower_bound(D);
        if (I != DiagIDs.end() && I->first == D)
          return I->second;

        // If not, assign a new ID.
        unsigned ID = DiagInfo.size()+DIAG_UPPER_LIMIT;
        DiagIDs.insert(std::make_pair(D, ID));
        DiagInfo.push_back(D);
        return ID;
      }
Ejemplo n.º 28
0
template<typename T> void removeItem(std::map<unsigned, std::vector<T>>& _container, unsigned _number)
{
	if (_container.empty())
		return;
	auto lower = _container.lower_bound(_number);
	if (lower != _container.end() && lower->first == _number)
	{
		_container.erase(lower);
		return;
	}
	if (lower ==  _container.begin())
		return;
	--lower;
	if (lower->first <= _number && (lower->first + lower->second.size()) > _number)
		lower->second.erase(lower->second.begin() + (_number - lower->first), lower->second.end());
}
 void addNum(int val) {
     auto it = map.lower_bound(val);
     if (it == map.end()) {
         if (!map.empty()) {
             auto prev_it = it;
             prev_it--;
             if (prev_it->second >= val) {
                 return;
             } else if (prev_it->second == val - 1) {
                 prev_it->second = val;
                 return;
             }
         }
         map[val] = val;
     } else if (it == map.begin()) {
         if (it->first == val) {
             return;
         } else if (it->first == val + 1) {
             map[val] = it->second;
             map.erase(val + 1);
         } else {
             map[val] = val;
         }
     } else {
         auto prev_it = it;
         prev_it--;
         if (prev_it->second >= val || it->first == val) {
             return;
         } else if (prev_it->second == val - 1) {
             if (it->first == val + 1) {
                 prev_it->second = it->second;
                 map.erase(val + 1);
             } else {
                 prev_it->second = val;
             }
         } else if (it->first == val + 1) {
             map[val] = it->second;
             map.erase(val + 1);
         } else {
             map[val] = val;
         }
     }
 }
Ejemplo n.º 30
0
inline std::map<K, V> operator>> (object o, std::map<K, V>& v)
{
	if(o.type != type::MAP) { throw type_error(); }
	object_kv* p(o.via.map.ptr);
	object_kv* const pend(o.via.map.ptr + o.via.map.size);
	for(; p != pend; ++p) {
		K key;
		p->key.convert(&key);
		typename std::map<K,V>::iterator it(v.lower_bound(key));
		if(it != v.end() && !(key < it->first)) {
			p->val.convert(&it->second);
		} else {
			V val;
			p->val.convert(&val);
			v.insert(it, std::pair<K,V>(key, val));
		}
	}
	return v;
}