| 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 #include "vm/growable_array.h" // For Malloc, EmptyBase | 8 #include "vm/growable_array.h" // For Malloc, EmptyBase |
| 9 #include "vm/zone.h" | 9 #include "vm/zone.h" |
| 10 | 10 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 const typename KeyValueTrait::Value kNoValue = | 161 const typename KeyValueTrait::Value kNoValue = |
| 162 KeyValueTrait::ValueOf(typename KeyValueTrait::Pair()); | 162 KeyValueTrait::ValueOf(typename KeyValueTrait::Pair()); |
| 163 typename KeyValueTrait::Pair* pair = Lookup(key); | 163 typename KeyValueTrait::Pair* pair = Lookup(key); |
| 164 return (pair == NULL) ? kNoValue : KeyValueTrait::ValueOf(*pair); | 164 return (pair == NULL) ? kNoValue : KeyValueTrait::ValueOf(*pair); |
| 165 } | 165 } |
| 166 | 166 |
| 167 | 167 |
| 168 template<typename KeyValueTrait, typename B, typename Allocator> | 168 template<typename KeyValueTrait, typename B, typename Allocator> |
| 169 typename KeyValueTrait::Pair* | 169 typename KeyValueTrait::Pair* |
| 170 BaseDirectChainedHashMap<KeyValueTrait, B, Allocator>::Iterator::Next() { | 170 BaseDirectChainedHashMap<KeyValueTrait, B, Allocator>::Iterator::Next() { |
| 171 const typename KeyValueTrait::Pair kNoPair = typename KeyValueTrait::Pair(); | 171 const typename KeyValueTrait::Value kNoValue = |
| 172 KeyValueTrait::ValueOf(typename KeyValueTrait::Pair()); |
| 172 | 173 |
| 173 if (array_index_ < map_.array_size_) { | 174 if (array_index_ < map_.array_size_) { |
| 174 // If we're not in the middle of a list, find the next array slot. | 175 // If we're not in the middle of a list, find the next array slot. |
| 175 if (list_index_ == kNil) { | 176 if (list_index_ == kNil) { |
| 176 while ((map_.array_[array_index_].kv == kNoPair) && | 177 while (KeyValueTrait::ValueOf(map_.array_[array_index_].kv) == kNoValue && |
| 177 (array_index_ < map_.array_size_)) { | 178 array_index_ < map_.array_size_) { |
| 178 array_index_++; | 179 array_index_++; |
| 179 } | 180 } |
| 180 if (array_index_ < map_.array_size_) { | 181 if (array_index_ < map_.array_size_) { |
| 181 // When we're done with the list, we'll continue with the next array | 182 // When we're done with the list, we'll continue with the next array |
| 182 // slot. | 183 // slot. |
| 183 const intptr_t old_array_index = array_index_; | 184 const intptr_t old_array_index = array_index_; |
| 184 array_index_++; | 185 array_index_++; |
| 185 list_index_ = map_.array_[old_array_index].next; | 186 list_index_ = map_.array_[old_array_index].next; |
| 186 return &map_.array_[old_array_index].kv; | 187 return &map_.array_[old_array_index].kv; |
| 187 } else { | 188 } else { |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 360 |
| 360 static intptr_t KeyOf(Pair kv) { return kv.first(); } | 361 static intptr_t KeyOf(Pair kv) { return kv.first(); } |
| 361 static T ValueOf(Pair kv) { return kv; } | 362 static T ValueOf(Pair kv) { return kv; } |
| 362 static inline intptr_t Hashcode(Key key) { return key; } | 363 static inline intptr_t Hashcode(Key key) { return key; } |
| 363 static inline bool IsKeyEqual(Pair kv, Key key) { return kv.first() == key; } | 364 static inline bool IsKeyEqual(Pair kv, Key key) { return kv.first() == key; } |
| 364 }; | 365 }; |
| 365 | 366 |
| 366 } // namespace dart | 367 } // namespace dart |
| 367 | 368 |
| 368 #endif // VM_HASH_MAP_H_ | 369 #endif // VM_HASH_MAP_H_ |
| OLD | NEW |