]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/hash-traits.h
1 /* Traits for hashable types.
2 Copyright (C) 2014-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/>. */
23 /* Helpful type for removing with free. */
25 template <typename Type
>
26 struct typed_free_remove
28 static inline void remove (Type
*p
);
32 /* Remove with free. */
34 template <typename Type
>
36 typed_free_remove
<Type
>::remove (Type
*p
)
42 /* Helpful type for a no-op remove. */
44 template <typename Type
>
45 struct typed_noop_remove
47 static inline void remove (Type
*p
);
51 /* Remove doing nothing. */
53 template <typename Type
>
55 typed_noop_remove
<Type
>::remove (Type
*p ATTRIBUTE_UNUSED
)
60 /* Pointer hash with a no-op remove method. */
62 template <typename Type
>
63 struct pointer_hash
: typed_noop_remove
<Type
>
65 typedef Type
*value_type
;
66 typedef Type
*compare_type
;
68 static inline hashval_t
hash (const value_type
&);
69 static inline bool equal (const value_type
&existing
,
70 const compare_type
&candidate
);
71 static inline void mark_deleted (Type
*&);
72 static inline void mark_empty (Type
*&);
73 static inline bool is_deleted (Type
*);
74 static inline bool is_empty (Type
*);
77 template <typename Type
>
79 pointer_hash
<Type
>::hash (const value_type
&candidate
)
81 /* This is a really poor hash function, but it is what the current code uses,
82 so I am reusing it to avoid an additional axis in testing. */
83 return (hashval_t
) ((intptr_t)candidate
>> 3);
86 template <typename Type
>
88 pointer_hash
<Type
>::equal (const value_type
&existing
,
89 const compare_type
&candidate
)
91 return existing
== candidate
;
94 template <typename Type
>
96 pointer_hash
<Type
>::mark_deleted (Type
*&e
)
98 e
= reinterpret_cast<Type
*> (1);
101 template <typename Type
>
103 pointer_hash
<Type
>::mark_empty (Type
*&e
)
108 template <typename Type
>
110 pointer_hash
<Type
>::is_deleted (Type
*e
)
112 return e
== reinterpret_cast<Type
*> (1);
115 template <typename Type
>
117 pointer_hash
<Type
>::is_empty (Type
*e
)
122 /* Hasher for entry in gc memory. */
127 typedef T value_type
;
128 typedef T compare_type
;
130 static void remove (T
&) {}
135 extern void gt_ggc_mx (T
&);
142 extern void gt_pch_nx (T
&);
147 pch_nx (T
&p
, gt_pointer_operator op
, void *cookie
)
153 /* Hasher for cache entry in gc memory. */
156 struct ggc_cache_hasher
: ggc_hasher
<T
>
158 /* Entries are weakly held because this is for caches. */
159 static void ggc_mx (T
&) {}
162 keep_cache_entry (T
&e
)
164 return ggc_marked_p (e
) ? -1 : 0;