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