[email protected] | 5138d5f | 2011-05-07 00:49:34 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 51ddf72 | 2012-09-01 00:55:09 | [diff] [blame] | 5 | #ifndef BASE_HASH_H_ |
6 | #define BASE_HASH_H_ | ||||
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 7 | |
8 | #include <string> | ||||
9 | |||||
[email protected] | 51ddf72 | 2012-09-01 00:55:09 | [diff] [blame] | 10 | #include "base/base_export.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 11 | #include "base/basictypes.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 12 | |
[email protected] | 51ddf72 | 2012-09-01 00:55:09 | [diff] [blame] | 13 | namespace base { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 14 | |
15 | // From http://www.azillionmonkeys.com/qed/hash.html | ||||
16 | // This is the hash used on WebCore/platform/stringhash | ||||
[email protected] | 51ddf72 | 2012-09-01 00:55:09 | [diff] [blame] | 17 | BASE_EXPORT uint32 SuperFastHash(const char * data, int len); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 18 | |
19 | inline uint32 Hash(const char* key, size_t length) { | ||||
20 | return SuperFastHash(key, static_cast<int>(length)); | ||||
21 | } | ||||
22 | |||||
23 | inline uint32 Hash(const std::string& key) { | ||||
24 | if (key.empty()) | ||||
25 | return 0; | ||||
26 | return SuperFastHash(key.data(), static_cast<int>(key.size())); | ||||
27 | } | ||||
28 | |||||
[email protected] | 51ddf72 | 2012-09-01 00:55:09 | [diff] [blame] | 29 | } // namespace base |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 30 | |
[email protected] | 51ddf72 | 2012-09-01 00:55:09 | [diff] [blame] | 31 | #endif // BASE_HASH_H_ |