From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2962 invoked by alias); 23 Jun 2015 14:43:02 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 2942 invoked by uid 89); 23 Jun 2015 14:43:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL,BAYES_00,KAM_ASCII_DIVIDERS,SPF_PASS autolearn=no version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 23 Jun 2015 14:43:00 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-30-s3aUgLGJRnCGIJpc-iDPZg-1 Received: from localhost ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 23 Jun 2015 15:42:56 +0100 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [01/12] Add hash_map traits that use existing hash_table-like traits References: <87egl2bicm.fsf@e105548-lin.cambridge.arm.com> Date: Tue, 23 Jun 2015 14:44:00 -0000 In-Reply-To: <87egl2bicm.fsf@e105548-lin.cambridge.arm.com> (Richard Sandiford's message of "Tue, 23 Jun 2015 15:38:17 +0100") Message-ID: <87616ebi4v.fsf@e105548-lin.cambridge.arm.com> User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-MC-Unique: s3aUgLGJRnCGIJpc-iDPZg-1 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2015-06/txt/msg01566.txt.bz2 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 >. Index: gcc/hash-map-traits.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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. */ =20 +#include "hash-traits.h" + /* implement default behavior for traits when types allow it. */ =20 struct default_hashmap_traits @@ -101,4 +103,75 @@ struct default_hashmap_traits } }; =20 +/* Implement hash_map traits for a key with hash traits H. Empty and + deleted map entries are represented as empty and deleted keys. */ + +template +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 static inline void remove (T &); + template static inline bool is_empty (const T &); + template static inline bool is_deleted (const T &); + template static inline void mark_empty (T &); + template static inline void mark_deleted (T &); +}; + +template +inline hashval_t +simple_hashmap_traits ::hash (const typename H::value_type &h) +{ + return H::hash (h); +} + +template +inline bool +simple_hashmap_traits ::equal_keys (const typename H::value_type &k1, + const typename H::value_type &k2) +{ + return H::equal (k1, k2); +} + +template +template +inline void +simple_hashmap_traits ::remove (T &entry) +{ + H::remove (entry.m_key); +} + +template +template +inline bool +simple_hashmap_traits ::is_empty (const T &entry) +{ + return H::is_empty (entry.m_key); +} + +template +template +inline bool +simple_hashmap_traits ::is_deleted (const T &entry) +{ + return H::is_deleted (entry.m_key); +} + +template +template +inline void +simple_hashmap_traits ::mark_empty (T &entry) +{ + H::mark_empty (entry.m_key); +} + +template +template +inline void +simple_hashmap_traits ::mark_deleted (T &entry) +{ + H::mark_deleted (entry.m_key); +} + #endif // HASH_MAP_TRAITS_H Index: gcc/mem-stats.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 =20 /* Forward declaration. */ template + typename Traits =3D simple_hashmap_traits > > class hash_map; =20 #define LOCATION_LINE_EXTRA_SPACE 30