M
ma740988
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.
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.