Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame^] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #ifndef ART_SRC_CLASS_UNORDERED_MAP_H_ |
| 4 | #define ART_SRC_CLASS_UNORDERED_MAP_H_ |
| 5 | |
| 6 | #include "stringpiece.h" |
| 7 | |
| 8 | #ifdef __ANDROID__ |
| 9 | #include <unordered_map> |
| 10 | #else |
| 11 | #include <tr1/unordered_map> |
| 12 | #endif |
| 13 | |
| 14 | namespace std { |
| 15 | #ifndef __ANDROID__ |
| 16 | namespace tr1 { |
| 17 | #endif |
| 18 | template<> |
| 19 | struct hash<art::StringPiece> { |
| 20 | public: |
| 21 | size_t operator()(const art::StringPiece& string_piece) const { |
| 22 | size_t string_size = string_piece.size(); |
| 23 | const char* string_data = string_piece.data(); |
| 24 | // this is the java.lang.String hashcode for convenience, not interoperability |
| 25 | size_t hash = 0; |
| 26 | while (string_size--) { |
| 27 | hash = hash * 31 + *string_data++; |
| 28 | } |
| 29 | return hash; |
| 30 | } |
| 31 | }; |
| 32 | #ifndef __ANDROID__ |
| 33 | } // namespace tr1 |
| 34 | #endif |
| 35 | } // namespace std |
| 36 | |
| 37 | #endif // ART_SRC_CLASS_UNORDERED_MAP_H_ |