]>
Commit | Line | Data |
---|---|---|
0ff42de5 | 1 | /* A hash map traits. |
f1717362 | 2 | Copyright (C) 2015-2016 Free Software Foundation, Inc. |
0ff42de5 | 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 | ||
b837d192 | 26 | #include "hash-traits.h" |
27 | ||
b837d192 | 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 | ||
76854650 | 31 | template <typename H, typename Value> |
b837d192 | 32 | struct simple_hashmap_traits |
33 | { | |
ee34b0e4 | 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 &); | |
b837d192 | 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 &); | |
42 | }; | |
43 | ||
76854650 | 44 | template <typename H, typename Value> |
b837d192 | 45 | inline hashval_t |
76854650 | 46 | simple_hashmap_traits <H, Value>::hash (const key_type &h) |
b837d192 | 47 | { |
48 | return H::hash (h); | |
49 | } | |
50 | ||
76854650 | 51 | template <typename H, typename Value> |
b837d192 | 52 | inline bool |
76854650 | 53 | simple_hashmap_traits <H, Value>::equal_keys (const key_type &k1, |
54 | const key_type &k2) | |
b837d192 | 55 | { |
56 | return H::equal (k1, k2); | |
57 | } | |
58 | ||
76854650 | 59 | template <typename H, typename Value> |
b837d192 | 60 | template <typename T> |
61 | inline void | |
76854650 | 62 | simple_hashmap_traits <H, Value>::remove (T &entry) |
b837d192 | 63 | { |
64 | H::remove (entry.m_key); | |
76854650 | 65 | entry.m_value.~Value (); |
b837d192 | 66 | } |
67 | ||
76854650 | 68 | template <typename H, typename Value> |
b837d192 | 69 | template <typename T> |
70 | inline bool | |
76854650 | 71 | simple_hashmap_traits <H, Value>::is_empty (const T &entry) |
b837d192 | 72 | { |
73 | return H::is_empty (entry.m_key); | |
74 | } | |
75 | ||
76854650 | 76 | template <typename H, typename Value> |
b837d192 | 77 | template <typename T> |
78 | inline bool | |
76854650 | 79 | simple_hashmap_traits <H, Value>::is_deleted (const T &entry) |
b837d192 | 80 | { |
81 | return H::is_deleted (entry.m_key); | |
82 | } | |
83 | ||
76854650 | 84 | template <typename H, typename Value> |
b837d192 | 85 | template <typename T> |
86 | inline void | |
76854650 | 87 | simple_hashmap_traits <H, Value>::mark_empty (T &entry) |
b837d192 | 88 | { |
89 | H::mark_empty (entry.m_key); | |
90 | } | |
91 | ||
76854650 | 92 | template <typename H, typename Value> |
b837d192 | 93 | template <typename T> |
94 | inline void | |
76854650 | 95 | simple_hashmap_traits <H, Value>::mark_deleted (T &entry) |
b837d192 | 96 | { |
97 | H::mark_deleted (entry.m_key); | |
98 | } | |
99 | ||
d5fb6135 | 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. */ | |
104 | ||
105 | template <typename Value> | |
106 | struct unbounded_hashmap_traits | |
107 | { | |
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 &); | |
113 | }; | |
114 | ||
115 | template <typename Value> | |
116 | template <typename T> | |
117 | inline void | |
118 | unbounded_hashmap_traits <Value>::remove (T &entry) | |
119 | { | |
120 | default_hash_traits <Value>::remove (entry.m_value); | |
121 | } | |
122 | ||
123 | template <typename Value> | |
124 | template <typename T> | |
125 | inline bool | |
126 | unbounded_hashmap_traits <Value>::is_empty (const T &entry) | |
127 | { | |
128 | return default_hash_traits <Value>::is_empty (entry.m_value); | |
129 | } | |
130 | ||
131 | template <typename Value> | |
132 | template <typename T> | |
133 | inline bool | |
134 | unbounded_hashmap_traits <Value>::is_deleted (const T &entry) | |
135 | { | |
136 | return default_hash_traits <Value>::is_deleted (entry.m_value); | |
137 | } | |
138 | ||
139 | template <typename Value> | |
140 | template <typename T> | |
141 | inline void | |
142 | unbounded_hashmap_traits <Value>::mark_empty (T &entry) | |
143 | { | |
144 | default_hash_traits <Value>::mark_empty (entry.m_value); | |
145 | } | |
146 | ||
147 | template <typename Value> | |
148 | template <typename T> | |
149 | inline void | |
150 | unbounded_hashmap_traits <Value>::mark_deleted (T &entry) | |
151 | { | |
152 | default_hash_traits <Value>::mark_deleted (entry.m_value); | |
153 | } | |
154 | ||
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. */ | |
158 | ||
159 | template <typename Key, typename Value> | |
160 | struct unbounded_int_hashmap_traits : unbounded_hashmap_traits <Value> | |
161 | { | |
ee34b0e4 | 162 | typedef Key key_type; |
d5fb6135 | 163 | static inline hashval_t hash (Key); |
164 | static inline bool equal_keys (Key, Key); | |
165 | }; | |
166 | ||
167 | template <typename Key, typename Value> | |
168 | inline hashval_t | |
169 | unbounded_int_hashmap_traits <Key, Value>::hash (Key k) | |
170 | { | |
171 | return k; | |
172 | } | |
173 | ||
174 | template <typename Key, typename Value> | |
175 | inline bool | |
176 | unbounded_int_hashmap_traits <Key, Value>::equal_keys (Key k1, Key k2) | |
177 | { | |
178 | return k1 == k2; | |
179 | } | |
180 | ||
0ff42de5 | 181 | #endif // HASH_MAP_TRAITS_H |