5 #ifndef FABCOIN_LIMITEDMAP_H 6 #define FABCOIN_LIMITEDMAP_H 12 template <
typename K,
typename V>
18 typedef std::pair<const key_type, mapped_type>
value_type;
20 typedef typename std::map<K, V>::size_type
size_type;
24 typedef typename std::map<K, V>::iterator
iterator;
25 std::multimap<V, iterator>
rmap;
33 nMaxSize = nMaxSizeIn;
35 const_iterator
begin()
const {
return map.begin(); }
36 const_iterator
end()
const {
return map.end(); }
37 size_type
size()
const {
return map.size(); }
38 bool empty()
const {
return map.empty(); }
39 const_iterator
find(
const key_type& k)
const {
return map.find(k); }
40 size_type
count(
const key_type& k)
const {
return map.count(k); }
43 std::pair<iterator, bool> ret = map.insert(x);
46 map.erase(rmap.begin()->second);
47 rmap.erase(rmap.begin());
49 rmap.insert(make_pair(x.second, ret.first));
54 iterator itTarget = map.find(k);
55 if (itTarget == map.end())
57 std::pair<rmap_iterator, rmap_iterator> itPair = rmap.equal_range(itTarget->second);
58 for (rmap_iterator it = itPair.first; it != itPair.second; ++it)
59 if (it->second == itTarget) {
67 void update(const_iterator itIn,
const mapped_type& v)
72 iterator itTarget = map.erase(itIn, itIn);
74 if (itTarget == map.end())
76 std::pair<rmap_iterator, rmap_iterator> itPair = rmap.equal_range(itTarget->second);
77 for (rmap_iterator it = itPair.first; it != itPair.second; ++it)
78 if (it->second == itTarget) {
81 rmap.insert(make_pair(v, itTarget));
91 while (map.size() > s) {
92 map.erase(rmap.begin()->second);
93 rmap.erase(rmap.begin());
100 #endif // FABCOIN_LIMITEDMAP_H std::map< K, V >::const_iterator const_iterator
std::pair< const key_type, mapped_type > value_type
STL-like map container that only keeps the N elements with the highest value.
void insert(const value_type &x)
std::multimap< V, iterator > rmap
void update(const_iterator itIn, const mapped_type &v)
limitedmap(size_type nMaxSizeIn)
assert(len-trim+(2 *lenIndices)<=WIDTH)
std::multimap< V, iterator >::iterator rmap_iterator
size_type count(const key_type &k) const
const_iterator end() const
size_type max_size() const
void erase(const key_type &k)
const_iterator begin() const
size_type max_size(size_type s)
std::map< K, V >::iterator iterator
const_iterator find(const key_type &k) const
std::map< K, V >::size_type size_type