Basmah
Basmah

Reputation: 899

Data structure for One column list for storing addresses , better lookup O(1) in C++

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

Answers (2)

Joost Sannen
Joost Sannen

Reputation: 215

You are looking for boost::unordered_map.

Upvotes: 0

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

Related Questions