STL insert with hint

M

Mark P

Is an insert with hint (in say std::set) only beneficial if the
insertion occurs immediately before the pointed to location of the hint?
Suppose the insertion occurs right after the hint location? Or
suppose the insertion is near to the hint location but not adjacent? Is
there a performance penalty for an approximate hint, a partial gain, or
no gain?

Thanks,
Mark
 
B

Bart van Ingen Schenau

Mark said:
Is an insert with hint (in say std::set) only beneficial if the
insertion occurs immediately before the pointed to location of the
hint?

No, the hint is most beneficial if the insertion takes place immediately
_after_ the hint.
Suppose the insertion occurs right after the hint location? Or
suppose the insertion is near to the hint location but not adjacent?
Is there a performance penalty for an approximate hint, a partial
gain, or no gain?

It depends on the implementation of std::set<> on your system, but an
insertion with hint should not be less efficient than insertion without
a hint.
Depending on the implementation and how close the hint is to the actual
insertion point, insertion with a hint may or may not be noticeably
more efficient.
Thanks,
Mark

Bart v Ingen Schenau
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top