//1// Copyright 2018 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// hash_utils.h: Hashing based helper functions.67#ifndef COMMON_HASHUTILS_H_8#define COMMON_HASHUTILS_H_910#include "common/debug.h"11#include "common/third_party/xxhash/xxhash.h"1213namespace angle14{15// Computes a hash of "key". Any data passed to this function must be multiples of16// 4 bytes, since the PMurHash32 method can only operate increments of 4-byte words.17inline std::size_t ComputeGenericHash(const void *key, size_t keySize)18{19static constexpr unsigned int kSeed = 0xABCDEF98;2021// We can't support "odd" alignments. ComputeGenericHash requires aligned types22ASSERT(keySize % 4 == 0);23#if defined(ANGLE_IS_64_BIT_CPU)24return XXH64(key, keySize, kSeed);25#else26return XXH32(key, keySize, kSeed);27#endif // defined(ANGLE_IS_64_BIT_CPU)28}2930template <typename T>31std::size_t ComputeGenericHash(const T &key)32{33static_assert(sizeof(key) % 4 == 0, "ComputeGenericHash requires aligned types");34return ComputeGenericHash(&key, sizeof(key));35}36} // namespace angle3738#endif // COMMON_HASHUTILS_H_394041