GCC Middle and Back End API Reference
hash-map-traits.h
Go to the documentation of this file.
1/* A hash map traits.
2 Copyright (C) 2015-2024 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along 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
26#include "hash-traits.h"
27
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
31template <typename H, typename Value>
33{
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 static const bool empty_zero_p = H::empty_zero_p;
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
46template <typename H, typename Value>
47inline hashval_t
49{
50 return H::hash (h);
51}
52
53template <typename H, typename Value>
54inline bool
56 const key_type &k2)
57{
58 return H::equal (k1, k2);
59}
60
61template <typename H, typename Value>
62template <typename T>
63inline void
65{
66 H::remove (entry.m_key);
67 entry.m_value.~Value ();
68}
69
70template <typename H, typename Value>
71template <typename T>
72inline bool
74{
75 return H::is_empty (entry.m_key);
76}
77
78template <typename H, typename Value>
79template <typename T>
80inline bool
82{
83 return H::is_deleted (entry.m_key);
84}
85
86template <typename H, typename Value>
87template <typename T>
88inline void
90{
91 H::mark_empty (entry.m_key);
92}
93
94template <typename H, typename Value>
95template <typename T>
96inline void
98{
99 H::mark_deleted (entry.m_key);
100}
101
102template <typename H, typename Value>
104{
105 static const bool maybe_mx = false;
106};
107
108/* Implement traits for a hash_map with keys of type Key and values of
109 type Value for cases in which the key cannot represent empty and
110 deleted slots. Instead record empty and deleted entries in Value. */
111
112template <typename Key, typename Value>
114{
115 typedef typename Key::value_type key_type;
116
117 static hashval_t hash (const typename Key::value_type &);
118 static bool equal_keys (const typename Key::value_type &,
119 const typename Key::compare_type &);
120
121 template <typename T> static inline void remove (T &);
122 static const bool empty_zero_p = default_hash_traits <Value>::empty_zero_p;
123 template <typename T> static inline bool is_empty (const T &);
124 template <typename T> static inline bool is_deleted (const T &);
125 template <typename T> static inline void mark_empty (T &);
126 template <typename T> static inline void mark_deleted (T &);
127};
128
129template <typename Key, typename Value>
130inline hashval_t
132::hash (const typename Key::value_type &key)
133{
134 return Key::hash (key);
135}
136
137template <typename Key, typename Value>
138inline bool
140::equal_keys (const typename Key::value_type &x,
141 const typename Key::compare_type &y)
142{
143 return Key::equal (x, y);
144}
145
146template <typename Key, typename Value>
147template <typename T>
148inline void
150{
151 default_hash_traits <Value>::remove (entry.m_value);
152}
153
154template <typename Key, typename Value>
155template <typename T>
156inline bool
158{
159 return default_hash_traits <Value>::is_empty (entry.m_value);
160}
161
162template <typename Key, typename Value>
163template <typename T>
164inline bool
166{
167 return default_hash_traits <Value>::is_deleted (entry.m_value);
168}
169
170template <typename Key, typename Value>
171template <typename T>
172inline void
174{
175 default_hash_traits <Value>::mark_empty (entry.m_value);
176}
177
178template <typename Key, typename Value>
179template <typename T>
180inline void
182{
183 default_hash_traits <Value>::mark_deleted (entry.m_value);
184}
185
186/* Implement traits for a hash_map from integer type Key to Value in
187 cases where Key has no spare values for recording empty and deleted
188 slots. */
189
190template <typename Key, typename Value>
193
194#endif // HASH_MAP_TRAITS_H
T * ggc_alloc(ALONE_CXX_MEM_STAT_INFO)
Definition ggc.h:184
Definition hash-map-traits.h:104
static const bool maybe_mx
Definition hash-map-traits.h:105
Definition hash-map-traits.h:33
static const bool maybe_mx
Definition hash-map-traits.h:35
static bool is_empty(const T &)
Definition hash-map-traits.h:73
static void remove(T &)
Definition hash-map-traits.h:64
H::value_type key_type
Definition hash-map-traits.h:34
static void mark_deleted(T &)
Definition hash-map-traits.h:97
static const bool empty_zero_p
Definition hash-map-traits.h:39
static void mark_empty(T &)
Definition hash-map-traits.h:89
static bool is_deleted(const T &)
Definition hash-map-traits.h:81
static bool equal_keys(const key_type &, const key_type &)
Definition hash-map-traits.h:55
static hashval_t hash(const key_type &)
Definition hash-map-traits.h:48
Definition hash-map-traits.h:114
static bool is_empty(const T &)
Definition hash-map-traits.h:157
static const bool empty_zero_p
Definition hash-map-traits.h:122
static void mark_empty(T &)
Definition hash-map-traits.h:173
static bool is_deleted(const T &)
Definition hash-map-traits.h:165
static bool equal_keys(const typename Key::value_type &, const typename Key::compare_type &)
Definition hash-map-traits.h:140
Key::value_type key_type
Definition hash-map-traits.h:115
static hashval_t hash(const typename Key::value_type &)
Definition hash-map-traits.h:132
static void remove(T &)
Definition hash-map-traits.h:149
static void mark_deleted(T &)
Definition hash-map-traits.h:181
const T2 & y
Definition wide-int.h:3870