6 #ifndef PIVX_LIMITEDMAP_H
7 #define PIVX_LIMITEDMAP_H
13 template <
typename K,
typename V>
19 typedef std::pair<const key_type, mapped_type>
value_type;
21 typedef typename std::map<K, V>::size_type
size_type;
25 typedef typename std::map<K, V>::iterator
iterator;
26 std::multimap<V, iterator>
rmap;
40 std::pair<iterator, bool> ret =
map.insert(x);
43 map.erase(
rmap.begin()->second);
46 rmap.insert(std::make_pair(x.second, ret.first));
53 if (itTarget ==
map.end())
55 std::pair<rmap_iterator, rmap_iterator> itPair =
rmap.equal_range(itTarget->second);
56 for (
rmap_iterator it = itPair.first; it != itPair.second; ++it)
57 if (it->second == itTarget) {
69 if (itTarget ==
map.end())
71 std::pair<rmap_iterator, rmap_iterator> itPair =
rmap.equal_range(itTarget->second);
72 for (
rmap_iterator it = itPair.first; it != itPair.second; ++it)
73 if (it->second == itTarget) {
76 rmap.insert(std::make_pair(v, itTarget));
86 while (
map.size() > s) {
87 map.erase(
rmap.begin()->second);
STL-like map container that only keeps the N elements with the highest value.
const_iterator begin() const
std::map< K, V >::size_type size_type
size_type max_size() const
const_iterator end() const
limitedmap(size_type nMaxSizeIn=0)
std::pair< const key_type, mapped_type > value_type
size_type max_size(size_type s)
void erase(const key_type &k)
std::map< K, V >::const_iterator const_iterator
std::multimap< V, iterator > rmap
const_iterator find(const key_type &k) const
std::multimap< V, iterator >::iterator rmap_iterator
size_type count(const key_type &k) const
std::map< K, V >::iterator iterator
void update(const_iterator itIn, const mapped_type &v)
void insert(const value_type &x)