diff options
author | mgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-03 07:59:27 +0000 |
---|---|---|
committer | mgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-03 07:59:27 +0000 |
commit | e30e29479b4babe4d2ae909255e6bb818d077cc1 (patch) | |
tree | 8f920b40a1bd95359b07df9a864cd8158dfb8367 /base/hash.h | |
parent | 58119e9ebf8886b8210a2d9cfd9947c591fe8fcb (diff) | |
download | chromium_src-e30e29479b4babe4d2ae909255e6bb818d077cc1.zip chromium_src-e30e29479b4babe4d2ae909255e6bb818d077cc1.tar.gz chromium_src-e30e29479b4babe4d2ae909255e6bb818d077cc1.tar.bz2 |
Moved SuperFastHash function from base/hash.cc to base/third_party.
This code was written by Paul Hsieh under a 3-clause BSD license. It
belongs in third_party.
I did not move the existing implementation, but re-downloaded the code
from upstream:
http://www.azillionmonkeys.com/qed/hash.html
This version is formatted differently and is written in plain C, but it
is identical to the version that was previously in hash.cc.
Added LICENSE and README.chromium files, as well as adding license text
to the top of superfasthash.cc, as required by checklicenses.py.
BUG=347393
Review URL: https://codereview.chromium.org/181643004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@254437 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/hash.h')
-rw-r--r-- | base/hash.h | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/base/hash.h b/base/hash.h index cf8ea3a..0b9c9f6 100644 --- a/base/hash.h +++ b/base/hash.h @@ -5,25 +5,33 @@ #ifndef BASE_HASH_H_ #define BASE_HASH_H_ +#include <limits> #include <string> #include "base/base_export.h" #include "base/basictypes.h" +#include "base/logging.h" namespace base { -// From http://www.azillionmonkeys.com/qed/hash.html -// This is the hash used on WebCore/platform/stringhash -BASE_EXPORT uint32 SuperFastHash(const char * data, int len); +// WARNING: This hash function should not be used for any cryptographic purpose. +BASE_EXPORT uint32 SuperFastHash(const char* data, int len); +// Computes the hash of a string |key| of a given |length|. |key| does not need +// to be null-terminated, and may contain null bytes. +// WARNING: This hash function should not be used for any cryptographic purpose. inline uint32 Hash(const char* key, size_t length) { + if (length > static_cast<size_t>(std::numeric_limits<int>::max())) { + NOTREACHED(); + return 0; + } return SuperFastHash(key, static_cast<int>(length)); } +// Computes the hash of a string |key|. +// WARNING: This hash function should not be used for any cryptographic purpose. inline uint32 Hash(const std::string& key) { - if (key.empty()) - return 0; - return SuperFastHash(key.data(), static_cast<int>(key.size())); + return Hash(key.data(), key.size()); } } // namespace base |