PR c++/83634
[official-gcc.git] / gcc / hash-map-traits.h
blobcb38ccbf0875e00f93c4d85a8ec2d0ee827b9019
1 /* A hash map traits.
2 Copyright (C) 2015-2018 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 const bool maybe_mx = true;
36 static inline hashval_t hash (const key_type &);
37 static inline bool equal_keys (const key_type &, const key_type &);
38 template <typename T> static inline void remove (T &);
39 template <typename T> static inline bool is_empty (const T &);
40 template <typename T> static inline bool is_deleted (const T &);
41 template <typename T> static inline void mark_empty (T &);
42 template <typename T> static inline void mark_deleted (T &);
45 template <typename H, typename Value>
46 inline hashval_t
47 simple_hashmap_traits <H, Value>::hash (const key_type &h)
49 return H::hash (h);
52 template <typename H, typename Value>
53 inline bool
54 simple_hashmap_traits <H, Value>::equal_keys (const key_type &k1,
55 const key_type &k2)
57 return H::equal (k1, k2);
60 template <typename H, typename Value>
61 template <typename T>
62 inline void
63 simple_hashmap_traits <H, Value>::remove (T &entry)
65 H::remove (entry.m_key);
66 entry.m_value.~Value ();
69 template <typename H, typename Value>
70 template <typename T>
71 inline bool
72 simple_hashmap_traits <H, Value>::is_empty (const T &entry)
74 return H::is_empty (entry.m_key);
77 template <typename H, typename Value>
78 template <typename T>
79 inline bool
80 simple_hashmap_traits <H, Value>::is_deleted (const T &entry)
82 return H::is_deleted (entry.m_key);
85 template <typename H, typename Value>
86 template <typename T>
87 inline void
88 simple_hashmap_traits <H, Value>::mark_empty (T &entry)
90 H::mark_empty (entry.m_key);
93 template <typename H, typename Value>
94 template <typename T>
95 inline void
96 simple_hashmap_traits <H, Value>::mark_deleted (T &entry)
98 H::mark_deleted (entry.m_key);
101 template <typename H, typename Value>
102 struct simple_cache_map_traits: public simple_hashmap_traits<H,Value>
104 static const bool maybe_mx = false;
107 /* Implement traits for a hash_map with values of type Value for cases
108 in which the key cannot represent empty and deleted slots. Instead
109 record empty and deleted entries in Value. Derived classes must
110 implement the hash and equal_keys functions. */
112 template <typename Value>
113 struct unbounded_hashmap_traits
115 template <typename T> static inline void remove (T &);
116 template <typename T> static inline bool is_empty (const T &);
117 template <typename T> static inline bool is_deleted (const T &);
118 template <typename T> static inline void mark_empty (T &);
119 template <typename T> static inline void mark_deleted (T &);
122 template <typename Value>
123 template <typename T>
124 inline void
125 unbounded_hashmap_traits <Value>::remove (T &entry)
127 default_hash_traits <Value>::remove (entry.m_value);
130 template <typename Value>
131 template <typename T>
132 inline bool
133 unbounded_hashmap_traits <Value>::is_empty (const T &entry)
135 return default_hash_traits <Value>::is_empty (entry.m_value);
138 template <typename Value>
139 template <typename T>
140 inline bool
141 unbounded_hashmap_traits <Value>::is_deleted (const T &entry)
143 return default_hash_traits <Value>::is_deleted (entry.m_value);
146 template <typename Value>
147 template <typename T>
148 inline void
149 unbounded_hashmap_traits <Value>::mark_empty (T &entry)
151 default_hash_traits <Value>::mark_empty (entry.m_value);
154 template <typename Value>
155 template <typename T>
156 inline void
157 unbounded_hashmap_traits <Value>::mark_deleted (T &entry)
159 default_hash_traits <Value>::mark_deleted (entry.m_value);
162 /* Implement traits for a hash_map from integer type Key to Value in
163 cases where Key has no spare values for recording empty and deleted
164 slots. */
166 template <typename Key, typename Value>
167 struct unbounded_int_hashmap_traits : unbounded_hashmap_traits <Value>
169 typedef Key key_type;
170 static inline hashval_t hash (Key);
171 static inline bool equal_keys (Key, Key);
174 template <typename Key, typename Value>
175 inline hashval_t
176 unbounded_int_hashmap_traits <Key, Value>::hash (Key k)
178 return k;
181 template <typename Key, typename Value>
182 inline bool
183 unbounded_int_hashmap_traits <Key, Value>::equal_keys (Key k1, Key k2)
185 return k1 == k2;
188 #endif // HASH_MAP_TRAITS_H