Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a problem which requires data to be stored in memory for users. The structure contains user_name and phone_number and I have to store it for say 1 million users. Now while retrieving if user_name is given as input then it should return the phone_number and if phone_number is given as input then it should return the user_name. What will be the appropriate data structure to implement this when I need optimized complexity while retrieving in terms of speed and storage.
try boost::bimap.
It's a bidirectional map (everything is a key and also a value).
Boost.Bimap
I think it's implemented with two maps though so note the memory usage.
Try leveldb, where you can store data in the form of key & value pairs.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to make a function that has one parameter (a string that contains the name of a variable in my program) and returns the value that the variable stores.
Unfortunately, C++ doesn't provide a simple mechanism for reflection (the idea that the program can, at runtime, look up variable names by value or the like). You may need to consider using an alternate approach.
For example, you could make a std::unordered_map whose keys represent certain values that you'd like to look up and whose values are populated with the items you'd like to look up.
Hope this helps!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Hi I need to type a code which calls the key and its values such as "Tokyo 10 23 32". I can't use arrays or vectors how can I store my data? Thanks.
Use std::map or std::unordered_map. std::map uses a Red-Black tree, and std::unordered_map uses a Hash Table.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am looking for a data structure which can store values with index and also can be resized like a std::vector (but should be indexed so I can access it easily) is there any C++ standard library implementation of my problem?
What I am looking for is an array-type DS from which I can remove elements.
You can use std::deque which is also indexed sequence container like std::vector. It provids also std::deque::resize member function.
However, your requirement should be much more specific to suggest std::deque at first place than std::vector
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i need some help in deciding which data structure i should use. i'm going to create a patient information system of a hospital just like a simple student information system.
i have studied Arrays, Linked Lists, Trees, Stacks, Queues and Graphs. i think it would be too simple with Array. should i use linked list?
how will i store all the fields into it? a Linked list stores one item of data at the moment, no? my requirements are to add information, search them by their ID and be able to delete through ID as well.
any ideas? thanks
my requirements are to add information, search them by their ID and be able to delete through ID as well.
Seems like an std::map<id, patient> would suit your needs via:
operator[] to add a record
at/find for retrieval
erase for removal
If you need more complex queries I'd recommend a full-fledged relational database.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Should a thread-safe mechanism be added when a class is developed and it is known that this class will be used in multi-threaded environment (not always however) or leave it to the user?
As a general rule, it's more flexible to leave it to the user. For example, consider a map-type container. Suppose the application needs to atomically move something from one map to another map. In this case, the user needs to lock both maps before the insert-erase sequence.
Having such a scenario be automatically taken care of somehow by your class would probably be inelegant, because it's naturally something that happens across objects, and because there may be many such scenarios, each slightly different.