-// Copyright (c) 2012 The Bitcoin developers
-// Distributed under the MIT/X11 software license, see the accompanying
+// Copyright (c) 2012 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_MRUSET_H
#include <utility>
/** STL-like set container that only keeps the most recent N elements. */
-template <typename T> class mruset
+template <typename T>
+class mruset
{
public:
typedef T key_type;
bool empty() const { return set.empty(); }
iterator find(const key_type& k) const { return set.find(k); }
size_type count(const key_type& k) const { return set.count(k); }
- void clear() { set.clear(); queue.clear(); }
+ void clear()
+ {
+ set.clear();
+ queue.clear();
+ }
bool inline friend operator==(const mruset<T>& a, const mruset<T>& b) { return a.set == b.set; }
bool inline friend operator==(const mruset<T>& a, const std::set<T>& b) { return a.set == b; }
bool inline friend operator<(const mruset<T>& a, const mruset<T>& b) { return a.set < b.set; }
std::pair<iterator, bool> insert(const key_type& x)
{
std::pair<iterator, bool> ret = set.insert(x);
- if (ret.second)
- {
- if (nMaxSize && queue.size() == nMaxSize)
- {
+ if (ret.second) {
+ if (nMaxSize && queue.size() == nMaxSize) {
set.erase(queue.front());
queue.pop_front();
}
size_type max_size(size_type s)
{
if (s)
- while (queue.size() > s)
- {
+ while (queue.size() > s) {
set.erase(queue.front());
queue.pop_front();
}