OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef RUNTIME_PLATFORM_HASHMAP_H_ | 5 #ifndef RUNTIME_PLATFORM_HASHMAP_H_ |
6 #define RUNTIME_PLATFORM_HASHMAP_H_ | 6 #define RUNTIME_PLATFORM_HASHMAP_H_ |
7 | 7 |
8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
9 | 9 |
10 namespace dart { | 10 namespace dart { |
11 | 11 |
12 class HashMap { | 12 class HashMap { |
13 public: | 13 public: |
14 typedef bool (*MatchFun) (void* key1, void* key2); | 14 typedef bool (*MatchFun)(void* key1, void* key2); |
15 | 15 |
16 typedef void (*ClearFun) (void* value); | 16 typedef void (*ClearFun)(void* value); |
17 | 17 |
18 // initial_capacity is the size of the initial hash map; | 18 // initial_capacity is the size of the initial hash map; |
19 // it must be a power of 2 (and thus must not be 0). | 19 // it must be a power of 2 (and thus must not be 0). |
20 HashMap(MatchFun match, uint32_t initial_capacity); | 20 HashMap(MatchFun match, uint32_t initial_capacity); |
21 | 21 |
22 ~HashMap(); | 22 ~HashMap(); |
23 | 23 |
24 static bool SamePointerValue(void* key1, void* key2) { | 24 static bool SamePointerValue(void* key1, void* key2) { return key1 == key2; } |
25 return key1 == key2; | |
26 } | |
27 | 25 |
28 static uint32_t StringHash(char* key) { | 26 static uint32_t StringHash(char* key) { |
29 uint32_t hash_ = 0; | 27 uint32_t hash_ = 0; |
30 if (key == NULL) return hash_; | 28 if (key == NULL) return hash_; |
31 int len = strlen(key); | 29 int len = strlen(key); |
32 for (int i = 0; i < len; i++) { | 30 for (int i = 0; i < len; i++) { |
33 hash_ += key[i]; | 31 hash_ += key[i]; |
34 hash_ += hash_ << 10; | 32 hash_ += hash_ << 10; |
35 hash_ ^= hash_ >> 6; | 33 hash_ ^= hash_ >> 6; |
36 } | 34 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 void Initialize(uint32_t capacity); | 97 void Initialize(uint32_t capacity); |
100 void Resize(); | 98 void Resize(); |
101 | 99 |
102 friend class IntSet; // From hashmap_test.cc | 100 friend class IntSet; // From hashmap_test.cc |
103 DISALLOW_COPY_AND_ASSIGN(HashMap); | 101 DISALLOW_COPY_AND_ASSIGN(HashMap); |
104 }; | 102 }; |
105 | 103 |
106 } // namespace dart | 104 } // namespace dart |
107 | 105 |
108 #endif // RUNTIME_PLATFORM_HASHMAP_H_ | 106 #endif // RUNTIME_PLATFORM_HASHMAP_H_ |
OLD | NEW |