File indexing completed on 2025-12-20 09:38:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 #ifndef ABSL_CONTAINER_INTERNAL_HASHTABLE_DEBUG_H_
0031 #define ABSL_CONTAINER_INTERNAL_HASHTABLE_DEBUG_H_
0032
0033 #include <cstddef>
0034 #include <algorithm>
0035 #include <type_traits>
0036 #include <vector>
0037
0038 #include "absl/container/internal/hashtable_debug_hooks.h"
0039
0040 namespace absl {
0041 ABSL_NAMESPACE_BEGIN
0042 namespace container_internal {
0043
0044
0045
0046
0047
0048 template <typename C>
0049 size_t GetHashtableDebugNumProbes(
0050 const C& c, const typename C::key_type& key) {
0051 return absl::container_internal::hashtable_debug_internal::
0052 HashtableDebugAccess<C>::GetNumProbes(c, key);
0053 }
0054
0055
0056
0057 template <typename C>
0058 std::vector<size_t> GetHashtableDebugNumProbesHistogram(const C& container) {
0059 std::vector<size_t> v;
0060 for (auto it = container.begin(); it != container.end(); ++it) {
0061 size_t num_probes = GetHashtableDebugNumProbes(
0062 container,
0063 absl::container_internal::hashtable_debug_internal::GetKey<C>(*it, 0));
0064 v.resize((std::max)(v.size(), num_probes + 1));
0065 v[num_probes]++;
0066 }
0067 return v;
0068 }
0069
0070 struct HashtableDebugProbeSummary {
0071 size_t total_elements;
0072 size_t total_num_probes;
0073 double mean;
0074 };
0075
0076
0077
0078 template <typename C>
0079 HashtableDebugProbeSummary GetHashtableDebugProbeSummary(const C& container) {
0080 auto probes = GetHashtableDebugNumProbesHistogram(container);
0081 HashtableDebugProbeSummary summary = {};
0082 for (size_t i = 0; i < probes.size(); ++i) {
0083 summary.total_elements += probes[i];
0084 summary.total_num_probes += probes[i] * i;
0085 }
0086 summary.mean = 1.0 * summary.total_num_probes / summary.total_elements;
0087 return summary;
0088 }
0089
0090
0091
0092 template <typename C>
0093 size_t AllocatedByteSize(const C& c) {
0094 return absl::container_internal::hashtable_debug_internal::
0095 HashtableDebugAccess<C>::AllocatedByteSize(c);
0096 }
0097
0098 }
0099 ABSL_NAMESPACE_END
0100 }
0101
0102 #endif