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