]> 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
0ff42de5 1/* A hash map traits.
f1717362 2 Copyright (C) 2015-2016 Free Software Foundation, Inc.
0ff42de5 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
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 31template <typename H, typename Value>
b837d192 32struct 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 44template <typename H, typename Value>
b837d192 45inline hashval_t
76854650 46simple_hashmap_traits <H, Value>::hash (const key_type &h)
b837d192 47{
48 return H::hash (h);
49}
50
76854650 51template <typename H, typename Value>
b837d192 52inline bool
76854650 53simple_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 59template <typename H, typename Value>
b837d192 60template <typename T>
61inline void
76854650 62simple_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 68template <typename H, typename Value>
b837d192 69template <typename T>
70inline bool
76854650 71simple_hashmap_traits <H, Value>::is_empty (const T &entry)
b837d192 72{
73 return H::is_empty (entry.m_key);
74}
75
76854650 76template <typename H, typename Value>
b837d192 77template <typename T>
78inline bool
76854650 79simple_hashmap_traits <H, Value>::is_deleted (const T &entry)
b837d192 80{
81 return H::is_deleted (entry.m_key);
82}
83
76854650 84template <typename H, typename Value>
b837d192 85template <typename T>
86inline void
76854650 87simple_hashmap_traits <H, Value>::mark_empty (T &entry)
b837d192 88{
89 H::mark_empty (entry.m_key);
90}
91
76854650 92template <typename H, typename Value>
b837d192 93template <typename T>
94inline void
76854650 95simple_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
105template <typename Value>
106struct 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
115template <typename Value>
116template <typename T>
117inline void
118unbounded_hashmap_traits <Value>::remove (T &entry)
119{
120 default_hash_traits <Value>::remove (entry.m_value);
121}
122
123template <typename Value>
124template <typename T>
125inline bool
126unbounded_hashmap_traits <Value>::is_empty (const T &entry)
127{
128 return default_hash_traits <Value>::is_empty (entry.m_value);
129}
130
131template <typename Value>
132template <typename T>
133inline bool
134unbounded_hashmap_traits <Value>::is_deleted (const T &entry)
135{
136 return default_hash_traits <Value>::is_deleted (entry.m_value);
137}
138
139template <typename Value>
140template <typename T>
141inline void
142unbounded_hashmap_traits <Value>::mark_empty (T &entry)
143{
144 default_hash_traits <Value>::mark_empty (entry.m_value);
145}
146
147template <typename Value>
148template <typename T>
149inline void
150unbounded_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
159template <typename Key, typename Value>
160struct 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
167template <typename Key, typename Value>
168inline hashval_t
169unbounded_int_hashmap_traits <Key, Value>::hash (Key k)
170{
171 return k;
172}
173
174template <typename Key, typename Value>
175inline bool
176unbounded_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