110d565efSmrg /* A hash map traits.
2*ec02198aSmrg    Copyright (C) 2015-2020 Free Software Foundation, Inc.
310d565efSmrg 
410d565efSmrg This file is part of GCC.
510d565efSmrg 
610d565efSmrg GCC is free software; you can redistribute it and/or modify it under
710d565efSmrg the terms of the GNU General Public License as published by the Free
810d565efSmrg Software Foundation; either version 3, or (at your option) any later
910d565efSmrg version.
1010d565efSmrg 
1110d565efSmrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
1210d565efSmrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
1310d565efSmrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1410d565efSmrg for more details.
1510d565efSmrg 
1610d565efSmrg You should have received a copy of the GNU General Public License
1710d565efSmrg along with GCC; see the file COPYING3.  If not see
1810d565efSmrg <http://www.gnu.org/licenses/>.  */
1910d565efSmrg 
2010d565efSmrg #ifndef HASH_MAP_TRAITS_H
2110d565efSmrg #define HASH_MAP_TRAITS_H
2210d565efSmrg 
2310d565efSmrg /* Bacause mem-stats.h uses default hashmap traits, we have to
2410d565efSmrg    put the class to this separate header file.  */
2510d565efSmrg 
2610d565efSmrg #include "hash-traits.h"
2710d565efSmrg 
2810d565efSmrg /* Implement hash_map traits for a key with hash traits H.  Empty and
2910d565efSmrg    deleted map entries are represented as empty and deleted keys.  */
3010d565efSmrg 
3110d565efSmrg template <typename H, typename Value>
3210d565efSmrg struct simple_hashmap_traits
3310d565efSmrg {
3410d565efSmrg   typedef typename H::value_type key_type;
35c7a68eb7Smrg   static const bool maybe_mx = true;
3610d565efSmrg   static inline hashval_t hash (const key_type &);
3710d565efSmrg   static inline bool equal_keys (const key_type &, const key_type &);
3810d565efSmrg   template <typename T> static inline void remove (T &);
39*ec02198aSmrg   static const bool empty_zero_p = H::empty_zero_p;
4010d565efSmrg   template <typename T> static inline bool is_empty (const T &);
4110d565efSmrg   template <typename T> static inline bool is_deleted (const T &);
4210d565efSmrg   template <typename T> static inline void mark_empty (T &);
4310d565efSmrg   template <typename T> static inline void mark_deleted (T &);
4410d565efSmrg };
4510d565efSmrg 
4610d565efSmrg template <typename H, typename Value>
4710d565efSmrg inline hashval_t
hash(const key_type & h)4810d565efSmrg simple_hashmap_traits <H, Value>::hash (const key_type &h)
4910d565efSmrg {
5010d565efSmrg   return H::hash (h);
5110d565efSmrg }
5210d565efSmrg 
5310d565efSmrg template <typename H, typename Value>
5410d565efSmrg inline bool
equal_keys(const key_type & k1,const key_type & k2)5510d565efSmrg simple_hashmap_traits <H, Value>::equal_keys (const key_type &k1,
5610d565efSmrg 					      const key_type &k2)
5710d565efSmrg {
5810d565efSmrg   return H::equal (k1, k2);
5910d565efSmrg }
6010d565efSmrg 
6110d565efSmrg template <typename H, typename Value>
6210d565efSmrg template <typename T>
6310d565efSmrg inline void
remove(T & entry)6410d565efSmrg simple_hashmap_traits <H, Value>::remove (T &entry)
6510d565efSmrg {
6610d565efSmrg   H::remove (entry.m_key);
6710d565efSmrg   entry.m_value.~Value ();
6810d565efSmrg }
6910d565efSmrg 
7010d565efSmrg template <typename H, typename Value>
7110d565efSmrg template <typename T>
7210d565efSmrg inline bool
is_empty(const T & entry)7310d565efSmrg simple_hashmap_traits <H, Value>::is_empty (const T &entry)
7410d565efSmrg {
7510d565efSmrg   return H::is_empty (entry.m_key);
7610d565efSmrg }
7710d565efSmrg 
7810d565efSmrg template <typename H, typename Value>
7910d565efSmrg template <typename T>
8010d565efSmrg inline bool
is_deleted(const T & entry)8110d565efSmrg simple_hashmap_traits <H, Value>::is_deleted (const T &entry)
8210d565efSmrg {
8310d565efSmrg   return H::is_deleted (entry.m_key);
8410d565efSmrg }
8510d565efSmrg 
8610d565efSmrg template <typename H, typename Value>
8710d565efSmrg template <typename T>
8810d565efSmrg inline void
mark_empty(T & entry)8910d565efSmrg simple_hashmap_traits <H, Value>::mark_empty (T &entry)
9010d565efSmrg {
9110d565efSmrg   H::mark_empty (entry.m_key);
9210d565efSmrg }
9310d565efSmrg 
9410d565efSmrg template <typename H, typename Value>
9510d565efSmrg template <typename T>
9610d565efSmrg inline void
mark_deleted(T & entry)9710d565efSmrg simple_hashmap_traits <H, Value>::mark_deleted (T &entry)
9810d565efSmrg {
9910d565efSmrg   H::mark_deleted (entry.m_key);
10010d565efSmrg }
10110d565efSmrg 
102c7a68eb7Smrg template <typename H, typename Value>
103c7a68eb7Smrg struct simple_cache_map_traits: public simple_hashmap_traits<H,Value>
104c7a68eb7Smrg {
105c7a68eb7Smrg   static const bool maybe_mx = false;
106c7a68eb7Smrg };
107c7a68eb7Smrg 
10810d565efSmrg /* Implement traits for a hash_map with values of type Value for cases
10910d565efSmrg    in which the key cannot represent empty and deleted slots.  Instead
11010d565efSmrg    record empty and deleted entries in Value.  Derived classes must
11110d565efSmrg    implement the hash and equal_keys functions.  */
11210d565efSmrg 
11310d565efSmrg template <typename Value>
11410d565efSmrg struct unbounded_hashmap_traits
11510d565efSmrg {
11610d565efSmrg   template <typename T> static inline void remove (T &);
117*ec02198aSmrg   static const bool empty_zero_p = default_hash_traits <Value>::empty_zero_p;
11810d565efSmrg   template <typename T> static inline bool is_empty (const T &);
11910d565efSmrg   template <typename T> static inline bool is_deleted (const T &);
12010d565efSmrg   template <typename T> static inline void mark_empty (T &);
12110d565efSmrg   template <typename T> static inline void mark_deleted (T &);
12210d565efSmrg };
12310d565efSmrg 
12410d565efSmrg template <typename Value>
12510d565efSmrg template <typename T>
12610d565efSmrg inline void
remove(T & entry)12710d565efSmrg unbounded_hashmap_traits <Value>::remove (T &entry)
12810d565efSmrg {
12910d565efSmrg   default_hash_traits <Value>::remove (entry.m_value);
13010d565efSmrg }
13110d565efSmrg 
13210d565efSmrg template <typename Value>
13310d565efSmrg template <typename T>
13410d565efSmrg inline bool
is_empty(const T & entry)13510d565efSmrg unbounded_hashmap_traits <Value>::is_empty (const T &entry)
13610d565efSmrg {
13710d565efSmrg   return default_hash_traits <Value>::is_empty (entry.m_value);
13810d565efSmrg }
13910d565efSmrg 
14010d565efSmrg template <typename Value>
14110d565efSmrg template <typename T>
14210d565efSmrg inline bool
is_deleted(const T & entry)14310d565efSmrg unbounded_hashmap_traits <Value>::is_deleted (const T &entry)
14410d565efSmrg {
14510d565efSmrg   return default_hash_traits <Value>::is_deleted (entry.m_value);
14610d565efSmrg }
14710d565efSmrg 
14810d565efSmrg template <typename Value>
14910d565efSmrg template <typename T>
15010d565efSmrg inline void
mark_empty(T & entry)15110d565efSmrg unbounded_hashmap_traits <Value>::mark_empty (T &entry)
15210d565efSmrg {
15310d565efSmrg   default_hash_traits <Value>::mark_empty (entry.m_value);
15410d565efSmrg }
15510d565efSmrg 
15610d565efSmrg template <typename Value>
15710d565efSmrg template <typename T>
15810d565efSmrg inline void
mark_deleted(T & entry)15910d565efSmrg unbounded_hashmap_traits <Value>::mark_deleted (T &entry)
16010d565efSmrg {
16110d565efSmrg   default_hash_traits <Value>::mark_deleted (entry.m_value);
16210d565efSmrg }
16310d565efSmrg 
16410d565efSmrg /* Implement traits for a hash_map from integer type Key to Value in
16510d565efSmrg    cases where Key has no spare values for recording empty and deleted
16610d565efSmrg    slots.  */
16710d565efSmrg 
16810d565efSmrg template <typename Key, typename Value>
16910d565efSmrg struct unbounded_int_hashmap_traits : unbounded_hashmap_traits <Value>
17010d565efSmrg {
17110d565efSmrg   typedef Key key_type;
17210d565efSmrg   static inline hashval_t hash (Key);
17310d565efSmrg   static inline bool equal_keys (Key, Key);
17410d565efSmrg };
17510d565efSmrg 
17610d565efSmrg template <typename Key, typename Value>
17710d565efSmrg inline hashval_t
hash(Key k)17810d565efSmrg unbounded_int_hashmap_traits <Key, Value>::hash (Key k)
17910d565efSmrg {
18010d565efSmrg   return k;
18110d565efSmrg }
18210d565efSmrg 
18310d565efSmrg template <typename Key, typename Value>
18410d565efSmrg inline bool
equal_keys(Key k1,Key k2)18510d565efSmrg unbounded_int_hashmap_traits <Key, Value>::equal_keys (Key k1, Key k2)
18610d565efSmrg {
18710d565efSmrg   return k1 == k2;
18810d565efSmrg }
18910d565efSmrg 
19010d565efSmrg #endif // HASH_MAP_TRAITS_H
191