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 /* implement default behavior for traits when types allow it. */
28 struct default_hashmap_traits
30 /* Hashes the passed in key. */
36 return uintptr_t (p
) >> 3;
39 /* If the value converts to hashval_t just use it. */
41 template<typename T
> static hashval_t
hash (T v
) { return v
; }
43 /* Return true if the two keys passed as arguments are equal. */
47 equal_keys (const T
&a
, const T
&b
)
52 /* Called to dispose of the key and value before marking the entry as
55 template<typename T
> static void remove (T
&v
) { v
.~T (); }
57 /* Mark the passed in entry as being deleted. */
63 mark_key_deleted (e
.m_key
);
66 /* Mark the passed in entry as being empty. */
72 mark_key_empty (e
.m_key
);
75 /* Return true if the passed in entry is marked as deleted. */
81 return e
.m_key
== (void *)1;
84 /* Return true if the passed in entry is marked as empty. */
86 template<typename T
> static bool is_empty (T
&e
) { return e
.m_key
== NULL
; }
91 mark_key_deleted (T
*&k
)
93 k
= reinterpret_cast<T
*> (1);
98 mark_key_empty (T
*&k
)
100 k
= static_cast<T
*> (0);
104 #endif // HASH_MAP_TRAITS_H