Fix type in the changelog entry,
[official-gcc.git] / gcc / hash-map-traits.h
blob2225426e365caac7832c4dd79ae15485ed292954
1 /* A hash map traits.
2 Copyright (C) 2015 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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/>. */
20 #ifndef HASH_MAP_TRAITS_H
21 #define HASH_MAP_TRAITS_H
23 /* Bacause mem-stats.h uses default hashmap traits, we have to
24 put the class to this separate header file. */
26 #include "hash-traits.h"
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. */
31 template <typename H>
32 struct simple_hashmap_traits
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 &);
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 &);
44 template <typename H>
45 inline hashval_t
46 simple_hashmap_traits <H>::hash (const key_type &h)
48 return H::hash (h);
51 template <typename H>
52 inline bool
53 simple_hashmap_traits <H>::equal_keys (const key_type &k1, const key_type &k2)
55 return H::equal (k1, k2);
58 template <typename H>
59 template <typename T>
60 inline void
61 simple_hashmap_traits <H>::remove (T &entry)
63 H::remove (entry.m_key);
66 template <typename H>
67 template <typename T>
68 inline bool
69 simple_hashmap_traits <H>::is_empty (const T &entry)
71 return H::is_empty (entry.m_key);
74 template <typename H>
75 template <typename T>
76 inline bool
77 simple_hashmap_traits <H>::is_deleted (const T &entry)
79 return H::is_deleted (entry.m_key);
82 template <typename H>
83 template <typename T>
84 inline void
85 simple_hashmap_traits <H>::mark_empty (T &entry)
87 H::mark_empty (entry.m_key);
90 template <typename H>
91 template <typename T>
92 inline void
93 simple_hashmap_traits <H>::mark_deleted (T &entry)
95 H::mark_deleted (entry.m_key);
98 /* Implement traits for a hash_map with values of type Value for cases
99 in which the key cannot represent empty and deleted slots. Instead
100 record empty and deleted entries in Value. Derived classes must
101 implement the hash and equal_keys functions. */
103 template <typename Value>
104 struct unbounded_hashmap_traits
106 template <typename T> static inline void remove (T &);
107 template <typename T> static inline bool is_empty (const T &);
108 template <typename T> static inline bool is_deleted (const T &);
109 template <typename T> static inline void mark_empty (T &);
110 template <typename T> static inline void mark_deleted (T &);
113 template <typename Value>
114 template <typename T>
115 inline void
116 unbounded_hashmap_traits <Value>::remove (T &entry)
118 default_hash_traits <Value>::remove (entry.m_value);
121 template <typename Value>
122 template <typename T>
123 inline bool
124 unbounded_hashmap_traits <Value>::is_empty (const T &entry)
126 return default_hash_traits <Value>::is_empty (entry.m_value);
129 template <typename Value>
130 template <typename T>
131 inline bool
132 unbounded_hashmap_traits <Value>::is_deleted (const T &entry)
134 return default_hash_traits <Value>::is_deleted (entry.m_value);
137 template <typename Value>
138 template <typename T>
139 inline void
140 unbounded_hashmap_traits <Value>::mark_empty (T &entry)
142 default_hash_traits <Value>::mark_empty (entry.m_value);
145 template <typename Value>
146 template <typename T>
147 inline void
148 unbounded_hashmap_traits <Value>::mark_deleted (T &entry)
150 default_hash_traits <Value>::mark_deleted (entry.m_value);
153 /* Implement traits for a hash_map from integer type Key to Value in
154 cases where Key has no spare values for recording empty and deleted
155 slots. */
157 template <typename Key, typename Value>
158 struct unbounded_int_hashmap_traits : unbounded_hashmap_traits <Value>
160 typedef Key key_type;
161 static inline hashval_t hash (Key);
162 static inline bool equal_keys (Key, Key);
165 template <typename Key, typename Value>
166 inline hashval_t
167 unbounded_int_hashmap_traits <Key, Value>::hash (Key k)
169 return k;
172 template <typename Key, typename Value>
173 inline bool
174 unbounded_int_hashmap_traits <Key, Value>::equal_keys (Key k1, Key k2)
176 return k1 == k2;
179 #endif // HASH_MAP_TRAITS_H