Reputation: 899
I am a beginner in C++. I need to store list of addresses that give a very good performance in terms of lookup and adding new entries.
I first want to see if the address tis already present in the list, if yes , then don't write, else add new entry to that list.
And at the time of certain operation, look if the address is present in the list or not.
Is there any fast access and dynamic growing data structure in terms of memory and space in C++.
Upvotes: 0
Views: 176
Reputation: 1
I would suggest using std::map
(usually implemented as some red-black tree) which has a logarithmic complexity so should be enough in practice.
If you had a C++11 standard conforming implementation, you could consider std::unordered_map
(usually implemented as some hash-table).
If you don't need any associated data to keys, but just to handle sets of them, considuer std::set
or std::unordered_set
And many libraries (Boost, Qt, ...) also implement associative containers.
Upvotes: 1