]>
Commit | Line | Data |
---|---|---|
2d44c7de | 1 | /* A hash map traits. |
8d9254fc | 2 | Copyright (C) 2015-2020 Free Software Foundation, Inc. |
2d44c7de ML |
3 | |
4 | This file is part of GCC. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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/>. */ | |
19 | ||
20 | #ifndef HASH_MAP_TRAITS_H | |
21 | #define HASH_MAP_TRAITS_H | |
22 | ||
23 | /* Bacause mem-stats.h uses default hashmap traits, we have to | |
24 | put the class to this separate header file. */ | |
25 | ||
4ef7b52a RS |
26 | #include "hash-traits.h" |
27 | ||
4ef7b52a RS |
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. */ | |
30 | ||
76b6ddbf | 31 | template <typename H, typename Value> |
4ef7b52a RS |
32 | struct simple_hashmap_traits |
33 | { | |
fb5c464a | 34 | typedef typename H::value_type key_type; |
21faa101 | 35 | static const bool maybe_mx = true; |
fb5c464a RS |
36 | static inline hashval_t hash (const key_type &); |
37 | static inline bool equal_keys (const key_type &, const key_type &); | |
4ef7b52a | 38 | template <typename T> static inline void remove (T &); |
7ca50de0 | 39 | static const bool empty_zero_p = H::empty_zero_p; |
4ef7b52a RS |
40 | template <typename T> static inline bool is_empty (const T &); |
41 | template <typename T> static inline bool is_deleted (const T &); | |
42 | template <typename T> static inline void mark_empty (T &); | |
43 | template <typename T> static inline void mark_deleted (T &); | |
44 | }; | |
45 | ||
76b6ddbf | 46 | template <typename H, typename Value> |
4ef7b52a | 47 | inline hashval_t |
76b6ddbf | 48 | simple_hashmap_traits <H, Value>::hash (const key_type &h) |
4ef7b52a RS |
49 | { |
50 | return H::hash (h); | |
51 | } | |
52 | ||
76b6ddbf | 53 | template <typename H, typename Value> |
4ef7b52a | 54 | inline bool |
76b6ddbf TS |
55 | simple_hashmap_traits <H, Value>::equal_keys (const key_type &k1, |
56 | const key_type &k2) | |
4ef7b52a RS |
57 | { |
58 | return H::equal (k1, k2); | |
59 | } | |
60 | ||
76b6ddbf | 61 | template <typename H, typename Value> |
4ef7b52a RS |
62 | template <typename T> |
63 | inline void | |
76b6ddbf | 64 | simple_hashmap_traits <H, Value>::remove (T &entry) |
4ef7b52a RS |
65 | { |
66 | H::remove (entry.m_key); | |
76b6ddbf | 67 | entry.m_value.~Value (); |
4ef7b52a RS |
68 | } |
69 | ||
76b6ddbf | 70 | template <typename H, typename Value> |
4ef7b52a RS |
71 | template <typename T> |
72 | inline bool | |
76b6ddbf | 73 | simple_hashmap_traits <H, Value>::is_empty (const T &entry) |
4ef7b52a RS |
74 | { |
75 | return H::is_empty (entry.m_key); | |
76 | } | |
77 | ||
76b6ddbf | 78 | template <typename H, typename Value> |
4ef7b52a RS |
79 | template <typename T> |
80 | inline bool | |
76b6ddbf | 81 | simple_hashmap_traits <H, Value>::is_deleted (const T &entry) |
4ef7b52a RS |
82 | { |
83 | return H::is_deleted (entry.m_key); | |
84 | } | |
85 | ||
76b6ddbf | 86 | template <typename H, typename Value> |
4ef7b52a RS |
87 | template <typename T> |
88 | inline void | |
76b6ddbf | 89 | simple_hashmap_traits <H, Value>::mark_empty (T &entry) |
4ef7b52a RS |
90 | { |
91 | H::mark_empty (entry.m_key); | |
92 | } | |
93 | ||
76b6ddbf | 94 | template <typename H, typename Value> |
4ef7b52a RS |
95 | template <typename T> |
96 | inline void | |
76b6ddbf | 97 | simple_hashmap_traits <H, Value>::mark_deleted (T &entry) |
4ef7b52a RS |
98 | { |
99 | H::mark_deleted (entry.m_key); | |
100 | } | |
101 | ||
21faa101 JM |
102 | template <typename H, typename Value> |
103 | struct simple_cache_map_traits: public simple_hashmap_traits<H,Value> | |
104 | { | |
105 | static const bool maybe_mx = false; | |
106 | }; | |
107 | ||
0ef08bc5 RS |
108 | /* Implement traits for a hash_map with values of type Value for cases |
109 | in which the key cannot represent empty and deleted slots. Instead | |
110 | record empty and deleted entries in Value. Derived classes must | |
111 | implement the hash and equal_keys functions. */ | |
112 | ||
113 | template <typename Value> | |
114 | struct unbounded_hashmap_traits | |
115 | { | |
116 | template <typename T> static inline void remove (T &); | |
7ca50de0 | 117 | static const bool empty_zero_p = default_hash_traits <Value>::empty_zero_p; |
0ef08bc5 RS |
118 | template <typename T> static inline bool is_empty (const T &); |
119 | template <typename T> static inline bool is_deleted (const T &); | |
120 | template <typename T> static inline void mark_empty (T &); | |
121 | template <typename T> static inline void mark_deleted (T &); | |
122 | }; | |
123 | ||
124 | template <typename Value> | |
125 | template <typename T> | |
126 | inline void | |
127 | unbounded_hashmap_traits <Value>::remove (T &entry) | |
128 | { | |
129 | default_hash_traits <Value>::remove (entry.m_value); | |
130 | } | |
131 | ||
132 | template <typename Value> | |
133 | template <typename T> | |
134 | inline bool | |
135 | unbounded_hashmap_traits <Value>::is_empty (const T &entry) | |
136 | { | |
137 | return default_hash_traits <Value>::is_empty (entry.m_value); | |
138 | } | |
139 | ||
140 | template <typename Value> | |
141 | template <typename T> | |
142 | inline bool | |
143 | unbounded_hashmap_traits <Value>::is_deleted (const T &entry) | |
144 | { | |
145 | return default_hash_traits <Value>::is_deleted (entry.m_value); | |
146 | } | |
147 | ||
148 | template <typename Value> | |
149 | template <typename T> | |
150 | inline void | |
151 | unbounded_hashmap_traits <Value>::mark_empty (T &entry) | |
152 | { | |
153 | default_hash_traits <Value>::mark_empty (entry.m_value); | |
154 | } | |
155 | ||
156 | template <typename Value> | |
157 | template <typename T> | |
158 | inline void | |
159 | unbounded_hashmap_traits <Value>::mark_deleted (T &entry) | |
160 | { | |
161 | default_hash_traits <Value>::mark_deleted (entry.m_value); | |
162 | } | |
163 | ||
164 | /* Implement traits for a hash_map from integer type Key to Value in | |
165 | cases where Key has no spare values for recording empty and deleted | |
166 | slots. */ | |
167 | ||
168 | template <typename Key, typename Value> | |
169 | struct unbounded_int_hashmap_traits : unbounded_hashmap_traits <Value> | |
170 | { | |
fb5c464a | 171 | typedef Key key_type; |
0ef08bc5 RS |
172 | static inline hashval_t hash (Key); |
173 | static inline bool equal_keys (Key, Key); | |
174 | }; | |
175 | ||
176 | template <typename Key, typename Value> | |
177 | inline hashval_t | |
178 | unbounded_int_hashmap_traits <Key, Value>::hash (Key k) | |
179 | { | |
180 | return k; | |
181 | } | |
182 | ||
183 | template <typename Key, typename Value> | |
184 | inline bool | |
185 | unbounded_int_hashmap_traits <Key, Value>::equal_keys (Key k1, Key k2) | |
186 | { | |
187 | return k1 == k2; | |
188 | } | |
189 | ||
2d44c7de | 190 | #endif // HASH_MAP_TRAITS_H |