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 8741631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:21:04+00:00 2026-06-13T11:21:04+00:00

A simple question, but the answer is not obvious to me: For performance reasons,

  • 0

A simple question, but the answer is not obvious to me: For performance reasons, which map-type (or maybe non map-type?) container should I, from a performance perspective, best use in the following scenario:

  • keys are unsigned integer numbers,
  • insertions are frequent,
  • read access is even more frequent and random access,
  • items are inserted with ascending key values (first inserted item has key 0, next one key 1 and so on),
  • items are removed randomly (so sooner or later the list of keys will have “holes”, as the corresponding items have been deleted). Removal is almost as frequent as insertion.

I hesitate to use std::map, as ascending key order and frequent removal seem to imply continuous re-balancing of the search tree, which to me seems to be a waste of performance.

In other words: Can I gain performance from the fact that I know in advance what the keys of the items will be and even the order in which the keys will appear for insertion? (I do not know the total number of items, though.)

  • 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-13T11:21:06+00:00Added an answer on June 13, 2026 at 11:21 am

    If you do use an stl::map — even if just for profiling to compare with a hash — you can use your knowledge that “items are inserted with ascending key values” to greatly increase the efficiency of the stl::map insertion operation by giving a hint to the insert call:

    iterator insert ( iterator position_hint, const value_type& x );
    

    … where the position_hint will be, for example, an iterator to the previous item inserted.

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

Sidebar

Related Questions

Simple question, but not obvious from the Mozilla JS docs. Anyone know the answer
I have a simple question but was not able to find an answer on
Its a simple question, but I'm not aware of the answer and I couldn't
I think this is a simple question, but I can not find the answer
I have read this question and the simple and clear answer but it's not
a simple question but Ive realised im not sure of the answer for this
This seems a simple question but I was not able to find the answer
One simple question (but I haven't quite found an obvious answer in the NLP
Simple question but cannot find answer anywhere. When using a MS Chart Control of
This may be a simple question but I can;t find the answer anywhere. Here

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.