// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Based on "v8/src/base/functional.cc". // See: Thomas Wang, Integer Hash Functions. // https://gist.github.com/badboy/6267743 // TODO(pkalinnikov): Consider moving the implementation into base/. #ifndef COMPONENTS_URL_PATTERN_INDEX_UINT64_HASHER_H_ #define COMPONENTS_URL_PATTERN_INDEX_UINT64_HASHER_H_ #include <stddef.h> #include <stdint.h> #include <type_traits> namespace url_pattern_index { template <typename T> typename std::enable_if<sizeof(T) == 4, T>::type Uint64Hash(uint64_t v) { … } template <typename T> typename std::enable_if<sizeof(T) == 8, T>::type Uint64Hash(uint64_t v) { … } // Note: A Uint64ToUint64Hasher variant is currently not needed. // Note: Be careful about a variant that hashes differently in 32-bit vs. 64-bit // processes (i.e., using |size_t| where the below uses |uint32_t|). Such a // variant will break compatibility for tables that are built and accessed in // processes of differing bitness, which is a real-world concern for users of // this component (see crbug.com/1174797 for details). class Uint64ToUint32Hasher { … }; } // namespace url_pattern_index #endif // COMPONENTS_URL_PATTERN_INDEX_UINT64_HASHER_H_