diff --git a/gcc/hash-traits.h b/gcc/hash-traits.h index 55b81eb0f9e..f5d12706324 100644 --- a/gcc/hash-traits.h +++ b/gcc/hash-traits.h @@ -408,6 +408,61 @@ pair_hash ::is_empty (const value_type &x) return T1::is_empty (x.first); } +/* Base traits for vectors, providing just the hash and comparison + functionality. Type gives the corresponding traits for the element + type. */ + +template +struct vec_hash_base +{ + typedef vec value_type; + typedef vec compare_type; + + static inline hashval_t hash (value_type); + static inline bool equal (value_type, compare_type); +}; + +template +inline hashval_t +vec_hash_base ::hash (value_type x) +{ + inchash::hash hstate; + hstate.add_int (x.length ()); + for (auto &value : x) + hstate.merge_hash (Type::hash (value)); + return hstate.end (); +} + +template +inline bool +vec_hash_base ::equal (value_type x, compare_type y) +{ + if (x.length () != y.length ()) + return false; + for (unsigned int i = 0; i < x.length (); ++i) + if (!Type::equal (x[i], y[i])) + return false; + return true; +} + +/* Traits for vectors whose contents should be freed normally. */ + +template +struct vec_free_hash_base : vec_hash_base +{ + static void remove (typename vec_hash_base ::value_type &); +}; + +template +void +vec_free_hash_base +::remove (typename vec_hash_base ::value_type &x) +{ + for (auto &value : x) + Type::remove (x); + x.release (); +} + template struct default_hash_traits : T {}; template