I have a set of elements in std :: vector that are sorted in descending order starting from the first element. I have to use a vector because I need to have elements in a continuous piece of memory. And I have a collection containing many instances of vectors with the described characteristics (always sorted in descending order).
Now, sometimes, when I find that I have too many elements in a larger collection (the one that stores these vectors), I drop the smallest elements from these vectors in some way similar to this pseudocode:
grand_collection: collection that holds these vectors
T: type argument of my vector
C: the type that is a member of T, that participates in the < comparison (this is what sorts data before they hit any of the vectors).
std::map<C, std::pair<T::const_reverse_iterator, std::vector<T>&>> what_to_delete;
iterate(it = grand_collection.begin() -> grand_collection.end())
{
iterate(vect_rit = it->rbegin() -> it->rend())
{
what_to_delete <- (vect_rit->C, pair(vect_rit, *it))
if (what_to_delete.size() > threshold)
what_to_delete.erase(what_to_delete.begin());
}
}
, , what_to_delete , , ( ). , , , , what_to_delete[0 - n] , n - m , n, m > 0.
_ . ++ 11 §24.4.1/1:
_ & * (reverse_iterator (i)) == & * (i-1)
, a vect_rit :
vector.erase(--vect_rit.base());
, ++ 11 §23.3.6.5/3:
( ); : Invalidates .
reverse_iterators? (vector[0]) vect_rit , ? reverse_iterator rbegin() ( vector[vector.size()]) -, 0-, ?
Edit:
, reverse_iterator rbegin() . , , , . ( const_iterator) what_to_delete .
, , , _ ? ?
!