Skip to content

Commit 344a2c4

Browse files
committed
Add support for std::unordered_{map,set} to memusage.h
1 parent 27faa6c commit 344a2c4

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/memusage.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <map>
1313
#include <set>
1414
#include <vector>
15+
#include <unordered_map>
16+
#include <unordered_set>
1517

1618
#include <boost/foreach.hpp>
1719
#include <boost/unordered_set.hpp>
@@ -149,7 +151,7 @@ static inline size_t DynamicUsage(const std::shared_ptr<X>& p)
149151
// Boost data structures
150152

151153
template<typename X>
152-
struct boost_unordered_node : private X
154+
struct unordered_node : private X
153155
{
154156
private:
155157
void* ptr;
@@ -158,13 +160,25 @@ struct boost_unordered_node : private X
158160
template<typename X, typename Y>
159161
static inline size_t DynamicUsage(const boost::unordered_set<X, Y>& s)
160162
{
161-
return MallocUsage(sizeof(boost_unordered_node<X>)) * s.size() + MallocUsage(sizeof(void*) * s.bucket_count());
163+
return MallocUsage(sizeof(unordered_node<X>)) * s.size() + MallocUsage(sizeof(void*) * s.bucket_count());
162164
}
163165

164166
template<typename X, typename Y, typename Z>
165167
static inline size_t DynamicUsage(const boost::unordered_map<X, Y, Z>& m)
166168
{
167-
return MallocUsage(sizeof(boost_unordered_node<std::pair<const X, Y> >)) * m.size() + MallocUsage(sizeof(void*) * m.bucket_count());
169+
return MallocUsage(sizeof(unordered_node<std::pair<const X, Y> >)) * m.size() + MallocUsage(sizeof(void*) * m.bucket_count());
170+
}
171+
172+
template<typename X, typename Y>
173+
static inline size_t DynamicUsage(const std::unordered_set<X, Y>& s)
174+
{
175+
return MallocUsage(sizeof(unordered_node<X>)) * s.size() + MallocUsage(sizeof(void*) * s.bucket_count());
176+
}
177+
178+
template<typename X, typename Y, typename Z>
179+
static inline size_t DynamicUsage(const std::unordered_map<X, Y, Z>& m)
180+
{
181+
return MallocUsage(sizeof(unordered_node<std::pair<const X, Y> >)) * m.size() + MallocUsage(sizeof(void*) * m.bucket_count());
168182
}
169183

170184
}

0 commit comments

Comments
 (0)