aboutsummaryrefslogtreecommitdiff
path: root/src/limitedmap.h
diff options
context:
space:
mode:
authorCasey Rodarmor <casey@rodarmor.com>2015-08-17 12:06:45 -0400
committerCasey Rodarmor <casey@rodarmor.com>2015-08-17 12:15:32 -0400
commit8b0689419470b5c3458142c055f80721c857b121 (patch)
tree2a1ae44e72a234f07f0f12f9f9c981a76aada220 /src/limitedmap.h
parentfd2d862fbc4d13129bfa3702a9241d9ea46ddae5 (diff)
Disallow unlimited limited maps
Diffstat (limited to 'src/limitedmap.h')
-rw-r--r--src/limitedmap.h19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/limitedmap.h b/src/limitedmap.h
index b990eab3ee..5456dfc7c4 100644
--- a/src/limitedmap.h
+++ b/src/limitedmap.h
@@ -27,7 +27,11 @@ protected:
size_type nMaxSize;
public:
- limitedmap(size_type nMaxSizeIn = 0) { nMaxSize = nMaxSizeIn; }
+ limitedmap(size_type nMaxSizeIn)
+ {
+ assert(nMaxSizeIn > 0);
+ nMaxSize = nMaxSizeIn;
+ }
const_iterator begin() const { return map.begin(); }
const_iterator end() const { return map.end(); }
size_type size() const { return map.size(); }
@@ -38,13 +42,12 @@ public:
{
std::pair<iterator, bool> ret = map.insert(x);
if (ret.second) {
- if (nMaxSize && map.size() > nMaxSize) {
+ if (map.size() > nMaxSize) {
map.erase(rmap.begin()->second);
rmap.erase(rmap.begin());
}
rmap.insert(make_pair(x.second, ret.first));
}
- return;
}
void erase(const key_type& k)
{
@@ -81,11 +84,11 @@ public:
size_type max_size() const { return nMaxSize; }
size_type max_size(size_type s)
{
- if (s)
- while (map.size() > s) {
- map.erase(rmap.begin()->second);
- rmap.erase(rmap.begin());
- }
+ assert(s > 0);
+ while (map.size() > s) {
+ map.erase(rmap.begin()->second);
+ rmap.erase(rmap.begin());
+ }
nMaxSize = s;
return nMaxSize;
}