/* * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_HASH_FUNCTIONS_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_HASH_FUNCTIONS_H_ #include <stdint.h> #include <type_traits> #include "base/bit_cast.h" namespace WTF { namespace internal { template <size_t size> struct IntTypes; template <> struct IntTypes<1> { … }; template <> struct IntTypes<2> { … }; template <> struct IntTypes<4> { … }; template <> struct IntTypes<8> { … }; IntHashBits; // Hash functions for integral and enum types. // Thomas Wang's 32 Bit Mix Function: // https://web.archive.org/web/20060507103516/http://www.cris.com/~Ttwang/tech/inthash.htm inline unsigned HashInt(uint32_t key) { … } inline unsigned HashInt(uint16_t key16) { … } inline unsigned HashInt(uint8_t key8) { … } // Thomas Wang's 64 bit Mix Function: // https://web.archive.org/web/20060507103516/http://www.cris.com/~Ttwang/tech/inthash.htm inline unsigned HashInt(uint64_t key) { … } } // namespace internal // Compound integer hash method: // http://opendatastructures.org/versions/edition-0.1d/ods-java/node33.html#SECTION00832000000000000000 inline unsigned HashInts(unsigned key1, unsigned key2) { … } template <typename T> unsigned HashInt(T key) { … } template <typename T> unsigned HashFloat(T key) { … } template <typename T> bool FloatEqualForHash(T a, T b) { … } template <typename T> unsigned HashPointer(T* key) { … } // Useful compounding hash functions. inline void AddIntToHash(unsigned& hash, unsigned key) { … } inline void AddFloatToHash(unsigned& hash, float value) { … } } // namespace WTF #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_HASH_FUNCTIONS_H_