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_VM_HASH_MAP_H_ | 5 #ifndef RUNTIME_VM_HASH_MAP_H_ |
6 #define RUNTIME_VM_HASH_MAP_H_ | 6 #define RUNTIME_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 21 matching lines...) Expand all Loading... |
32 allocator_->template Free<HashMapListElement>(lists_, lists_size_); | 32 allocator_->template Free<HashMapListElement>(lists_, lists_size_); |
33 } | 33 } |
34 | 34 |
35 void Insert(typename KeyValueTrait::Pair kv); | 35 void Insert(typename KeyValueTrait::Pair kv); |
36 bool Remove(typename KeyValueTrait::Key key); | 36 bool Remove(typename KeyValueTrait::Key key); |
37 | 37 |
38 typename KeyValueTrait::Value LookupValue( | 38 typename KeyValueTrait::Value LookupValue( |
39 typename KeyValueTrait::Key key) const; | 39 typename KeyValueTrait::Key key) const; |
40 | 40 |
41 typename KeyValueTrait::Pair* Lookup(typename KeyValueTrait::Key key) const; | 41 typename KeyValueTrait::Pair* Lookup(typename KeyValueTrait::Key key) const; |
| 42 bool HasKey(typename KeyValueTrait::Key key) const { |
| 43 return Lookup(key) != NULL; |
| 44 } |
42 | 45 |
43 bool IsEmpty() const { return count_ == 0; } | 46 bool IsEmpty() const { return count_ == 0; } |
44 | 47 |
45 virtual void Clear() { | 48 virtual void Clear() { |
46 if (!IsEmpty()) { | 49 if (!IsEmpty()) { |
47 count_ = 0; | 50 count_ = 0; |
48 InitArray(array_, array_size_); | 51 InitArray(array_, array_size_); |
49 InitArray(lists_, lists_size_); | 52 InitArray(lists_, lists_size_); |
50 lists_[0].next = kNil; | 53 lists_[0].next = kNil; |
51 for (intptr_t i = 1; i < lists_size_; ++i) { | 54 for (intptr_t i = 1; i < lists_size_; ++i) { |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 } | 374 } |
372 | 375 |
373 | 376 |
374 template <typename KeyValueTrait> | 377 template <typename KeyValueTrait> |
375 class DirectChainedHashMap | 378 class DirectChainedHashMap |
376 : public BaseDirectChainedHashMap<KeyValueTrait, ValueObject> { | 379 : public BaseDirectChainedHashMap<KeyValueTrait, ValueObject> { |
377 public: | 380 public: |
378 DirectChainedHashMap() | 381 DirectChainedHashMap() |
379 : BaseDirectChainedHashMap<KeyValueTrait, ValueObject>( | 382 : BaseDirectChainedHashMap<KeyValueTrait, ValueObject>( |
380 ASSERT_NOTNULL(Thread::Current()->zone())) {} | 383 ASSERT_NOTNULL(Thread::Current()->zone())) {} |
| 384 |
| 385 explicit DirectChainedHashMap(Zone* zone) |
| 386 : BaseDirectChainedHashMap<KeyValueTrait, ValueObject>( |
| 387 ASSERT_NOTNULL(zone)) {} |
381 }; | 388 }; |
382 | 389 |
383 | 390 |
384 template <typename KeyValueTrait> | 391 template <typename KeyValueTrait> |
385 class MallocDirectChainedHashMap | 392 class MallocDirectChainedHashMap |
386 : public BaseDirectChainedHashMap<KeyValueTrait, EmptyBase, Malloc> { | 393 : public BaseDirectChainedHashMap<KeyValueTrait, EmptyBase, Malloc> { |
387 public: | 394 public: |
388 MallocDirectChainedHashMap() | 395 MallocDirectChainedHashMap() |
389 : BaseDirectChainedHashMap<KeyValueTrait, EmptyBase, Malloc>(NULL) {} | 396 : BaseDirectChainedHashMap<KeyValueTrait, EmptyBase, Malloc>(NULL) {} |
390 }; | 397 }; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 | 444 |
438 static Key KeyOf(Pair kv) { return kv.key; } | 445 static Key KeyOf(Pair kv) { return kv.key; } |
439 static Value ValueOf(Pair kv) { return kv.value; } | 446 static Value ValueOf(Pair kv) { return kv.value; } |
440 static intptr_t Hashcode(Key key) { return reinterpret_cast<intptr_t>(key); } | 447 static intptr_t Hashcode(Key key) { return reinterpret_cast<intptr_t>(key); } |
441 static bool IsKeyEqual(Pair kv, Key key) { return kv.key == key; } | 448 static bool IsKeyEqual(Pair kv, Key key) { return kv.key == key; } |
442 }; | 449 }; |
443 | 450 |
444 } // namespace dart | 451 } // namespace dart |
445 | 452 |
446 #endif // RUNTIME_VM_HASH_MAP_H_ | 453 #endif // RUNTIME_VM_HASH_MAP_H_ |
OLD | NEW |