tree-hasher.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Hash Table Helper for Trees
  2. Copyright (C) 2012-2015 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. #include "hash-table.h"
  19. struct int_tree_map {
  20. unsigned int uid;
  21. tree to;
  22. };
  23. /* Hashtable helpers. */
  24. struct int_tree_hasher
  25. {
  26. typedef int_tree_map value_type;
  27. typedef int_tree_map compare_type;
  28. typedef int store_values_directly;
  29. static inline hashval_t hash (const value_type &);
  30. static inline bool equal (const value_type &, const compare_type &);
  31. static bool is_deleted (const value_type &v)
  32. {
  33. return v.to == reinterpret_cast<tree> (1);
  34. }
  35. static void mark_deleted (value_type &v) { v.to = reinterpret_cast<tree> (0x1); }
  36. static bool is_empty (const value_type &v) { return v.to == NULL; }
  37. static void mark_empty (value_type &v) { v.to = NULL; }
  38. static void remove (value_type &) {}
  39. };
  40. /* Hash a UID in a int_tree_map. */
  41. inline hashval_t
  42. int_tree_hasher::hash (const value_type &item)
  43. {
  44. return item.uid;
  45. }
  46. /* Return true if the uid in both int tree maps are equal. */
  47. inline bool
  48. int_tree_hasher::equal (const value_type &a, const compare_type &b)
  49. {
  50. return (a.uid == b.uid);
  51. }
  52. typedef hash_table <int_tree_hasher> int_tree_htab_type;
  53. #endif /* GCC_TREE_HASHER_H */