tree-hasher.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Hash Table Helper for Trees
  2. Copyright (C) 2012-2019 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 void mark_empty (value_type &v) { v.to = NULL; }
  36. static void remove (value_type &) {}
  37. };
  38. /* Hash a UID in a int_tree_map. */
  39. inline hashval_t
  40. int_tree_hasher::hash (const value_type &item)
  41. {
  42. return item.uid;
  43. }
  44. /* Return true if the uid in both int tree maps are equal. */
  45. inline bool
  46. int_tree_hasher::equal (const value_type &a, const compare_type &b)
  47. {
  48. return (a.uid == b.uid);
  49. }
  50. typedef hash_table <int_tree_hasher> int_tree_htab_type;
  51. #endif /* GCC_TREE_HASHER_H */