File onnxruntime-transparent-hash-in-unordered_map.patch of Package onnxruntime
diff --git a/include/onnxruntime/core/common/inlined_containers.h b/include/onnxruntime/core/common/inlined_containers.h
index 00bf2d19c1..ae246554cf 100644
--- a/include/onnxruntime/core/common/inlined_containers.h
+++ b/include/onnxruntime/core/common/inlined_containers.h
@@ -125,15 +125,15 @@ class InlinedHashSet : public std::unordered_set<T,
using Base::Base;
};
-template <typename Key, typename Value,
- typename Allocator>
+template <typename Key, typename Value, typename Hash,
+ typename Comparator, typename Allocator>
class InlinedHashMap : public std::unordered_map<Key, Value,
- std::hash<Key>,
- std::equal_to<Key>,
+ Hash,
+ Comparator,
Allocator> {
using Base = std::unordered_map<Key, Value,
- std::hash<Key>,
- std::equal_to<Key>,
+ Hash,
+ Comparator,
Allocator>;
public:
diff --git a/include/onnxruntime/core/common/inlined_containers_fwd.h b/include/onnxruntime/core/common/inlined_containers_fwd.h
index 4b150955ec..39e4f5d432 100644
--- a/include/onnxruntime/core/common/inlined_containers_fwd.h
+++ b/include/onnxruntime/core/common/inlined_containers_fwd.h
@@ -3,6 +3,7 @@
#pragma once
+#include <algorithm>
#include <memory>
#include <utility>
@@ -140,10 +141,29 @@ template <typename T,
typename Allocator = std::allocator<T>>
class InlinedHashSet;
-template <typename Key, typename Value,
+template <typename Key, typename Value, typename Hash = std::hash<Key>, typename Comparator = std::equal_to<Key>,
typename Allocator = std::allocator<std::pair<const Key, Value>>>
class InlinedHashMap;
+#ifdef DISABLE_ABSEIL
+// transparent hash
+struct string_view_compatible_hash {
+ using is_transparent = void;
+ [[nodiscard]] size_t operator()(const char *str) const {
+ return std::hash<std::string_view>{}(str);
+ }
+ [[nodiscard]] size_t operator()(std::string_view str) const {
+ return std::hash<std::string_view>{}(str);
+ }
+ [[nodiscard]] size_t operator()(const std::string &str) const {
+ return std::hash<std::string>{}(str);
+ }
+};
+// transparent comparator
+using InlinedStringHashMap = class InlinedHashMap <std::string, int, string_view_compatible_hash,
+ std::equal_to<>, std::allocator<std::pair<const std::string, int>>>;
+#endif
+
template <typename T, typename Allocator = std::allocator<T>>
class NodeHashSet;
diff --git a/onnxruntime/core/framework/ort_value_name_idx_map.h b/onnxruntime/core/framework/ort_value_name_idx_map.h
index 6035dc4e85..fa139c9736 100644
--- a/onnxruntime/core/framework/ort_value_name_idx_map.h
+++ b/onnxruntime/core/framework/ort_value_name_idx_map.h
@@ -13,7 +13,11 @@
namespace onnxruntime {
class OrtValueNameIdxMap {
public:
+#ifdef DISABLE_ABSEIL
+ using const_iterator = typename InlinedStringHashMap::const_iterator;
+#else
using const_iterator = typename InlinedHashMap<std::string, int>::const_iterator;
+#endif
OrtValueNameIdxMap() = default;
@@ -66,7 +70,11 @@ class OrtValueNameIdxMap {
ORT_DISALLOW_COPY_ASSIGNMENT_AND_MOVE(OrtValueNameIdxMap);
int next_idx_ = 0;
+#ifdef DISABLE_ABSEIL
+ InlinedStringHashMap map_;
+#else
InlinedHashMap<std::string, int> map_;
+#endif
InlinedHashMap<int, std::string> idx_name_map_;
};
} // namespace onnxruntime