unordered-map

Remove Elements from an Unordered Map Fulfilling a Predicate

无人久伴 提交于 2020-11-26 07:00:30
问题 I want to remove elements (histogram bins) from an std::unordered_map (histogram) that fulfills a predictate (histogram bins having zero count) given as a lambda expression as follows std::remove_if(begin(m_map), end(m_map), [](const Bin & bin) { return bin.second == 0; }); but GCC-4.6.1 complains as follows /usr/include/c++/4.6/bits/stl_pair.h:156:2: error: assignment of read-only member ‘std::pair<const unsigned char, unsigned char>::first’ /usr/include/c++/4.6/bits/stl_pair.h: In member

Remove Elements from an Unordered Map Fulfilling a Predicate

独自空忆成欢 提交于 2020-11-26 07:00:29
问题 I want to remove elements (histogram bins) from an std::unordered_map (histogram) that fulfills a predictate (histogram bins having zero count) given as a lambda expression as follows std::remove_if(begin(m_map), end(m_map), [](const Bin & bin) { return bin.second == 0; }); but GCC-4.6.1 complains as follows /usr/include/c++/4.6/bits/stl_pair.h:156:2: error: assignment of read-only member ‘std::pair<const unsigned char, unsigned char>::first’ /usr/include/c++/4.6/bits/stl_pair.h: In member

How to change the key in an unordered_map?

…衆ロ難τιáo~ 提交于 2020-08-08 08:10:15
问题 I need to use a data structure which supports constant time lookups on average. I think that using a std::unordered_map is a good way to do it. My data is a "collection" of numbers. |115|190|380|265| These numbers do not have to be in a particular order. I need to have about O(1) time to determine whether or not a given number exists in this data structure. I have the idea of using a std::unordered_map , which is actually a hash table (am I correct?). So the numbers will be keys, and then I