Re: STL: how to get the sequence number of a newly added item into a
set
On May 26, 8:04 am, Jerry Coffin <jcof...@taeus.com> wrote:
In article <g1di7e$8i...@aioe.org>, bilgek...@bilgekhanbilgekhan.net.tr
says...
[ ... ]
Yes, distance() does what I wanted, but it is VERY slow!
That's not terribly surprising.
It seems each time it walks all items from the beginning to the
item in question, ie. it practically does a find().
Yes, that's correct.
That's unfortunately too inefficient for my needs.
Isn't there a better (a direct) method without traversing the set ?
None of which I'm aware.
Perhaps the solution to his problem would be to use an
std::vector, and keep it sorted (using std::lower_bound to find
the insertion point). If insertions aren't too frequent, or
copying is fairly cheap, this can be even faster than an
std::set. And of course, given an iterator to an element, it's
trivial and very fast to find the elements sequence number.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34