本文整理汇总了C++中std::set::lower_bound方法的典型用法代码示例。如果您正苦于以下问题:C++ set::lower_bound方法的具体用法?C++ set::lower_bound怎么用?C++ set::lower_bound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::set
的用法示例。
在下文中一共展示了set::lower_bound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadInternal
bool DirectoryBlobReader::ReadInternal(u64 offset, u64 length, u8* buffer,
const std::set<DiscContent>& contents)
{
if (contents.empty())
return true;
// Determine which DiscContent the offset refers to
std::set<DiscContent>::const_iterator it = contents.lower_bound(DiscContent(offset));
if (it->GetOffset() > offset && it != contents.begin())
--it;
// zero fill to start of file data
PadToAddress(it->GetOffset(), &offset, &length, &buffer);
while (it != contents.end() && length > 0)
{
_dbg_assert_(DISCIO, it->GetOffset() <= offset);
if (!it->Read(&offset, &length, &buffer))
return false;
++it;
if (it != contents.end())
{
_dbg_assert_(DISCIO, it->GetOffset() >= offset);
PadToAddress(it->GetOffset(), &offset, &length, &buffer);
}
}
return true;
}
示例2: addLine
/*
* INFO: Adding line to the envelope
* Line is of type 'y=a*x+b' represented by 2 coefficients 'a' and 'b'
* COMPLEXITY: Adding N lines(N calls of function) takes O(N*log N) time
*/
void addLine(coef_t a, coef_t b)
{
//find the place where line will be inserted in set
Line l3 = Line(a, b);
auto it = hull.lower_bound(l3);
//if parallel line is already in set, one of them becomes irrelevant
if (it!=hull.end() && areParallel(*it, l3))
{
if (isMax && it->b < b || !isMax && it->b > b)
it = hull.erase(it);
else
return;
}
//try to insert
it = hull.insert(it, l3);
if (irrelevant(it)) { hull.erase(it); return; }
//remove lines which became irrelevant after inserting line
while (hasPrev(it) && irrelevant(std::prev(it))) hull.erase(std::prev(it));
while (hasNext(it) && irrelevant(std::next(it))) hull.erase(std::next(it));
//refresh 'xLine'
it = updateLeftBorder(it);
if (hasPrev(it))
updateLeftBorder(std::prev(it));
if (hasNext(it))
updateLeftBorder(std::next(it));
}
示例3: excellent
int excellent(){
int i,x,y,count;
std::set<std::pair<int,int> >::iterator first,last,prev;
C.clear();
C.insert(A[0].second);
count = 1;
for(i = 1; i < N; i++){
x = A[i].second.first;
y = A[i].second.second;
prev = C.lower_bound(A[i].second);
first = prev;
if(prev == C.begin() || (*(--prev)).second > y){
++count;
last = first;
while(last != C.end() && (*last).second > y) last++;
if(first != last) C.erase(first,last);
C.insert(A[i].second);
}
}
return count;
}
示例4: getClosestToRef
size_t DiscreteDepthDistortionModel::getClosestToRef(const std::set<size_t> &divisors, const double &ref)
{
std::set<size_t>::iterator low, prev;
low = divisors.lower_bound(ref);
if(low == divisors.end())
{
return *(--divisors.end());
}
else if(low == divisors.begin())
{
return *low;
}
else
{
prev = low;
--prev;
if((ref - *prev) <= (*low - ref))
{
return *prev;
}
else
{
return *low;
}
}
}
示例5: main
int main(void)
{
scanf("%d", &tests);
for(int t = 0; t < tests; ++ t)
{
tree = iTree();
scanf("%d", &size);
for(int s = 0; s < size; ++ s)
{
scanf("%d", &tab[s]);
secik.insert(s);
}
for(int s = size - 1; s >= 0; -- s)
{
//printf("%d: %d; %d\n", s + 1, tab[s], tree.get(tab[s] + 1));
temp = secik.lower_bound(tab[s] + tree.get(tab[s] + 1));
result[s] = *temp + 1;
//printf("%d => %d\n", s + 1, *temp + 1);
secik.erase(temp);
tree.insert(tab[s] + 2);
}
for(int s = 0; s < size; ++ s)
printf("%d ", result[s]);
puts("");
}
return 0;
}
示例6: findNearestAllowedAngle
Float_t findNearestAllowedAngle(std::set<Float_t>& angles,
const Float_t ang) {
// find closest allowed angle
std::set<Float_t>::const_iterator
hiang = angles.lower_bound(ang),
loang = hiang;
if (loang!=angles.begin()) {
--loang;
}
#ifdef DEBUG
Printf("loang=%p, hiang=%p, end=%p",
(void*)&(*loang), (void*)&(*hiang), (void*)&(*angles.end()));
#endif
if ( (loang==angles.end()) || (hiang==angles.end()) ) {
// too big; take the largest one
return *(angles.rbegin());
} else {
// round to the nearest angle (round up if halfway)
#ifdef DEBUG
Printf("loang=%g, hiang=%g, ang=%g",
*loang, *hiang, ang);
#endif
if ( TMath::Abs(*loang - ang) < TMath::Abs(*hiang - ang) ) {
return *loang;
} else {
return *hiang;
}
}
}
示例7:
std::set<IDBKeyData>::iterator MemoryObjectStoreCursor::firstForwardIteratorInRemainingRange(std::set<IDBKeyData>& set)
{
if (m_remainingRange.isExactlyOneKey())
return set.find(m_remainingRange.lowerKey);
auto lowest = set.lower_bound(m_remainingRange.lowerKey);
if (lowest == set.end())
return lowest;
if (m_remainingRange.lowerOpen && *lowest == m_remainingRange.lowerKey) {
++lowest;
if (lowest == set.end())
return lowest;
}
if (!m_remainingRange.upperKey.isNull()) {
if (lowest->compare(m_remainingRange.upperKey) > 0)
return set.end();
if (m_remainingRange.upperOpen && *lowest == m_remainingRange.upperKey)
return set.end();
}
return lowest;
}
示例8: Set
void Set(const uint256 &hash, const std::vector<unsigned char>& vchSig, const CPubKey& pubKey)
{
// DoS prevention: limit cache size to less than 10MB
// (~200 bytes per cache entry times 50,000 entries)
// Since there are a maximum of 20,000 signature operations per block
// 50,000 is a reasonable default.
int64_t nMaxCacheSize = GetArg("-maxsigcachesize", 50000);
if (nMaxCacheSize <= 0) return;
boost::unique_lock<boost::shared_mutex> lock(cs_sigcache);
while (static_cast<int64_t>(setValid.size()) > nMaxCacheSize)
{
// Evict a random entry. Random because that helps
// foil would-be DoS attackers who might try to pre-generate
// and re-use a set of valid signatures just-slightly-greater
// than our cache size.
uint256 randomHash = GetRandHash();
std::vector<unsigned char> unused;
std::set<sigdata_type>::iterator it =
setValid.lower_bound(sigdata_type(randomHash, unused, unused));
if (it == setValid.end())
it = setValid.begin();
setValid.erase(*it);
}
sigdata_type k(hash, vchSig, pubKey);
setValid.insert(k);
}
示例9: ComputeNodesReachableFrom
/// ComputeNodesReacahbleFrom - Compute the set of nodes in the specified
/// inverse graph that are reachable from N. This is a simple depth first
/// search.
///
static void ComputeNodesReachableFrom(DSNode *N,
std::set<std::pair<DSNode*,DSNode*> > &InverseGraph,
hash_set<const DSNode*> &Reachable) {
if (!Reachable.insert(N).second) return; // Already visited!
std::set<std::pair<DSNode*,DSNode*> >::iterator I =
InverseGraph.lower_bound(std::make_pair(N, (DSNode*)0));
for (; I != InverseGraph.end() && I->first == N; ++I)
ComputeNodesReachableFrom(I->second, InverseGraph, Reachable);
}
示例10: getBest
/*
* INFO: Query, which returns max/min(depends on hull type - see more info above) value in point with abscissa 'x'
* COMPLEXITY: O(log N), N-amount of lines in hull
*/
val_t getBest(coord_t x) const
{
Line q;
q.val = x;
q.type = isMax ? Line::Type::maxQuery : Line::Type::minQuery;
auto bestLine = hull.lower_bound(q);
if (isMax) --bestLine;
return bestLine->valueAt(x);
}
示例11: FindRandomFrom
UtxoData::iterator FindRandomFrom(const std::set<COutPoint> &utxoSet) {
assert(utxoSet.size());
auto utxoSetIt = utxoSet.lower_bound(COutPoint(InsecureRand256(), 0));
if (utxoSetIt == utxoSet.end()) {
utxoSetIt = utxoSet.begin();
}
auto utxoDataIt = utxoData.find(*utxoSetIt);
assert(utxoDataIt != utxoData.end());
return utxoDataIt;
}
示例12: getBest
val_t getBest(coord_t x) const
{
Line q;
q.val = x;
q.type = isMax ? Line::Type::maxQuery : Line::Type::minQuery;
if(hull.empty())
return isMax? -INF:INF;
auto bestLine = hull.lower_bound(q);
if(hull.begin()==bestLine && isMax)return isMax?-INF:INF;
if (isMax) --bestLine;
return bestLine->valueAt(x);
}
示例13: insertEmptyColumns
void ColumnCmd::insertEmptyColumns(const std::set<int> &indices,
bool insertAfter) {
// Filter out all less than 0 indices (in particular, the 'camera' column
// in the Toonz derivative product "Tab")
std::vector<int> positiveIndices(indices.lower_bound(0), indices.end());
if (positiveIndices.empty()) return;
std::unique_ptr<ColumnCommandUndo> undo(
new InsertEmptyColumnsUndo(positiveIndices, insertAfter));
if (undo->isConsistent()) {
undo->redo();
TUndoManager::manager()->add(undo.release());
}
}
示例14: main
int main(){
//insert O(log N) per element or O(1) am per element for _sorted_ elements
//For a total of O(N log N) or O(N) for sorted inputs
int key;
for(key = 0; key < 10; key++){
myset.insert(key);
}
//find O(log N)
it = myset.find(3);
//removes 3 in O(1) am post-find time
myset.erase(it);
//removes 4 from the set O(log N) time
myset.erase(4);
//iterate the set in forward order O(1) am / O(log N)
//for a total of O(N) total
//Note that begin() returns an iterator to the first element
//whereas that end() returns to a dummy element after the last element
for(it = myset.begin(); it != myset.end(); it++){
std::cout << *it << " " ;
}
std::cout << std::endl;
//iterate the set in reverse order )O(1) am / O(log N)
//for a total of O(N) total
//Note that rbegin() returns an iterator to the last element
//whereas that end() returns to a dummy element before the first element
for(rit = myset.rbegin(); rit != myset.rend(); rit++){
std::cout << *rit << " " ;
}
std::cout << std::endl;
//Find the first element greater than or equal to the current element in O(log N) time
//In this case it returns 6
it = myset.lower_bound(6);
std::cout << *it << std::endl;
//Find the first element greater than the current element in O(log N) time
//In this case it returns 7
it = myset.upper_bound(6);
std::cout << *it << std::endl;
// Empties the set O(N) time
myset.clear();
}
示例15: setForwardIteratorFromRemainingRange
void MemoryObjectStoreCursor::setForwardIteratorFromRemainingRange(std::set<IDBKeyData>& set)
{
if (!set.size()) {
m_iterator = Nullopt;
return;
}
if (m_remainingRange.isExactlyOneKey()) {
m_iterator = set.find(m_remainingRange.lowerKey);
if (*m_iterator == set.end())
m_iterator = Nullopt;
return;
}
m_iterator = Nullopt;
auto lowest = set.lower_bound(m_remainingRange.lowerKey);
if (lowest == set.end())
return;
if (m_remainingRange.lowerOpen && *lowest == m_remainingRange.lowerKey) {
++lowest;
if (lowest == set.end())
return;
}
if (!m_remainingRange.upperKey.isNull()) {
if (lowest->compare(m_remainingRange.upperKey) > 0)
return;
if (m_remainingRange.upperOpen && *lowest == m_remainingRange.upperKey)
return;
}
m_iterator = lowest;
}