STL insert with hint

Discussion in 'C++' started by Mark P, Mar 25, 2005.

  1. Mark P

    Mark P Guest

    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
    Mark P, Mar 25, 2005
    #1
    1. Advertising

  2. Mark P wrote:

    > 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
    --
    a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
    c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html
    c.l.c++ FAQ: http://www.parashift.com/c -faq-lite/
    Bart van Ingen Schenau, Mar 26, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marek

    How to create a hint?

    Marek, Dec 27, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    1,539
    =?Utf-8?B?a2VybWl0?=
    Dec 27, 2004
  2. Replies:
    3
    Views:
    923
    Howard Hinnant
    Apr 20, 2005
  3. Mark P

    set, insert with hint

    Mark P, May 3, 2005, in forum: C++
    Replies:
    6
    Views:
    1,484
    Mark P
    May 4, 2005
  4. desktop
    Replies:
    6
    Views:
    607
    desktop
    Jun 13, 2007
  5. hurcan solter

    multimap insert behaviour with a hint

    hurcan solter, Feb 23, 2009, in forum: C++
    Replies:
    1
    Views:
    642
Loading...

Share This Page