File indexing completed on 2026-05-10 08:44:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LLVM_PROFILEDATA_HASHKEYMAP_H
0016 #define LLVM_PROFILEDATA_HASHKEYMAP_H
0017
0018 #include "llvm/ADT/Hashing.h"
0019 #include <iterator>
0020 #include <utility>
0021
0022 namespace llvm {
0023
0024 namespace sampleprof {
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050 template <template <typename, typename, typename...> typename MapT,
0051 typename KeyT, typename ValueT, typename... MapTArgs>
0052 class HashKeyMap :
0053 public MapT<decltype(hash_value(KeyT())), ValueT, MapTArgs...> {
0054 public:
0055 using base_type = MapT<decltype(hash_value(KeyT())), ValueT, MapTArgs...>;
0056 using key_type = decltype(hash_value(KeyT()));
0057 using original_key_type = KeyT;
0058 using mapped_type = ValueT;
0059 using value_type = typename base_type::value_type;
0060
0061 using iterator = typename base_type::iterator;
0062 using const_iterator = typename base_type::const_iterator;
0063
0064 template <typename... Ts>
0065 std::pair<iterator, bool> try_emplace(const key_type &Hash,
0066 const original_key_type &Key,
0067 Ts &&...Args) {
0068 assert(Hash == hash_value(Key));
0069 return base_type::try_emplace(Hash, std::forward<Ts>(Args)...);
0070 }
0071
0072 template <typename... Ts>
0073 std::pair<iterator, bool> try_emplace(const original_key_type &Key,
0074 Ts &&...Args) {
0075 return try_emplace(hash_value(Key), Key, std::forward<Ts>(Args)...);
0076 }
0077
0078 template <typename... Ts> std::pair<iterator, bool> emplace(Ts &&...Args) {
0079 return try_emplace(std::forward<Ts>(Args)...);
0080 }
0081
0082 mapped_type &operator[](const original_key_type &Key) {
0083 return try_emplace(Key, mapped_type()).first->second;
0084 }
0085
0086 iterator find(const original_key_type &Key) {
0087 auto It = base_type::find(hash_value(Key));
0088 if (It != base_type::end())
0089 return It;
0090 return base_type::end();
0091 }
0092
0093 const_iterator find(const original_key_type &Key) const {
0094 auto It = base_type::find(hash_value(Key));
0095 if (It != base_type::end())
0096 return It;
0097 return base_type::end();
0098 }
0099
0100 mapped_type lookup(const original_key_type &Key) const {
0101 auto It = base_type::find(hash_value(Key));
0102 if (It != base_type::end())
0103 return It->second;
0104 return mapped_type();
0105 }
0106
0107 size_t count(const original_key_type &Key) const {
0108 return base_type::count(hash_value(Key));
0109 }
0110
0111 size_t erase(const original_key_type &Ctx) {
0112 auto It = find(Ctx);
0113 if (It != base_type::end()) {
0114 base_type::erase(It);
0115 return 1;
0116 }
0117 return 0;
0118 }
0119
0120 iterator erase(const_iterator It) {
0121 return base_type::erase(It);
0122 }
0123 };
0124
0125 }
0126
0127 }
0128
0129 #endif