TVM  0.9.4
map.h
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #include <functional>
6 #include <map>
7 #include <unordered_map>
8 
9 namespace tvm::utils::internal
10 {
11 template<typename ObjWithId>
12 class IdLess
13 {
14 public:
15  using T = typename std::decay<typename std::remove_pointer<ObjWithId>::type>::type;
16  constexpr bool operator()(const T * const lhs, const T * const rhs) const
17  { return lhs && rhs && lhs->id() < rhs->id(); }
18  constexpr bool operator()(const T & lhs, const T & rhs) const { return lhs.id() < rhs.id(); }
19 };
20 
21 template<typename ObjWithId>
22 class IdEqual
23 {
24 public:
25  using T = typename std::decay<typename std::remove_pointer<ObjWithId>::type>::type;
26  constexpr bool operator()(const T * const lhs, const T * const rhs) const
27  { return lhs && rhs && lhs->id() == rhs->id(); }
28  constexpr bool operator()(const T & lhs, const T & rhs) const { return lhs.id() == rhs.id(); }
29 };
30 
31 template<typename ObjWithId>
32 class HashId
33 {
34 public:
35  using T = typename std::decay<typename std::remove_pointer<ObjWithId>::type>::type;
36  std::size_t operator()(const T * key) const { return key ? std::hash<int>()(key->id()) : std::hash<int>()(-1); }
37  std::size_t operator()(const T & key) const { return std::hash<int>()(key.id()); }
38 };
39 
40 template<typename KeyWithId, typename Value, typename Allocator = std::allocator<std::pair<const KeyWithId, Value>>>
41 using map = std::map<KeyWithId, Value, IdLess<KeyWithId>, Allocator>;
42 
43 template<typename KeyWithId, typename Value, typename Allocator = std::allocator<std::pair<const KeyWithId, Value>>>
44 using unordered_map = std::unordered_map<KeyWithId, Value, HashId<KeyWithId>, IdEqual<KeyWithId>, Allocator>;
45 
46 } // namespace tvm::utils::internal
Definition: map.h:33
typename std::decay< typename std::remove_pointer< ObjWithId >::type >::type T
Definition: map.h:35
std::size_t operator()(const T &key) const
Definition: map.h:37
std::size_t operator()(const T *key) const
Definition: map.h:36
Definition: map.h:23
constexpr bool operator()(const T &lhs, const T &rhs) const
Definition: map.h:28
constexpr bool operator()(const T *const lhs, const T *const rhs) const
Definition: map.h:26
typename std::decay< typename std::remove_pointer< ObjWithId >::type >::type T
Definition: map.h:25
Definition: map.h:13
constexpr bool operator()(const T &lhs, const T &rhs) const
Definition: map.h:18
constexpr bool operator()(const T *const lhs, const T *const rhs) const
Definition: map.h:16
typename std::decay< typename std::remove_pointer< ObjWithId >::type >::type T
Definition: map.h:15
Definition: AffineExprDetail.h:15
std::unordered_map< KeyWithId, Value, HashId< KeyWithId >, IdEqual< KeyWithId >, Allocator > unordered_map
Definition: map.h:44
std::map< KeyWithId, Value, IdLess< KeyWithId >, Allocator > map
Definition: map.h:41