annotate gcc/hash-map-traits.h @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* A hash map traits.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2015-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
9 version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
14 for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #ifndef HASH_MAP_TRAITS_H
kono
parents:
diff changeset
21 #define HASH_MAP_TRAITS_H
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 /* Bacause mem-stats.h uses default hashmap traits, we have to
kono
parents:
diff changeset
24 put the class to this separate header file. */
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 #include "hash-traits.h"
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 /* Implement hash_map traits for a key with hash traits H. Empty and
kono
parents:
diff changeset
29 deleted map entries are represented as empty and deleted keys. */
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 template <typename H, typename Value>
kono
parents:
diff changeset
32 struct simple_hashmap_traits
kono
parents:
diff changeset
33 {
kono
parents:
diff changeset
34 typedef typename H::value_type key_type;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
35 static const bool maybe_mx = true;
111
kono
parents:
diff changeset
36 static inline hashval_t hash (const key_type &);
kono
parents:
diff changeset
37 static inline bool equal_keys (const key_type &, const key_type &);
kono
parents:
diff changeset
38 template <typename T> static inline void remove (T &);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
39 static const bool empty_zero_p = H::empty_zero_p;
111
kono
parents:
diff changeset
40 template <typename T> static inline bool is_empty (const T &);
kono
parents:
diff changeset
41 template <typename T> static inline bool is_deleted (const T &);
kono
parents:
diff changeset
42 template <typename T> static inline void mark_empty (T &);
kono
parents:
diff changeset
43 template <typename T> static inline void mark_deleted (T &);
kono
parents:
diff changeset
44 };
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 template <typename H, typename Value>
kono
parents:
diff changeset
47 inline hashval_t
kono
parents:
diff changeset
48 simple_hashmap_traits <H, Value>::hash (const key_type &h)
kono
parents:
diff changeset
49 {
kono
parents:
diff changeset
50 return H::hash (h);
kono
parents:
diff changeset
51 }
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 template <typename H, typename Value>
kono
parents:
diff changeset
54 inline bool
kono
parents:
diff changeset
55 simple_hashmap_traits <H, Value>::equal_keys (const key_type &k1,
kono
parents:
diff changeset
56 const key_type &k2)
kono
parents:
diff changeset
57 {
kono
parents:
diff changeset
58 return H::equal (k1, k2);
kono
parents:
diff changeset
59 }
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 template <typename H, typename Value>
kono
parents:
diff changeset
62 template <typename T>
kono
parents:
diff changeset
63 inline void
kono
parents:
diff changeset
64 simple_hashmap_traits <H, Value>::remove (T &entry)
kono
parents:
diff changeset
65 {
kono
parents:
diff changeset
66 H::remove (entry.m_key);
kono
parents:
diff changeset
67 entry.m_value.~Value ();
kono
parents:
diff changeset
68 }
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 template <typename H, typename Value>
kono
parents:
diff changeset
71 template <typename T>
kono
parents:
diff changeset
72 inline bool
kono
parents:
diff changeset
73 simple_hashmap_traits <H, Value>::is_empty (const T &entry)
kono
parents:
diff changeset
74 {
kono
parents:
diff changeset
75 return H::is_empty (entry.m_key);
kono
parents:
diff changeset
76 }
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 template <typename H, typename Value>
kono
parents:
diff changeset
79 template <typename T>
kono
parents:
diff changeset
80 inline bool
kono
parents:
diff changeset
81 simple_hashmap_traits <H, Value>::is_deleted (const T &entry)
kono
parents:
diff changeset
82 {
kono
parents:
diff changeset
83 return H::is_deleted (entry.m_key);
kono
parents:
diff changeset
84 }
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 template <typename H, typename Value>
kono
parents:
diff changeset
87 template <typename T>
kono
parents:
diff changeset
88 inline void
kono
parents:
diff changeset
89 simple_hashmap_traits <H, Value>::mark_empty (T &entry)
kono
parents:
diff changeset
90 {
kono
parents:
diff changeset
91 H::mark_empty (entry.m_key);
kono
parents:
diff changeset
92 }
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 template <typename H, typename Value>
kono
parents:
diff changeset
95 template <typename T>
kono
parents:
diff changeset
96 inline void
kono
parents:
diff changeset
97 simple_hashmap_traits <H, Value>::mark_deleted (T &entry)
kono
parents:
diff changeset
98 {
kono
parents:
diff changeset
99 H::mark_deleted (entry.m_key);
kono
parents:
diff changeset
100 }
kono
parents:
diff changeset
101
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
102 template <typename H, typename Value>
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
103 struct simple_cache_map_traits: public simple_hashmap_traits<H,Value>
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
104 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
105 static const bool maybe_mx = false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
106 };
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
107
111
kono
parents:
diff changeset
108 /* Implement traits for a hash_map with values of type Value for cases
kono
parents:
diff changeset
109 in which the key cannot represent empty and deleted slots. Instead
kono
parents:
diff changeset
110 record empty and deleted entries in Value. Derived classes must
kono
parents:
diff changeset
111 implement the hash and equal_keys functions. */
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 template <typename Value>
kono
parents:
diff changeset
114 struct unbounded_hashmap_traits
kono
parents:
diff changeset
115 {
kono
parents:
diff changeset
116 template <typename T> static inline void remove (T &);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
117 static const bool empty_zero_p = default_hash_traits <Value>::empty_zero_p;
111
kono
parents:
diff changeset
118 template <typename T> static inline bool is_empty (const T &);
kono
parents:
diff changeset
119 template <typename T> static inline bool is_deleted (const T &);
kono
parents:
diff changeset
120 template <typename T> static inline void mark_empty (T &);
kono
parents:
diff changeset
121 template <typename T> static inline void mark_deleted (T &);
kono
parents:
diff changeset
122 };
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 template <typename Value>
kono
parents:
diff changeset
125 template <typename T>
kono
parents:
diff changeset
126 inline void
kono
parents:
diff changeset
127 unbounded_hashmap_traits <Value>::remove (T &entry)
kono
parents:
diff changeset
128 {
kono
parents:
diff changeset
129 default_hash_traits <Value>::remove (entry.m_value);
kono
parents:
diff changeset
130 }
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 template <typename Value>
kono
parents:
diff changeset
133 template <typename T>
kono
parents:
diff changeset
134 inline bool
kono
parents:
diff changeset
135 unbounded_hashmap_traits <Value>::is_empty (const T &entry)
kono
parents:
diff changeset
136 {
kono
parents:
diff changeset
137 return default_hash_traits <Value>::is_empty (entry.m_value);
kono
parents:
diff changeset
138 }
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 template <typename Value>
kono
parents:
diff changeset
141 template <typename T>
kono
parents:
diff changeset
142 inline bool
kono
parents:
diff changeset
143 unbounded_hashmap_traits <Value>::is_deleted (const T &entry)
kono
parents:
diff changeset
144 {
kono
parents:
diff changeset
145 return default_hash_traits <Value>::is_deleted (entry.m_value);
kono
parents:
diff changeset
146 }
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 template <typename Value>
kono
parents:
diff changeset
149 template <typename T>
kono
parents:
diff changeset
150 inline void
kono
parents:
diff changeset
151 unbounded_hashmap_traits <Value>::mark_empty (T &entry)
kono
parents:
diff changeset
152 {
kono
parents:
diff changeset
153 default_hash_traits <Value>::mark_empty (entry.m_value);
kono
parents:
diff changeset
154 }
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 template <typename Value>
kono
parents:
diff changeset
157 template <typename T>
kono
parents:
diff changeset
158 inline void
kono
parents:
diff changeset
159 unbounded_hashmap_traits <Value>::mark_deleted (T &entry)
kono
parents:
diff changeset
160 {
kono
parents:
diff changeset
161 default_hash_traits <Value>::mark_deleted (entry.m_value);
kono
parents:
diff changeset
162 }
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 /* Implement traits for a hash_map from integer type Key to Value in
kono
parents:
diff changeset
165 cases where Key has no spare values for recording empty and deleted
kono
parents:
diff changeset
166 slots. */
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 template <typename Key, typename Value>
kono
parents:
diff changeset
169 struct unbounded_int_hashmap_traits : unbounded_hashmap_traits <Value>
kono
parents:
diff changeset
170 {
kono
parents:
diff changeset
171 typedef Key key_type;
kono
parents:
diff changeset
172 static inline hashval_t hash (Key);
kono
parents:
diff changeset
173 static inline bool equal_keys (Key, Key);
kono
parents:
diff changeset
174 };
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 template <typename Key, typename Value>
kono
parents:
diff changeset
177 inline hashval_t
kono
parents:
diff changeset
178 unbounded_int_hashmap_traits <Key, Value>::hash (Key k)
kono
parents:
diff changeset
179 {
kono
parents:
diff changeset
180 return k;
kono
parents:
diff changeset
181 }
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 template <typename Key, typename Value>
kono
parents:
diff changeset
184 inline bool
kono
parents:
diff changeset
185 unbounded_int_hashmap_traits <Key, Value>::equal_keys (Key k1, Key k2)
kono
parents:
diff changeset
186 {
kono
parents:
diff changeset
187 return k1 == k2;
kono
parents:
diff changeset
188 }
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 #endif // HASH_MAP_TRAITS_H