1 //  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2 //  This source code is licensed under both the GPLv2 (found in the
3 //  COPYING file in the root directory) and Apache 2.0 License
4 //  (found in the LICENSE.Apache file in the root directory).
5 
6 #pragma once
7 
8 #include <unordered_map>
9 
10 namespace ROCKSDB_NAMESPACE {
11 
12 // Helper methods to estimate memroy usage by std containers.
13 
14 template <class Key, class Value, class Hash>
ApproximateMemoryUsage(const std::unordered_map<Key,Value,Hash> & umap)15 size_t ApproximateMemoryUsage(
16     const std::unordered_map<Key, Value, Hash>& umap) {
17   typedef std::unordered_map<Key, Value, Hash> Map;
18   return sizeof(umap) +
19          // Size of all items plus a next pointer for each item.
20          (sizeof(typename Map::value_type) + sizeof(void*)) * umap.size() +
21          // Size of hash buckets.
22          umap.bucket_count() * sizeof(void*);
23 }
24 
25 }  // namespace ROCKSDB_NAMESPACE
26