Home

ma740988 wrote:
> For discussion purposes, assume the vector ivec contains 67108864 (67
> million elements) elements. Lets futher assume nstart and end equal
> 1008000 and 11088000 respectively.
>
> The question. What's the _fastest_ way to erase element numbers less
> than 1008000 and element numbers greater than 11088000. Current
> approach.
>
> typedef std::vector < int > INT_VEC ;
>
> int main () {
>
> int dummy( 0 ) ;
> for ( INT_VEC::iterator it = ivec.begin(); it != ivec.end(); ) {
> if ( dummy < nstart || dummy > end ) {
> it = ivec.erase ( it ) ;
> } else {
> ++ it ;
> }
> ++ dummy ;
> }
>
> }
>
> This is 'dog' slow. That said, I thinking it would be ideal if i
> copied elements into a separate vector.

Extract the numbers you want to keep into the separate vector:

std::vector<int> tokeep(&ivec[1008000], &ivec[11088000 + 1]);


and clear 'ivec':

std::vector<int>().swap(ivec);

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

previous
next

Re: How do you debug?
Re: Iterator implementation questions: copy constructor and postfix increment
Re: any g++ compilation warning to detect empty if statement
Re: How to Modify Console output AFTER it has gone to cout
Re: getopt with negative numbers?
paraprotex opinie
tkaniny dekoracyjne
bwin.com
artykuły biurowe
download