From: Richard Sandiford <richard.sandiford@arm.com>
To: gcc-patches@gcc.gnu.org
Subject: [01/12] Add hash_map traits that use existing hash_table-like traits
Date: Tue, 23 Jun 2015 14:44:00 -0000 [thread overview]
Message-ID: <87616ebi4v.fsf@e105548-lin.cambridge.arm.com> (raw)
In-Reply-To: <87egl2bicm.fsf@e105548-lin.cambridge.arm.com> (Richard Sandiford's message of "Tue, 23 Jun 2015 15:38:17 +0100")
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
next parent reply other threads:[~2015-06-23 14:43 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87egl2bicm.fsf@e105548-lin.cambridge.arm.com>
2015-06-23 14:44 ` Richard Sandiford [this message]
2015-06-25 16:34 ` Jeff Law
2015-06-23 14:45 ` [02/12] Move tree operand hashers to a new header file Richard Sandiford
2015-06-25 16:34 ` Jeff Law
2015-06-23 14:47 ` [03/12] Move decl hasher to " Richard Sandiford
2015-06-25 16:34 ` Jeff Law
2015-06-23 14:48 ` [04/12] Move ssa_name " Richard Sandiford
2015-06-25 16:35 ` Jeff Law
2015-06-23 14:49 ` [05/12] Move TREE_HASH " Richard Sandiford
2015-06-25 16:36 ` Jeff Law
2015-06-23 14:50 ` [06/12] Consolidate string hashers Richard Sandiford
2015-06-24 10:13 ` Mikhail Maltsev
2015-06-24 11:39 ` Richard Sandiford
2015-06-25 16:37 ` Jeff Law
2015-06-23 14:52 ` [07/12] Use new string hasher for MIPS Richard Sandiford
2015-06-25 16:39 ` Jeff Law
2015-06-23 14:53 ` [08/12] Add common traits for integer hash keys Richard Sandiford
2015-06-25 16:40 ` Jeff Law
2015-06-23 14:55 ` [09/12] Remove all but one use of default_hashmap_traits Richard Sandiford
2015-06-25 16:41 ` Jeff Law
2015-06-23 14:56 ` [10/12] Add helper class for valued-based empty and deleted slots Richard Sandiford
2015-06-25 16:41 ` Jeff Law
2015-06-23 14:57 ` [11/12] Remove default_hashmap_traits Richard Sandiford
2015-06-25 16:42 ` Jeff Law
2015-06-23 14:58 ` [12/12] Simplify uses of hash_map Richard Sandiford
2015-06-25 16:57 ` Jeff Law
2015-06-26 13:50 ` Rainer Orth
2015-06-26 14:38 ` Richard Sandiford
2015-06-26 14:39 ` Jan-Benedict Glaw
2015-06-26 15:34 ` Rainer Orth
2015-06-26 16:17 ` Richard Sandiford
2015-06-26 16:45 ` Richard Sandiford
2015-06-26 17:03 ` Richard Sandiford
2015-06-26 16:09 ` Mikhail Maltsev
2015-06-26 14:36 ` [BUILDROBOT] could not convert template argument ‘fill_decls_vec’ to ‘bool (*)(tree_node*&, tree_node**, auto_vec<cilk_decls>*)’ (was: [12/12] Simplify uses of hash_map) Jan-Benedict Glaw
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87616ebi4v.fsf@e105548-lin.cambridge.arm.com \
--to=richard.sandiford@arm.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).