Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Existence map in C++

Tags:

c++

map

stl

I want something like an std::map, but I only want to see if the item exists or not, I don't actually need a key AND a value. What should I use?

like image 510
Net Citizen Avatar asked Nov 26 '22 23:11

Net Citizen


2 Answers

Looks like you need a std::set.

like image 151
Alexander Kojevnikov Avatar answered Dec 25 '22 07:12

Alexander Kojevnikov


If you want the same type of behavior as std::map, then you want std::set.

If you are mixing insert/delete and query operations, then std::set is probably the best choice. However, if you can populate the set first and then follow it with the queries, it might be worth looking at using std::vector, sorting it, and then using a binary search to check for existence in the vector.

like image 26
David Dibben Avatar answered Dec 25 '22 07:12

David Dibben