OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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_TABLE_H_ | 5 #ifndef VM_HASH_TABLE_H_ |
6 #define VM_HASH_TABLE_H_ | 6 #define VM_HASH_TABLE_H_ |
7 | 7 |
8 // Temporarily used when sorting the indices in EnumIndexHashTable. | 8 // Temporarily used when sorting the indices in EnumIndexHashTable. |
9 // TODO(koda): Remove these dependencies before using in production. | 9 // TODO(koda): Remove these dependencies before using in production. |
10 #include <map> | 10 #include <map> |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 bool Remove(const Key& key) const { | 555 bool Remove(const Key& key) const { |
556 intptr_t entry = BaseIterTable::FindKey(key); | 556 intptr_t entry = BaseIterTable::FindKey(key); |
557 if (entry == -1) { | 557 if (entry == -1) { |
558 return false; | 558 return false; |
559 } else { | 559 } else { |
560 BaseIterTable::DeleteEntry(entry); | 560 BaseIterTable::DeleteEntry(entry); |
561 return true; | 561 return true; |
562 } | 562 } |
563 } | 563 } |
564 | 564 |
| 565 void Clear() const { |
| 566 BaseIterTable::Initialize(); |
| 567 } |
| 568 |
565 protected: | 569 protected: |
566 void EnsureCapacity() const { | 570 void EnsureCapacity() const { |
567 static const double kMaxLoadFactor = 0.75; | 571 static const double kMaxLoadFactor = 0.75; |
| 572 // We currently never shrink. |
568 HashTables::EnsureLoadFactor(0.0, kMaxLoadFactor, *this); | 573 HashTables::EnsureLoadFactor(0.0, kMaxLoadFactor, *this); |
569 } | 574 } |
570 }; | 575 }; |
571 | 576 |
572 | 577 |
573 template<typename KeyTraits> | 578 template<typename KeyTraits> |
574 class UnorderedHashMap : public HashMap<UnorderedHashTable<KeyTraits, 1> > { | 579 class UnorderedHashMap : public HashMap<UnorderedHashTable<KeyTraits, 1> > { |
575 public: | 580 public: |
576 typedef HashMap<UnorderedHashTable<KeyTraits, 1> > BaseMap; | 581 typedef HashMap<UnorderedHashTable<KeyTraits, 1> > BaseMap; |
577 explicit UnorderedHashMap(RawArray* data) : BaseMap(data) {} | 582 explicit UnorderedHashMap(RawArray* data) : BaseMap(data) {} |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 bool Remove(const Key& key) const { | 649 bool Remove(const Key& key) const { |
645 intptr_t entry = BaseIterTable::FindKey(key); | 650 intptr_t entry = BaseIterTable::FindKey(key); |
646 if (entry == -1) { | 651 if (entry == -1) { |
647 return false; | 652 return false; |
648 } else { | 653 } else { |
649 BaseIterTable::DeleteEntry(entry); | 654 BaseIterTable::DeleteEntry(entry); |
650 return true; | 655 return true; |
651 } | 656 } |
652 } | 657 } |
653 | 658 |
| 659 void Clear() const { |
| 660 BaseIterTable::Initialize(); |
| 661 } |
| 662 |
654 protected: | 663 protected: |
655 void EnsureCapacity() const { | 664 void EnsureCapacity() const { |
656 static const double kMaxLoadFactor = 0.75; | 665 static const double kMaxLoadFactor = 0.75; |
| 666 // We currently never shrink. |
657 HashTables::EnsureLoadFactor(0.0, kMaxLoadFactor, *this); | 667 HashTables::EnsureLoadFactor(0.0, kMaxLoadFactor, *this); |
658 } | 668 } |
659 }; | 669 }; |
660 | 670 |
661 | 671 |
662 template<typename KeyTraits> | 672 template<typename KeyTraits> |
663 class UnorderedHashSet : public HashSet<UnorderedHashTable<KeyTraits, 0> > { | 673 class UnorderedHashSet : public HashSet<UnorderedHashTable<KeyTraits, 0> > { |
664 public: | 674 public: |
665 typedef HashSet<UnorderedHashTable<KeyTraits, 0> > BaseSet; | 675 typedef HashSet<UnorderedHashTable<KeyTraits, 0> > BaseSet; |
666 explicit UnorderedHashSet(RawArray* data) : BaseSet(data) {} | 676 explicit UnorderedHashSet(RawArray* data) : BaseSet(data) {} |
667 UnorderedHashSet(Isolate* isolate, RawArray* data) : BaseSet(isolate, data) {} | 677 UnorderedHashSet(Isolate* isolate, RawArray* data) : BaseSet(isolate, data) {} |
668 }; | 678 }; |
669 | 679 |
670 | 680 |
671 template<typename KeyTraits> | 681 template<typename KeyTraits> |
672 class EnumIndexHashSet : public HashSet<EnumIndexHashTable<KeyTraits, 0> > { | 682 class EnumIndexHashSet : public HashSet<EnumIndexHashTable<KeyTraits, 0> > { |
673 public: | 683 public: |
674 typedef HashSet<EnumIndexHashTable<KeyTraits, 0> > BaseSet; | 684 typedef HashSet<EnumIndexHashTable<KeyTraits, 0> > BaseSet; |
675 explicit EnumIndexHashSet(RawArray* data) : BaseSet(data) {} | 685 explicit EnumIndexHashSet(RawArray* data) : BaseSet(data) {} |
676 EnumIndexHashSet(Isolate* isolate, RawArray* data) : BaseSet(isolate, data) {} | 686 EnumIndexHashSet(Isolate* isolate, RawArray* data) : BaseSet(isolate, data) {} |
677 }; | 687 }; |
678 | 688 |
679 } // namespace dart | 689 } // namespace dart |
680 | 690 |
681 #endif // VM_HASH_TABLE_H_ | 691 #endif // VM_HASH_TABLE_H_ |
OLD | NEW |