PR rtl-optimization/82913
[official-gcc.git] / gcc / hash-map-traits.h
blob2b5fddf2d095f070ee0ac97c3be0716dd07d2f4b
1 /* A hash map traits.
2 Copyright (C) 2015-2017 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef HASH_MAP_TRAITS_H
21 #define HASH_MAP_TRAITS_H
23 /* Bacause mem-stats.h uses default hashmap traits, we have to
24 put the class to this separate header file. */
26 #include "hash-traits.h"
28 /* Implement hash_map traits for a key with hash traits H. Empty and
29 deleted map entries are represented as empty and deleted keys. */
31 template <typename H, typename Value>
32 struct simple_hashmap_traits
34 typedef typename H::value_type key_type;
35 static inline hashval_t hash (const key_type &);
36 static inline bool equal_keys (const key_type &, const key_type &);
37 template <typename T> static inline void remove (T &);
38 template <typename T> static inline bool is_empty (const T &);
39 template <typename T> static inline bool is_deleted (const T &);
40 template <typename T> static inline void mark_empty (T &);
41 template <typename T> static inline void mark_deleted (T &);
44 template <typename H, typename Value>
45 inline hashval_t
46 simple_hashmap_traits <H, Value>::hash (const key_type &h)
48 return H::hash (h);
51 template <typename H, typename Value>
52 inline bool
53 simple_hashmap_traits <H, Value>::equal_keys (const key_type &k1,
54 const key_type &k2)
56 return H::equal (k1, k2);
59 template <typename H, typename Value>
60 template <typename T>
61 inline void
62 simple_hashmap_traits <H, Value>::remove (T &entry)
64 H::remove (entry.m_key);
65 entry.m_value.~Value ();
68 template <typename H, typename Value>
69 template <typename T>
70 inline bool
71 simple_hashmap_traits <H, Value>::is_empty (const T &entry)
73 return H::is_empty (entry.m_key);
76 template <typename H, typename Value>
77 template <typename T>
78 inline bool
79 simple_hashmap_traits <H, Value>::is_deleted (const T &entry)
81 return H::is_deleted (entry.m_key);
84 template <typename H, typename Value>
85 template <typename T>
86 inline void
87 simple_hashmap_traits <H, Value>::mark_empty (T &entry)
89 H::mark_empty (entry.m_key);
92 template <typename H, typename Value>
93 template <typename T>
94 inline void
95 simple_hashmap_traits <H, Value>::mark_deleted (T &entry)
97 H::mark_deleted (entry.m_key);
100 /* Implement traits for a hash_map with values of type Value for cases
101 in which the key cannot represent empty and deleted slots. Instead
102 record empty and deleted entries in Value. Derived classes must
103 implement the hash and equal_keys functions. */
105 template <typename Value>
106 struct unbounded_hashmap_traits
108 template <typename T> static inline void remove (T &);
109 template <typename T> static inline bool is_empty (const T &);
110 template <typename T> static inline bool is_deleted (const T &);
111 template <typename T> static inline void mark_empty (T &);
112 template <typename T> static inline void mark_deleted (T &);
115 template <typename Value>
116 template <typename T>
117 inline void
118 unbounded_hashmap_traits <Value>::remove (T &entry)
120 default_hash_traits <Value>::remove (entry.m_value);
123 template <typename Value>
124 template <typename T>
125 inline bool
126 unbounded_hashmap_traits <Value>::is_empty (const T &entry)
128 return default_hash_traits <Value>::is_empty (entry.m_value);
131 template <typename Value>
132 template <typename T>
133 inline bool
134 unbounded_hashmap_traits <Value>::is_deleted (const T &entry)
136 return default_hash_traits <Value>::is_deleted (entry.m_value);
139 template <typename Value>
140 template <typename T>
141 inline void
142 unbounded_hashmap_traits <Value>::mark_empty (T &entry)
144 default_hash_traits <Value>::mark_empty (entry.m_value);
147 template <typename Value>
148 template <typename T>
149 inline void
150 unbounded_hashmap_traits <Value>::mark_deleted (T &entry)
152 default_hash_traits <Value>::mark_deleted (entry.m_value);
155 /* Implement traits for a hash_map from integer type Key to Value in
156 cases where Key has no spare values for recording empty and deleted
157 slots. */
159 template <typename Key, typename Value>
160 struct unbounded_int_hashmap_traits : unbounded_hashmap_traits <Value>
162 typedef Key key_type;
163 static inline hashval_t hash (Key);
164 static inline bool equal_keys (Key, Key);
167 template <typename Key, typename Value>
168 inline hashval_t
169 unbounded_int_hashmap_traits <Key, Value>::hash (Key k)
171 return k;
174 template <typename Key, typename Value>
175 inline bool
176 unbounded_int_hashmap_traits <Key, Value>::equal_keys (Key k1, Key k2)
178 return k1 == k2;
181 #endif // HASH_MAP_TRAITS_H