/src/brpc/src/butil/hash.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 | | // Use of this source code is governed by a BSD-style license that can be |
3 | | // found in the LICENSE file. |
4 | | |
5 | | #ifndef BUTIL_HASH_H_ |
6 | | #define BUTIL_HASH_H_ |
7 | | |
8 | | #include <limits> |
9 | | #include <string> |
10 | | |
11 | | #include "butil/base_export.h" |
12 | | #include "butil/basictypes.h" |
13 | | #include "butil/logging.h" |
14 | | |
15 | | namespace butil { |
16 | | |
17 | | // WARNING: This hash function should not be used for any cryptographic purpose. |
18 | | BUTIL_EXPORT uint32_t SuperFastHash(const char* data, int len); |
19 | | |
20 | | // Computes a hash of a memory buffer |data| of a given |length|. |
21 | | // WARNING: This hash function should not be used for any cryptographic purpose. |
22 | 177 | inline uint32_t Hash(const char* data, size_t length) { |
23 | 177 | if (length > static_cast<size_t>(std::numeric_limits<int>::max())) { |
24 | 0 | NOTREACHED(); |
25 | 0 | return 0; |
26 | 0 | } |
27 | 177 | return SuperFastHash(data, static_cast<int>(length)); |
28 | 177 | } |
29 | | |
30 | | // Computes a hash of a string |str|. |
31 | | // WARNING: This hash function should not be used for any cryptographic purpose. |
32 | 177 | inline uint32_t Hash(const std::string& str) { |
33 | 177 | return Hash(str.data(), str.size()); |
34 | 177 | } |
35 | | |
36 | | } // namespace butil |
37 | | |
38 | | #endif // BUTIL_HASH_H_ |