In article <85f819a0-6c66-4f13-8e22-eb11d431b773
@c58g2000hsc.googlegroups.com>,
says...
[ ... ]
> for example i am doing the operation as below in my program
> whenever i receive a packet or something ...i will check does it
> contain in my vector list....
> so if I contain around 2 million entreis in my vector and i received
> around 100 packets...
> then the computation would be 100 packets * 2 million iterations...
>
> as my list goes on incresing I will have more iterations..
> this is the problem i am facing with my simulation..
[ and elsethread: ]
> as i said...if my checking element matches one of the element in my
> vector list then i will collect the statistics...
> if it doesnt matches any one of the vector elements then i will move
> this checking elment to a new vector...
Okay, from the sound of things, the issue is really with searches, not
with the iterators per se. From your description, you're currently using
a linear search, which is pretty slow, as you've pointed out. A binary
search should be much faster (logarithmic instead of linear complexity).
An std::set or std::map will use a binary search, but that does NOT
necessarily mean it's the best structure to use. I'm not _entirely_ sure
I follow what you're saying, but it _sounds_ like the searches are being
done in a fixed set of items -- i.e. you're _not_ (for example) adding
are removing items from that set during a single run.
If that's correct, then you're probably better off continuing to use a
vector, but sorting it and using binary_search or upper_bound (or
possibly lower_bound) to search it.
Given the number of items you're dealing with, you might also want to
try using an unordered_set instead -- this uses a hash map, so its speed
is normally nearly constant regardless of the number of items being
searched.
--
Later,
Jerry.
The universe is a figment of its own imagination.