This patch defines a class that converts hash_table-style traits into
hash_map traits.  It can be used as the default traits for all hash_maps
that don't specify their own traits (i.e. this patch does work on its own).

By the end of the series this class replaces default_hashmap_traits.


gcc/
        * hash-map-traits.h: Include hash-traits.h.
        (simple_hashmap_traits): New class.
        * mem-stats.h (hash_map): Change the default traits to
        simple_hashmap_traits<default_hash_traits<Key> >.

Index: gcc/hash-map-traits.h
===================================================================
--- gcc/hash-map-traits.h       2015-06-23 15:42:24.132002236 +0100
+++ gcc/hash-map-traits.h       2015-06-23 15:42:24.128002280 +0100
@@ -23,6 +23,8 @@ #define HASH_MAP_TRAITS_H
 /* Bacause mem-stats.h uses default hashmap traits, we have to
    put the class to this separate header file.  */
 
+#include "hash-traits.h"
+
 /* implement default behavior for traits when types allow it.  */
 
 struct default_hashmap_traits
@@ -101,4 +103,75 @@ struct default_hashmap_traits
     }
 };
 
+/* Implement hash_map traits for a key with hash traits H.  Empty and
+   deleted map entries are represented as empty and deleted keys.  */
+
+template <typename H>
+struct simple_hashmap_traits
+{
+  static inline hashval_t hash (const typename H::value_type &);
+  static inline bool equal_keys (const typename H::value_type &,
+                                const typename H::value_type &);
+  template <typename T> static inline void remove (T &);
+  template <typename T> static inline bool is_empty (const T &);
+  template <typename T> static inline bool is_deleted (const T &);
+  template <typename T> static inline void mark_empty (T &);
+  template <typename T> static inline void mark_deleted (T &);
+};
+
+template <typename H>
+inline hashval_t
+simple_hashmap_traits <H>::hash (const typename H::value_type &h)
+{
+  return H::hash (h);
+}
+
+template <typename H>
+inline bool
+simple_hashmap_traits <H>::equal_keys (const typename H::value_type &k1,
+                                      const typename H::value_type &k2)
+{
+  return H::equal (k1, k2);
+}
+
+template <typename H>
+template <typename T>
+inline void
+simple_hashmap_traits <H>::remove (T &entry)
+{
+  H::remove (entry.m_key);
+}
+
+template <typename H>
+template <typename T>
+inline bool
+simple_hashmap_traits <H>::is_empty (const T &entry)
+{
+  return H::is_empty (entry.m_key);
+}
+
+template <typename H>
+template <typename T>
+inline bool
+simple_hashmap_traits <H>::is_deleted (const T &entry)
+{
+  return H::is_deleted (entry.m_key);
+}
+
+template <typename H>
+template <typename T>
+inline void
+simple_hashmap_traits <H>::mark_empty (T &entry)
+{
+  H::mark_empty (entry.m_key);
+}
+
+template <typename H>
+template <typename T>
+inline void
+simple_hashmap_traits <H>::mark_deleted (T &entry)
+{
+  H::mark_deleted (entry.m_key);
+}
+
 #endif // HASH_MAP_TRAITS_H
Index: gcc/mem-stats.h
===================================================================
--- gcc/mem-stats.h     2015-06-23 15:42:24.132002236 +0100
+++ gcc/mem-stats.h     2015-06-23 15:42:24.128002280 +0100
@@ -3,7 +3,7 @@ #define GCC_MEM_STATS_H
 
 /* Forward declaration.  */
 template<typename Key, typename Value,
-        typename Traits = default_hashmap_traits>
+        typename Traits = simple_hashmap_traits<default_hash_traits<Key> > >
 class hash_map;
 
 #define LOCATION_LINE_EXTRA_SPACE 30

Reply via email to