]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/hash-map-traits.h
Update copyright years.
[thirdparty/gcc.git] / gcc / hash-map-traits.h
CommitLineData
2d44c7de 1/* A hash map traits.
8d9254fc 2 Copyright (C) 2015-2020 Free Software Foundation, Inc.
2d44c7de
ML
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
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 31template <typename H, typename Value>
4ef7b52a
RS
32struct 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
RS
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 &);
43};
44
76b6ddbf 45template <typename H, typename Value>
4ef7b52a 46inline hashval_t
76b6ddbf 47simple_hashmap_traits <H, Value>::hash (const key_type &h)
4ef7b52a
RS
48{
49 return H::hash (h);
50}
51
76b6ddbf 52template <typename H, typename Value>
4ef7b52a 53inline bool
76b6ddbf
TS
54simple_hashmap_traits <H, Value>::equal_keys (const key_type &k1,
55 const key_type &k2)
4ef7b52a
RS
56{
57 return H::equal (k1, k2);
58}
59
76b6ddbf 60template <typename H, typename Value>
4ef7b52a
RS
61template <typename T>
62inline void
76b6ddbf 63simple_hashmap_traits <H, Value>::remove (T &entry)
4ef7b52a
RS
64{
65 H::remove (entry.m_key);
76b6ddbf 66 entry.m_value.~Value ();
4ef7b52a
RS
67}
68
76b6ddbf 69template <typename H, typename Value>
4ef7b52a
RS
70template <typename T>
71inline bool
76b6ddbf 72simple_hashmap_traits <H, Value>::is_empty (const T &entry)
4ef7b52a
RS
73{
74 return H::is_empty (entry.m_key);
75}
76
76b6ddbf 77template <typename H, typename Value>
4ef7b52a
RS
78template <typename T>
79inline bool
76b6ddbf 80simple_hashmap_traits <H, Value>::is_deleted (const T &entry)
4ef7b52a
RS
81{
82 return H::is_deleted (entry.m_key);
83}
84
76b6ddbf 85template <typename H, typename Value>
4ef7b52a
RS
86template <typename T>
87inline void
76b6ddbf 88simple_hashmap_traits <H, Value>::mark_empty (T &entry)
4ef7b52a
RS
89{
90 H::mark_empty (entry.m_key);
91}
92
76b6ddbf 93template <typename H, typename Value>
4ef7b52a
RS
94template <typename T>
95inline void
76b6ddbf 96simple_hashmap_traits <H, Value>::mark_deleted (T &entry)
4ef7b52a
RS
97{
98 H::mark_deleted (entry.m_key);
99}
100
21faa101
JM
101template <typename H, typename Value>
102struct simple_cache_map_traits: public simple_hashmap_traits<H,Value>
103{
104 static const bool maybe_mx = false;
105};
106
0ef08bc5
RS
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. */
111
112template <typename Value>
113struct unbounded_hashmap_traits
114{
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 &);
120};
121
122template <typename Value>
123template <typename T>
124inline void
125unbounded_hashmap_traits <Value>::remove (T &entry)
126{
127 default_hash_traits <Value>::remove (entry.m_value);
128}
129
130template <typename Value>
131template <typename T>
132inline bool
133unbounded_hashmap_traits <Value>::is_empty (const T &entry)
134{
135 return default_hash_traits <Value>::is_empty (entry.m_value);
136}
137
138template <typename Value>
139template <typename T>
140inline bool
141unbounded_hashmap_traits <Value>::is_deleted (const T &entry)
142{
143 return default_hash_traits <Value>::is_deleted (entry.m_value);
144}
145
146template <typename Value>
147template <typename T>
148inline void
149unbounded_hashmap_traits <Value>::mark_empty (T &entry)
150{
151 default_hash_traits <Value>::mark_empty (entry.m_value);
152}
153
154template <typename Value>
155template <typename T>
156inline void
157unbounded_hashmap_traits <Value>::mark_deleted (T &entry)
158{
159 default_hash_traits <Value>::mark_deleted (entry.m_value);
160}
161
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. */
165
166template <typename Key, typename Value>
167struct unbounded_int_hashmap_traits : unbounded_hashmap_traits <Value>
168{
fb5c464a 169 typedef Key key_type;
0ef08bc5
RS
170 static inline hashval_t hash (Key);
171 static inline bool equal_keys (Key, Key);
172};
173
174template <typename Key, typename Value>
175inline hashval_t
176unbounded_int_hashmap_traits <Key, Value>::hash (Key k)
177{
178 return k;
179}
180
181template <typename Key, typename Value>
182inline bool
183unbounded_int_hashmap_traits <Key, Value>::equal_keys (Key k1, Key k2)
184{
185 return k1 == k2;
186}
187
2d44c7de 188#endif // HASH_MAP_TRAITS_H