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
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
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. */
32 struct simple_hashmap_traits
34 static inline hashval_t
hash (const typename
H::value_type
&);
35 static inline bool equal_keys (const typename
H::value_type
&,
36 const typename
H::value_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
&);
46 simple_hashmap_traits
<H
>::hash (const typename
H::value_type
&h
)
53 simple_hashmap_traits
<H
>::equal_keys (const typename
H::value_type
&k1
,
54 const typename
H::value_type
&k2
)
56 return H::equal (k1
, k2
);
62 simple_hashmap_traits
<H
>::remove (T
&entry
)
64 H::remove (entry
.m_key
);
70 simple_hashmap_traits
<H
>::is_empty (const T
&entry
)
72 return H::is_empty (entry
.m_key
);
78 simple_hashmap_traits
<H
>::is_deleted (const T
&entry
)
80 return H::is_deleted (entry
.m_key
);
86 simple_hashmap_traits
<H
>::mark_empty (T
&entry
)
88 H::mark_empty (entry
.m_key
);
94 simple_hashmap_traits
<H
>::mark_deleted (T
&entry
)
96 H::mark_deleted (entry
.m_key
);
99 /* Implement traits for a hash_map with values of type Value for cases
100 in which the key cannot represent empty and deleted slots. Instead
101 record empty and deleted entries in Value. Derived classes must
102 implement the hash and equal_keys functions. */
104 template <typename Value
>
105 struct unbounded_hashmap_traits
107 template <typename T
> static inline void remove (T
&);
108 template <typename T
> static inline bool is_empty (const T
&);
109 template <typename T
> static inline bool is_deleted (const T
&);
110 template <typename T
> static inline void mark_empty (T
&);
111 template <typename T
> static inline void mark_deleted (T
&);
114 template <typename Value
>
115 template <typename T
>
117 unbounded_hashmap_traits
<Value
>::remove (T
&entry
)
119 default_hash_traits
<Value
>::remove (entry
.m_value
);
122 template <typename Value
>
123 template <typename T
>
125 unbounded_hashmap_traits
<Value
>::is_empty (const T
&entry
)
127 return default_hash_traits
<Value
>::is_empty (entry
.m_value
);
130 template <typename Value
>
131 template <typename T
>
133 unbounded_hashmap_traits
<Value
>::is_deleted (const T
&entry
)
135 return default_hash_traits
<Value
>::is_deleted (entry
.m_value
);
138 template <typename Value
>
139 template <typename T
>
141 unbounded_hashmap_traits
<Value
>::mark_empty (T
&entry
)
143 default_hash_traits
<Value
>::mark_empty (entry
.m_value
);
146 template <typename Value
>
147 template <typename T
>
149 unbounded_hashmap_traits
<Value
>::mark_deleted (T
&entry
)
151 default_hash_traits
<Value
>::mark_deleted (entry
.m_value
);
154 /* Implement traits for a hash_map from integer type Key to Value in
155 cases where Key has no spare values for recording empty and deleted
158 template <typename Key
, typename Value
>
159 struct unbounded_int_hashmap_traits
: unbounded_hashmap_traits
<Value
>
161 static inline hashval_t
hash (Key
);
162 static inline bool equal_keys (Key
, Key
);
165 template <typename Key
, typename Value
>
167 unbounded_int_hashmap_traits
<Key
, Value
>::hash (Key k
)
172 template <typename Key
, typename Value
>
174 unbounded_int_hashmap_traits
<Key
, Value
>::equal_keys (Key k1
, Key k2
)
179 #endif // HASH_MAP_TRAITS_H