]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
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). | |
7c673cae FG |
5 | |
6 | #pragma once | |
7 | ||
8 | #include <unordered_map> | |
9 | ||
10 | namespace rocksdb { | |
11 | ||
12 | // Helper methods to estimate memroy usage by std containers. | |
13 | ||
14 | template <class Key, class Value, class Hash> | |
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 |