Beispiel #1
0
  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);
  }
Beispiel #2
0
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;
      }
   }
}
Beispiel #3
0
void StructureDynArrayData::MoveDown( std::set< size_t >& selectedIndices )
{
    const Structure *structure = GetInternalStructure();
    size_t size = structure->m_DynArrayAdapter->GetSize(GetInternalPtr(structure));

    std::set< size_t > newSelectedIndices;

    std::set< size_t >::const_reverse_iterator itr = selectedIndices.rbegin();
    std::set< size_t >::const_reverse_iterator end = selectedIndices.rend();

    for( ; itr != end; ++itr )
    {
        if ( ( (*itr) == size - 1 ) || ( newSelectedIndices.find( (*itr) + 1 ) != newSelectedIndices.end() ) )
        {
            newSelectedIndices.insert( *itr );
            continue;
        }

        structure->m_DynArrayAdapter->Swap(GetInternalPtr(structure), *itr + 1, *itr);

        newSelectedIndices.insert( *itr + 1 );
    }

    selectedIndices = newSelectedIndices;
}
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);
	}
}
Beispiel #5
0
void output(int oo)
{
	if (oo != *pos.rbegin())
		printf("%d ", oo);
	else
		printf("%d", oo);
}
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;
}
Beispiel #7
0
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

}
Beispiel #8
0
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();
}
//--------------------------------------------------------------------------------------------------
/// 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();
}
Beispiel #10
0
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;
}
Beispiel #11
0
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;
	}
}
/** 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;
}
Beispiel #13
0
VectorBase<scalar,index,SizeAtCompileTime> VectorBase<scalar,index,SizeAtCompileTime>::block(const std::set<index>& indices) const
{
	if( *indices.rbegin() >= this->size() )
	{
		throw COException("Index out of range in Vector blocking!");
	}
	VectorBase<scalar,index,SizeAtCompileTime> result(indices.size());
	index i = 0;
	for ( const auto& s : indices ){
		result[i] = this->operator[](s);
		++ i;
	} 
	return result;
}
Beispiel #14
0
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();

}
Beispiel #15
0
void ThumbnailLoader::Enqueue( const std::set< Helium::Path >& files )
{
    Helium::Locker< Helium::OrderedSet< Helium::Path > >::Handle queue( m_FileQueue );

    for ( std::set< Helium::Path >::const_reverse_iterator itr = files.rbegin(), end = files.rend();
        itr != end;
        ++itr )
    {
        bool signal = !queue->Remove( *itr );
        queue->Prepend( *itr );
        if ( signal )
        {
            m_Signal.Increment();
        }
    }
}
Beispiel #16
0
/**
   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);
        }
    }
}
Beispiel #17
0
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();
}
Beispiel #18
0
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_();

}
Beispiel #19
0
void Document::moveLayers(const std::set<int>& layers, int newpos)
{
	int smaller = 0;
	for (std::set<int>::const_iterator iter = layers.begin(); iter != layers.end(); ++iter)
		if (*iter < newpos)
			smaller++;
	newpos -= smaller;

	std::vector<Layer*> v;
	for (std::set<int>::const_iterator iter = layers.begin(); iter != layers.end(); ++iter)
		v.push_back(layers_[*iter]);

	for (std::set<int>::const_reverse_iterator iter = layers.rbegin(); iter != layers.rend(); ++iter)
		layers_.erase(layers_.begin() + *iter);

	for (std::size_t i = 0; i < v.size(); ++i)
		layers_.insert(layers_.begin() + newpos, v[i]);
}
void f_set() {
  std::set<int> C;
  std::set<int>::iterator SetI1 = C.begin();
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when declaring iterators
  // CHECK-FIXES: auto SetI1 = C.begin();

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

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

  std::set<int>::const_reverse_iterator SetI4 = D.rbegin();
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when declaring iterators
  // CHECK-FIXES: auto SetI4 = D.rbegin();
}
Beispiel #21
0
bool is_cyclic(const std::set<int>& nodes,
               const std::map<int,std::set<int>>& edges) {

  // Check that graph is valid
  if (!is_closure(nodes, edges)) {
    std::stringstream err;
    err << __FILE__ << " " << __LINE__ << " :: " << "graph is not a closure";
    throw lbann_exception(err.str());
  }

  // Topologically sorted graphs are not cyclic
  if (is_topologically_sorted(nodes, edges)) {
    return false;
  }

  // Perform depth-first searches to detect cycles
  std::unordered_map<int,bool> is_visited, is_sorted;
  std::stack<int> search_stack;
  for (auto&& it = nodes.rbegin(); it != nodes.rend(); ++it) {
    search_stack.push(*it);
  }
  while (!search_stack.empty()) {
    const auto& node = search_stack.top();
    search_stack.pop();
    if (!is_sorted[node]) {
      if (is_visited[node]) {
        is_sorted[node] = true;
      } else {
        is_visited[node] = true;
        search_stack.push(node);
        for (const auto& neighbor : get_neighbors(node, edges)) {
          if (is_visited[neighbor] && !is_sorted[neighbor]) {
            return true;
          }
          search_stack.push(neighbor);
        }
      }
    }
  }
  return false;
  
}
std::set<IDBKeyData>::reverse_iterator MemoryObjectStoreCursor::firstReverseIteratorInRemainingRange(std::set<IDBKeyData>& set)
{
    if (m_remainingRange.isExactlyOneKey()) {
        auto iterator = set.find(m_remainingRange.lowerKey);
        if (iterator == set.end())
            return set.rend();

        return --std::set<IDBKeyData>::reverse_iterator(iterator);
    }

    if (!m_remainingRange.upperKey.isValid())
        return set.rbegin();

    // This is one record past the actual key we're looking for.
    auto highest = set.upper_bound(m_remainingRange.upperKey);

    // This is one record before that, which *is* the key we're looking for.
    auto reverse = std::set<IDBKeyData>::reverse_iterator(highest);
    if (reverse == set.rend())
        return reverse;

    if (m_remainingRange.upperOpen && *reverse == m_remainingRange.upperKey) {
        ++reverse;
        if (reverse == set.rend())
            return reverse;
    }

    if (!m_remainingRange.lowerKey.isNull()) {
        if (reverse->compare(m_remainingRange.lowerKey) < 0)
            return set.rend();

        if (m_remainingRange.lowerOpen && *reverse == m_remainingRange.lowerKey)
            return set.rend();
    }

    return reverse;
}
Beispiel #23
0
void SimpleStlVectorData<T>::MoveDown( std::set< size_t >& selectedIndices )
{
    std::set< size_t > newSelectedIndices;

    std::set< size_t >::const_reverse_iterator itr = selectedIndices.rbegin();
    std::set< size_t >::const_reverse_iterator end = selectedIndices.rend();

    for( ; itr != end; ++itr )
    {
        if ( ( (*itr) == m_Data->size() - 1 ) || ( newSelectedIndices.find( (*itr) + 1 ) != newSelectedIndices.end() ) )
        {
            newSelectedIndices.insert( *itr );
            continue;
        }
        
        T temp = m_Data->at( (*itr) + 1 );
        m_Data->at( (*itr) + 1 ) = m_Data->at( (*itr) );
        m_Data->at( (*itr) ) = temp;

        newSelectedIndices.insert( *itr + 1 );
    }

    selectedIndices = newSelectedIndices;
}
Beispiel #24
0
int main()
{
    {
        typedef int V;
        V ar[] =
        {
            1,
            1,
            1,
            2,
            2,
            2,
            3,
            3,
            3,
            4,
            4,
            4,
            5,
            5,
            5,
            6,
            6,
            6,
            7,
            7,
            7,
            8,
            8,
            8
        };
        std::set<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
        assert(std::distance(m.begin(), m.end()) == m.size());
        assert(std::distance(m.rbegin(), m.rend()) == m.size());
        std::set<int>::iterator i;
        i = m.begin();
        std::set<int>::const_iterator k = i;
        assert(i == k);
        for (int j = 1; j <= m.size(); ++j, ++i)
            assert(*i == j);
    }
    {
        typedef int V;
        V ar[] =
        {
            1,
            1,
            1,
            2,
            2,
            2,
            3,
            3,
            3,
            4,
            4,
            4,
            5,
            5,
            5,
            6,
            6,
            6,
            7,
            7,
            7,
            8,
            8,
            8
        };
        const std::set<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
        assert(std::distance(m.begin(), m.end()) == m.size());
        assert(std::distance(m.cbegin(), m.cend()) == m.size());
        assert(std::distance(m.rbegin(), m.rend()) == m.size());
        assert(std::distance(m.crbegin(), m.crend()) == m.size());
        std::set<int>::const_iterator i;
        i = m.begin();
        for (int j = 1; j <= m.size(); ++j, ++i)
            assert(*i == j);
    }
#if TEST_STD_VER >= 11
    {
        typedef int V;
        V ar[] =
        {
            1,
            1,
            1,
            2,
            2,
            2,
            3,
            3,
            3,
            4,
            4,
            4,
            5,
            5,
            5,
            6,
            6,
            6,
            7,
            7,
            7,
            8,
            8,
            8
        };
        std::set<int, std::less<int>, min_allocator<int>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
        assert(std::distance(m.begin(), m.end()) == m.size());
        assert(std::distance(m.rbegin(), m.rend()) == m.size());
        std::set<int, std::less<int>, min_allocator<int>>::iterator i;
        i = m.begin();
        std::set<int, std::less<int>, min_allocator<int>>::const_iterator k = i;
        assert(i == k);
        for (int j = 1; j <= m.size(); ++j, ++i)
            assert(*i == j);
    }
    {
        typedef int V;
        V ar[] =
        {
            1,
            1,
            1,
            2,
            2,
            2,
            3,
            3,
            3,
            4,
            4,
            4,
            5,
            5,
            5,
            6,
            6,
            6,
            7,
            7,
            7,
            8,
            8,
            8
        };
        const std::set<int, std::less<int>, min_allocator<int>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
        assert(std::distance(m.begin(), m.end()) == m.size());
        assert(std::distance(m.cbegin(), m.cend()) == m.size());
        assert(std::distance(m.rbegin(), m.rend()) == m.size());
        assert(std::distance(m.crbegin(), m.crend()) == m.size());
        std::set<int, std::less<int>, min_allocator<int>>::const_iterator i;
        i = m.begin();
        for (int j = 1; j <= m.size(); ++j, ++i)
            assert(*i == j);
    }
#endif
#if _LIBCPP_STD_VER > 11
    { // N3644 testing
        typedef std::set<int> C;
        C::iterator ii1{}, ii2{};
        C::iterator ii4 = ii1;
        C::const_iterator cii{};
        assert ( ii1 == ii2 );
        assert ( ii1 == ii4 );

        assert (!(ii1 != ii2 ));

        assert ( (ii1 == cii ));
        assert ( (cii == ii1 ));
        assert (!(ii1 != cii ));
        assert (!(cii != ii1 ));
    }
#endif
}