Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: base/hash.h

Issue 182253007: base::Hash: Minor improvements to documentation and testing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added a comment that this algorithm is also in Blink. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/hash.cc » ('j') | base/hash_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_HASH_H_ 5 #ifndef BASE_HASH_H_
6 #define BASE_HASH_H_ 6 #define BASE_HASH_H_
7 7
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 10
11 #include "base/base_export.h" 11 #include "base/base_export.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 14
15 namespace base { 15 namespace base {
16 16
17 // WARNING: This hash function should not be used for any cryptographic purpose. 17 // WARNING: This hash function should not be used for any cryptographic purpose.
18 BASE_EXPORT uint32 SuperFastHash(const char* data, int len); 18 BASE_EXPORT uint32 SuperFastHash(const char* data, int len);
19 19
20 // Computes the hash of a string |key| of a given |length|. |key| does not need 20 // Computes a hash of a memory buffer |data| of a given |length|.
21 // to be null-terminated, and may contain null bytes.
22 // WARNING: This hash function should not be used for any cryptographic purpose. 21 // WARNING: This hash function should not be used for any cryptographic purpose.
23 inline uint32 Hash(const char* key, size_t length) { 22 inline uint32 Hash(const char* data, size_t length) {
24 if (length > static_cast<size_t>(std::numeric_limits<int>::max())) { 23 if (length > static_cast<size_t>(std::numeric_limits<int>::max())) {
25 NOTREACHED(); 24 NOTREACHED();
26 return 0; 25 return 0;
27 } 26 }
28 return SuperFastHash(key, static_cast<int>(length)); 27 return SuperFastHash(data, static_cast<int>(length));
29 } 28 }
30 29
31 // Computes the hash of a string |key|. 30 // Computes a hash of a string |str|.
32 // WARNING: This hash function should not be used for any cryptographic purpose. 31 // WARNING: This hash function should not be used for any cryptographic purpose.
33 inline uint32 Hash(const std::string& key) { 32 inline uint32 Hash(const std::string& str) {
34 return Hash(key.data(), key.size()); 33 return Hash(str.data(), str.size());
35 } 34 }
36 35
37 } // namespace base 36 } // namespace base
38 37
39 #endif // BASE_HASH_H_ 38 #endif // BASE_HASH_H_
OLDNEW
« no previous file with comments | « no previous file | base/hash.cc » ('j') | base/hash_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698