本文整理汇总了C++中std::set::rbegin方法的典型用法代码示例。如果您正苦于以下问题:C++ set::rbegin方法的具体用法?C++ set::rbegin怎么用?C++ set::rbegin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::set
的用法示例。
在下文中一共展示了set::rbegin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: xpt
double operator[](double x) const {
assert(!curve_.empty());
AbstractCurvePoint xpt(x);
if (xpt <= *curve_.begin()) {
return static_cast<double>(*curve_.begin());
}
if (xpt >= *curve_.rbegin()) {
return static_cast<double>(*curve_.rbegin());
}
auto it_max = curve_.upper_bound(xpt);
assert(!((*it_max) <= xpt));
assert(xpt != (*it_max));
assert(xpt < (*it_max));
auto it_min = std::prev(it_max, 1);
assert(!((*it_min) > xpt));
assert((*it_min) <= xpt);
assert((*it_min) < (*it_max));
assert((*it_min) != (*it_max));
if (xpt == (*it_min)) {
return static_cast<double>(*it_min);
}
return (*it_min).interpolate(*it_max, x);
}
示例2: 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;
}
}
}
示例3: deleteRows
void DebtsTableModel::deleteRows(const std::set<int>& rows)
{
for (std::set<int>::const_reverse_iterator iter=rows.rbegin(); iter!=rows.rend(); ++iter)
{
mCostSplitter->removeDebt(*iter);
}
}
示例4: output
void output(int oo)
{
if (oo != *pos.rbegin())
printf("%d ", oo);
else
printf("%d", oo);
}
示例5: newStorageWithRemovedRows
Storage newStorageWithRemovedRows(const Storage& origSto,
const std::set<int>& rowsToRemove) {
Storage sto(1000);
auto labels = origSto.getColumnLabels();
auto numOrigColumns = origSto.getColumnLabels().getSize() - 1;
// Remove in reverse order so it's easier to keep track of indices.
for (auto it = rowsToRemove.rbegin(); it != rowsToRemove.rend(); ++it) {
labels.remove(*it);
}
sto.setColumnLabels(labels);
double time;
for (int itime = 0; itime < origSto.getSize(); ++itime) {
SimTK::Vector rowData(numOrigColumns);
origSto.getData(itime, numOrigColumns, rowData);
SimTK::Vector newRowData(numOrigColumns - (int)rowsToRemove.size());
int iNew = 0;
for (int iOrig = 0; iOrig < numOrigColumns; ++iOrig) {
if (rowsToRemove.count(iOrig) == 0) {
newRowData[iNew] = rowData[iOrig];
++iNew;
}
}
origSto.getTime(itime, time);
sto.append(time, newRowData);
}
return sto;
}
示例6: merge
void merge( std::set<T>& bigger, const std::set<U>& smaller )
{
// invariant: largest element of smaller is smaller than the smallest element of bigger
for( auto iter = smaller.rbegin() ; iter != smaller.rend() ; ++iter )
bigger.emplace_hint( bigger.begin(), *iter ) ;
// http://en.cppreference.com/w/cpp/container/set/emplace_hint
}
示例7: add
void DoubleList::add(const std::set<int>& sSelPos) // adds elements from the specified indexes
{
switch (m_eSelectionMode)
{
case SINGLE_UNSORTABLE:
for (set<int>::const_reverse_iterator it = sSelPos.rbegin(), end = sSelPos.rend(); it != end; ++it) // the last must be processed first, so removal of elements doesn't change the row number for the remaining ones
{
int nRow (*it);
int nIndex (m_listPainter.m_vAvailable[nRow]);
vector<int>::iterator it1 (lower_bound(m_listPainter.m_vSel.begin(), m_listPainter.m_vSel.end(), nIndex));
m_listPainter.m_vSel.insert(it1, nIndex);
m_listPainter.m_vAvailable.erase(m_listPainter.m_vAvailable.begin() + nRow);
}
break;
case SINGLE_SORTABLE:
for (set<int>::const_iterator it = sSelPos.begin(), end = sSelPos.end(); it != end; ++it)
{
int nRow (*it);
int nIndex (m_listPainter.m_vAvailable[nRow]);
m_listPainter.m_vSel.push_back(nIndex);
}
for (set<int>::const_reverse_iterator it = sSelPos.rbegin(), end = sSelPos.rend(); it != end; ++it)
{
int nRow (*it);
m_listPainter.m_vAvailable.erase(m_listPainter.m_vAvailable.begin() + nRow);
}
break;
case MULTIPLE:
for (set<int>::const_iterator it = sSelPos.begin(), end = sSelPos.end(); it != end; ++it)
{
int nRow (*it);
//int nIndex (m_listPainter.m_vAvailable[nRow]);
//m_listPainter.getSel_().push_back(nIndex);
m_listPainter.m_vSel.push_back(nRow);
}
break;
default:
CB_ASSERT(false);
}
adjustOnDataChanged();
}
示例8: setLevelsFromValues
//--------------------------------------------------------------------------------------------------
/// This method sets all the levels to the user defined domain values,
/// overriding any previous max and min range settings.
//--------------------------------------------------------------------------------------------------
void ScalarMapperRangeBased::setLevelsFromValues(const std::set<double>& levelValues)
{
CVF_ASSERT(!m_userDefinedLevelValues.empty());
m_userDefinedLevelValues = levelValues;
m_rangeMax = (*levelValues.rbegin());
m_rangeMin = (*levelValues.begin());
updateSortedLevels();
}
示例9: main
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
for (int i = 1; i <= m; i++) {
scanf("%d%d", &o[i].op, &o[i].r);
o[i].t = i;
}
for (int i = m; i >= 1; i--) {
add(n - o[i].r + 1);
if (sum(n - o[i].r) == 0) {
s[++tot] = o[i];
}
}
std::reverse(s + 1, s + tot + 1);
s[0].r = n;
s[0].t = 0;
for (int i = n; i > s[1].r; i--) {
answer[i] = a[i];
}
for (int i = s[1].r; i >= 1; i--) {
set.insert(std::make_pair(a[i], i));
}
for (int i = 2, tmp = n; i <= tot; i++) {
int length = s[i - 1].r - s[i].r, t = 0;
for (int j = 1; j <= length; j++)
if (s[i - 1].op == 1) {
auto it = --set.end();
b[++t] = *it;
set.erase(it);
} else if (s[i - 1].op == 2) {
auto it = set.begin();
b[++t] = *it;
set.erase(it);
}
for (int j = s[i - 1].r, z = 0; j > s[i].r; j--) {
answer[j] = b[++z].first;
}
}
if (s[tot].op == 1) {
int p = 0;
for (auto it = set.begin(); it != set.end(); it++) {
answer[++p] = it -> first;
}
} else {
int p = 0;
for (auto it = set.rbegin(); it != set.rend(); it++) {
answer[++p] = it -> first;
}
}
for (int i = 1; i <= n; i++) {
printf("%d%c", answer[i], " \n"[i == n]);
}
return 0;
}
示例10: COException
void VectorBase<scalar,index,SizeAtCompileTime>::blockFromVector(const VectorBase& vec,const std::set<index>& indices)
{
if( *indices.rbegin() >= vec.size() )
{
throw COException("Index out of range in Vector blocking!");
}
this->resize(indices.size());
index i = 0;
for ( const auto& s : indices ){
this->operator[](i) = vec[s];
++ i;
}
}
示例11: primeNumber
/** n**2 + a*n + b */
int primeNumber(int a, int b, const std::set<long>& primes)
{
int i = 0;
while (true)
{
long n = i*i+a*i+b;
if((*primes.rbegin())<n)
return -1;
if(primes.find(n)==primes.end())
break;
++ i;
}
return i+1;
}
示例12: 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();
}
示例13: erase_values
/**
Erase from a list of wcstring values at specified indexes
*/
static void erase_values(wcstring_list_t &list, const std::vector<long> &indexes)
{
// Make a set of indexes.
// This both sorts them into ascending order and removes duplicates.
const std::set<long> indexes_set(indexes.begin(), indexes.end());
// Now walk the set backwards, so we encounter larger indexes first, and remove elements at the given (1-based) indexes.
std::set<long>::const_reverse_iterator iter;
for (iter = indexes_set.rbegin(); iter != indexes_set.rend(); iter++) {
long val = *iter;
if (val > 0 && val <= list.size()) {
// One-based indexing!
list.erase(list.begin() + val - 1);
}
}
}
示例14: remove
void DoubleList::remove(const std::set<int>& sSelPos) // removes elements from the specified indexes
{
for (set<int>::const_reverse_iterator it = sSelPos.rbegin(), end = sSelPos.rend(); it != end; ++it)
{
int nRow (*it);
int nIndex (m_listPainter.m_vSel[nRow]);
if (MULTIPLE != m_eSelectionMode)
{
vector<int>::iterator it1 (lower_bound(m_listPainter.m_vAvailable.begin(), m_listPainter.m_vAvailable.end(), nIndex));
m_listPainter.m_vAvailable.insert(it1, nIndex);
}
m_listPainter.m_vSel.erase(m_listPainter.m_vSel.begin() + nRow);
}
adjustOnDataChanged();
}
示例15: if
void
Network::setPhases_(Region *r, std::set<UInt32>& phases)
{
if (phases.empty())
NTA_THROW << "Attempt to set empty phase list for region " << r->getName();
UInt32 maxNewPhase = *(phases.rbegin());
UInt32 nextPhase = phaseInfo_.size();
if (maxNewPhase >= nextPhase)
{
// It is very unlikely that someone would add a region
// with a phase much greater than the phase of any other
// region. This sanity check catches such problems,
// though it should arguably be legal to set any phase.
if (maxNewPhase - nextPhase > 3)
NTA_THROW << "Attempt to set phase of " << maxNewPhase
<< " when expected next phase is " << nextPhase
<< " -- this is probably an error.";
phaseInfo_.resize(maxNewPhase+1);
}
for (UInt i = 0; i < phaseInfo_.size(); i++)
{
bool insertPhase = false;
if (phases.find(i) != phases.end())
insertPhase = true;
// remove previous settings for this region
std::set<Region*>::iterator item;
item = phaseInfo_[i].find(r);
if (item != phaseInfo_[i].end() && !insertPhase)
{
phaseInfo_[i].erase(item);
} else if (insertPhase)
{
phaseInfo_[i].insert(r);
}
}
// keep track (redundantly) of phases inside the Region also, for serialization
r->setPhases(phases);
resetEnabledPhases_();
}