1 // 2 // Copyright 2024 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 // hash_containers.h: angle::HashMap and HashSet 8 9 #ifndef COMMON_HASH_CONTAINERS_H_ 10 #define COMMON_HASH_CONTAINERS_H_ 11 12 #if defined(ANGLE_USE_ABSEIL) 13 # include "absl/container/flat_hash_map.h" 14 # include "absl/container/flat_hash_set.h" 15 #else 16 # include <unordered_map> 17 # include <unordered_set> 18 #endif // defined(ANGLE_USE_ABSEIL) 19 20 namespace angle 21 { 22 23 #if defined(ANGLE_USE_ABSEIL) 24 template <typename Key, 25 typename T, 26 class Hash = absl::container_internal::hash_default_hash<Key>, 27 class Eq = absl::container_internal::hash_default_eq<Key>> 28 using HashMap = absl::flat_hash_map<Key, T, Hash, Eq>; 29 template <typename Key, 30 class Hash = absl::container_internal::hash_default_hash<Key>, 31 class Eq = absl::container_internal::hash_default_eq<Key>> 32 using HashSet = absl::flat_hash_set<Key, Hash, Eq>; 33 34 // Absl has generic lookup unconditionally 35 # define ANGLE_HAS_HASH_MAP_GENERIC_LOOKUP 1 36 #else 37 template <typename Key, 38 typename T, 39 class Hash = std::hash<Key>, 40 class KeyEqual = std::equal_to<Key>> 41 using HashMap = std::unordered_map<Key, T, Hash, KeyEqual>; 42 template <typename Key, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>> 43 using HashSet = std::unordered_set<Key, Hash, KeyEqual>; 44 # if __cpp_lib_generic_unordered_lookup >= 201811L 45 # define ANGLE_HAS_HASH_MAP_GENERIC_LOOKUP 1 46 # else 47 # define ANGLE_HAS_HASH_MAP_GENERIC_LOOKUP 0 48 # endif 49 #endif // defined(ANGLE_USE_ABSEIL) 50 51 } // namespace angle 52 53 #endif // COMMON_HASH_CONTAINERS_H_ 54