blob: 66613c6a015251d0f20b8984589ecdd0a6c32a8f [file] [log] [blame]
Brian Carlstrom7e93b502011-08-04 14:16:22 -07001// 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
14namespace std {
15#ifndef __ANDROID__
16namespace tr1 {
17#endif
18template<>
19struct 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_