diff options
Diffstat (limited to 'src/google/protobuf/stubs/stringpiece.h')
-rw-r--r-- | src/google/protobuf/stubs/stringpiece.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/google/protobuf/stubs/stringpiece.h b/src/google/protobuf/stubs/stringpiece.h index 353a60d3..ec3ffd5b 100644 --- a/src/google/protobuf/stubs/stringpiece.h +++ b/src/google/protobuf/stubs/stringpiece.h @@ -149,6 +149,7 @@ #include <string> #include <google/protobuf/stubs/common.h> +#include <google/protobuf/stubs/hash.h> namespace google { namespace protobuf { @@ -437,4 +438,16 @@ extern std::ostream& operator<<(std::ostream& o, StringPiece piece); } // namespace protobuf } // namespace google +GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_START +template<> struct hash<StringPiece> { + size_t operator()(const StringPiece& s) const { + size_t result = 0; + for (const char *str = s.data(), *end = str + s.size(); str < end; str++) { + result = 5 * result + *str; + } + return result; + } +}; +GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_END + #endif // STRINGS_STRINGPIECE_H_ |