本文整理汇总了C++中std::map::lower_bound方法的典型用法代码示例。如果您正苦于以下问题:C++ map::lower_bound方法的具体用法?C++ map::lower_bound怎么用?C++ map::lower_bound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::map
的用法示例。
在下文中一共展示了map::lower_bound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: move_close_to
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;
}
}
示例2: findDisassemblyEntry
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();
}
示例3:
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;
}
示例4:
//
// 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()) {
}
示例5: lock
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);
}
示例6:
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;
}
示例7: getMyProfile
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
}
}
示例8: mergeInto
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);
}
}
}
示例9: assign
// 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));
}
}
示例10: NewTx
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;
}
示例11: remove_expired_keys
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!");
}
}
示例12: find_row_for_id
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;
}
示例13: RandomOrphan
CTransactionRef RandomOrphan()
{
std::map<uint256, COrphanTx>::iterator it;
it = mapOrphanTransactions.lower_bound(GetRandHash());
if (it == mapOrphanTransactions.end())
it = mapOrphanTransactions.begin();
return it->second.tx;
}
示例14:
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;
}
示例15: RandomOrphan
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;
}