tree-hasher.h 1.9 KB

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