Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8046145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:43:06+00:00 2026-06-05T05:43:06+00:00

Efficiency of the map::insert(iterator position, const value& k) can be dramatically improved by providing

  • 0

Efficiency of the map::insert(iterator position, const value& k) can be dramatically improved by providing the appropriate value in parameter position.

If I use integer numbers as the key, and every insertion is done with a number larger than all previously inserted keys, can I speed up the ::insert operation when giving the ::end() iterator of the map?

Something like:

myMap.insert( myMap.end() , make_pair( next_number , myValue ) );

where myMap is of type map<uint64_t,MyType> and next_number is an every incrementing large integer.

Edit:

The answer to this question might differ depending on whether the data stored in the map is dense or not (see discussion below). So, lets ask the question in both ways: Once it’s dense once it’s not. Still curious. Perhaps measuring will answer it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:43:07+00:00Added an answer on June 5, 2026 at 5:43 am

    To directly answer the question asked, the C++ specs say that:

    • In C++03, insertion into a map with a.insert(p,t) must be amortized constant complexity (rather than logarithmic) if t is inserted right after p.
    • In C++11, insertion into a map with a.insert(p,t) must be amortized constant complexity if t is inserted right before p.

    and in neither case does p need to be dereferenceable. Therefore, in your case, a.end() is likely to be the best hint in C++11, but not in C++03.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just found std::map.insert could accept an iterator as its first parameter as a
I am confused which is more efficient? As we can access map directly, why
In terms of performance and efficiency, is it better to use lots of small
How can I use BOOST_FOREACH efficiently (number-of-character/readability-wise) with a boost::ptr_map? Kristo demonstrated in his
I've got a value type that I want put into a map. It has
I have a map (for example, of character to integer). I insert values into
Here is some working code: std::pair<typename std::map< time_t, T >::iterator, bool> ret; ret =
How efficient is the find() function on the std::map class? Does it iterate through
Is there a fast/efficiency way to check if a table is empty? DECLARE @StartEndTimes
I'm interested in the worst-case efficiency of stepping forwards and backwards through binary search

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.