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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:20:01+00:00 2026-06-03T00:20:01+00:00

I need a data structure in which I want to store information about which

  • 0

I need a data structure in which I want to store information about which instances I already processed during an action. Because of limitations I can’t store it in the instance itself (e.g. because I can execute the action in parallel.

What’s specific is that the instances for which I want to store information have a unique number, so instead of a pointer to the instance, I could use that unique number to store information.

My first solution was to use an std::set<Instance *>. Every time i process an instance, I add it to the set so that I know that I already processed that instance.

  • Advantage: this is very fast to initialize
  • Disadvantage: lookups are not O(1), but O(logN)

My second soluction was to use an std::vector<bool> (actually std::vector<byte> because bool vectors have a specific specialization which makes it slower than a non-bool vector). The unique number of the instance can be used as index into the vector, and in the vector simply contains true or false to indicate if we already processed the instance or not (luckily my unique numbers start to count from 1).

  • Advantage: lookups are O(1)
  • Disadvantage: initialization if relatively slow, since std::vector needs to initialize every element explicitly (and probably also independently)

I could also use a C-style array (on which I can use memset), but since the number of instances (or the number of unique numbers) is not known beforehand, I need to write my own code to extend the array, memset the rest of the array, … (which is not very hard, but which is something I want to avoid).

Is there any other kind of data structure that is very fast to initialize, and has O(1) lookup time?

  • 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-03T00:20:03+00:00Added an answer on June 3, 2026 at 12:20 am

    Well, with such a simple identification method… I would use a hash table.

    Can you not use boost::unordered_map or std::unordered_map ?

    Of course, you might prefer more sophisticated implementations if you want guaranteed O(1) insertion instead of amortized O(1) insertion, but it should get you started.

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

Sidebar

Related Questions

I am beginner in C++, I need to know which data structure to store
I need to store a tree data structure in my database, for which I
I need a data structure which will support the following operations in a performant
I am planning to work in TRIE data structure for which I need a
I need to have data structure, each element in which is accessible by pair
I need an efficient data structure to store a list of integers. The amount
I need a data structure to store a number of integer values associated with
I have in my homework some question about data structure: I have elements which
Is there an R data structure into which I can store a number of
I need a data structure that acts like a SortedDictionary<int, double> but is sorted

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.