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 VM_HASH_MAP_H_ | 5 #ifndef VM_HASH_MAP_H_ |
6 #define VM_HASH_MAP_H_ | 6 #define VM_HASH_MAP_H_ |
7 | 7 |
8 namespace dart { | 8 namespace dart { |
9 | 9 |
10 template <typename KeyValueTrait> | 10 template <typename KeyValueTrait> |
(...skipping 10 matching lines...) Expand all Loading... |
21 } | 21 } |
22 | 22 |
23 DirectChainedHashMap(const DirectChainedHashMap& other); | 23 DirectChainedHashMap(const DirectChainedHashMap& other); |
24 | 24 |
25 void Insert(typename KeyValueTrait::Pair kv); | 25 void Insert(typename KeyValueTrait::Pair kv); |
26 | 26 |
27 typename KeyValueTrait::Value Lookup(typename KeyValueTrait::Key key) const; | 27 typename KeyValueTrait::Value Lookup(typename KeyValueTrait::Key key) const; |
28 | 28 |
29 bool IsEmpty() const { return count_ == 0; } | 29 bool IsEmpty() const { return count_ == 0; } |
30 | 30 |
31 private: | 31 void Clear() { |
| 32 if (!IsEmpty()) { |
| 33 count_ = 0; |
| 34 memset(array_, 0, sizeof(HashMapListElement) * array_size_); |
| 35 memset(lists_, 0, sizeof(HashMapListElement) * lists_size_); |
| 36 lists_[0].next = kNil; |
| 37 for (intptr_t i = 1; i < lists_size_; ++i) { |
| 38 lists_[i].next = i - 1; |
| 39 } |
| 40 free_list_head_ = lists_size_ - 1; |
| 41 } |
| 42 } |
| 43 |
| 44 protected: |
32 // A linked list of T values. Stored in arrays. | 45 // A linked list of T values. Stored in arrays. |
33 struct HashMapListElement { | 46 struct HashMapListElement { |
34 typename KeyValueTrait::Pair kv; | 47 typename KeyValueTrait::Pair kv; |
35 intptr_t next; // Index in the array of the next list element. | 48 intptr_t next; // Index in the array of the next list element. |
36 }; | 49 }; |
37 static const intptr_t kNil = -1; // The end of a linked list | 50 static const intptr_t kNil = -1; // The end of a linked list |
38 | 51 |
39 // Must be a power of 2. | 52 // Must be a power of 2. |
40 static const intptr_t kInitialSize = 16; | 53 static const intptr_t kInitialSize = 16; |
41 | 54 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } | 234 } |
222 | 235 |
223 static inline bool IsKeyEqual(Pair kv, Key key) { | 236 static inline bool IsKeyEqual(Pair kv, Key key) { |
224 return kv->Equals(key); | 237 return kv->Equals(key); |
225 } | 238 } |
226 }; | 239 }; |
227 | 240 |
228 } // namespace dart | 241 } // namespace dart |
229 | 242 |
230 #endif // VM_HASH_MAP_H_ | 243 #endif // VM_HASH_MAP_H_ |
OLD | NEW |