]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/tree-hasher.h
allow storing values directly in hash tables
[thirdparty/gcc.git] / gcc / tree-hasher.h
CommitLineData
4a8fb1a1 1/* Hash Table Helper for Trees
23a5b65a 2 Copyright (C) 2012-2014 Free Software Foundation, Inc.
4a8fb1a1
LC
3 Contributed by Lawrence Crowl <crowl@google.com>
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_TREE_HASHER_H
22#define GCC_TREE_HASHER_H 1
23
24#include "hash-table.h"
cc524fc7
AM
25
26struct int_tree_map {
27 unsigned int uid;
28 tree to;
29};
4a8fb1a1
LC
30
31/* Hashtable helpers. */
32
84baa4b9 33struct int_tree_hasher
4a8fb1a1
LC
34{
35 typedef int_tree_map value_type;
36 typedef int_tree_map compare_type;
84baa4b9
TS
37 typedef int store_values_directly;
38 static inline hashval_t hash (const value_type &);
39 static inline bool equal (const value_type &, const compare_type &);
40 static bool is_deleted (const value_type &v)
41 {
42 return v.to == reinterpret_cast<tree> (1);
43 }
44 static void mark_deleted (value_type &v) { v.to = reinterpret_cast<tree> (0x1); }
45 static bool is_empty (const value_type &v) { return v.to == NULL; }
46 static void mark_empty (value_type &v) { v.to = NULL; }
47 static void remove (value_type &) {}
4a8fb1a1
LC
48};
49
50/* Hash a UID in a int_tree_map. */
51
52inline hashval_t
84baa4b9 53int_tree_hasher::hash (const value_type &item)
4a8fb1a1 54{
84baa4b9 55 return item.uid;
4a8fb1a1
LC
56}
57
58/* Return true if the uid in both int tree maps are equal. */
59
60inline bool
84baa4b9 61int_tree_hasher::equal (const value_type &a, const compare_type &b)
4a8fb1a1 62{
84baa4b9 63 return (a.uid == b.uid);
4a8fb1a1
LC
64}
65
66typedef hash_table <int_tree_hasher> int_tree_htab_type;
67
68#endif /* GCC_TREE_HASHER_H */