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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 key_handle_(Object::Handle(zone_)), | 92 key_handle_(Object::Handle(zone_)), |
93 smi_handle_(Smi::Handle(zone_)), | 93 smi_handle_(Smi::Handle(zone_)), |
94 data_(&Array::Handle(zone_, data)), | 94 data_(&Array::Handle(zone_, data)), |
95 released_data_(NULL) {} | 95 released_data_(NULL) {} |
96 // Like above, except uses current zone. | 96 // Like above, except uses current zone. |
97 explicit HashTable(RawArray* data) | 97 explicit HashTable(RawArray* data) |
98 : zone_(Thread::Current()->zone()), | 98 : zone_(Thread::Current()->zone()), |
99 key_handle_(Object::Handle(zone_)), | 99 key_handle_(Object::Handle(zone_)), |
100 smi_handle_(Smi::Handle(zone_)), | 100 smi_handle_(Smi::Handle(zone_)), |
101 data_(&Array::Handle(zone_, data)), | 101 data_(&Array::Handle(zone_, data)), |
102 released_data_(NULL) {} | 102 released_data_(NULL) { |
| 103 ASSERT(!data_->IsNull()); |
| 104 } |
103 | 105 |
104 // Returns the final table. The handle is cleared when this HashTable is | 106 // Returns the final table. The handle is cleared when this HashTable is |
105 // destroyed. | 107 // destroyed. |
106 Array& Release() { | 108 Array& Release() { |
107 ASSERT(data_ != NULL); | 109 ASSERT(data_ != NULL); |
108 ASSERT(released_data_ == NULL); | 110 ASSERT(released_data_ == NULL); |
109 // Ensure that no methods are called after 'Release'. | 111 // Ensure that no methods are called after 'Release'. |
110 released_data_ = data_; | 112 released_data_ = data_; |
111 data_ = NULL; | 113 data_ = NULL; |
112 return *released_data_; | 114 return *released_data_; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 | 291 |
290 RawObject* InternalGetKey(intptr_t entry) const { | 292 RawObject* InternalGetKey(intptr_t entry) const { |
291 return data_->At(KeyIndex(entry)); | 293 return data_->At(KeyIndex(entry)); |
292 } | 294 } |
293 | 295 |
294 void InternalSetKey(intptr_t entry, const Object& key) const { | 296 void InternalSetKey(intptr_t entry, const Object& key) const { |
295 data_->SetAt(KeyIndex(entry), key); | 297 data_->SetAt(KeyIndex(entry), key); |
296 } | 298 } |
297 | 299 |
298 intptr_t GetSmiValueAt(intptr_t index) const { | 300 intptr_t GetSmiValueAt(intptr_t index) const { |
| 301 ASSERT(!data_->IsNull()); |
299 ASSERT(Object::Handle(zone(), data_->At(index)).IsSmi()); | 302 ASSERT(Object::Handle(zone(), data_->At(index)).IsSmi()); |
300 return Smi::Value(Smi::RawCast(data_->At(index))); | 303 return Smi::Value(Smi::RawCast(data_->At(index))); |
301 } | 304 } |
302 | 305 |
303 void SetSmiValueAt(intptr_t index, intptr_t value) const { | 306 void SetSmiValueAt(intptr_t index, intptr_t value) const { |
304 smi_handle_ = Smi::New(value); | 307 smi_handle_ = Smi::New(value); |
305 data_->SetAt(index, smi_handle_); | 308 data_->SetAt(index, smi_handle_); |
306 } | 309 } |
307 | 310 |
308 void AdjustSmiValueAt(intptr_t index, intptr_t delta) const { | 311 void AdjustSmiValueAt(intptr_t index, intptr_t delta) const { |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 // We currently never shrink. | 685 // We currently never shrink. |
683 HashTables::EnsureLoadFactor(0.0, kMaxLoadFactor, *this); | 686 HashTables::EnsureLoadFactor(0.0, kMaxLoadFactor, *this); |
684 } | 687 } |
685 }; | 688 }; |
686 | 689 |
687 | 690 |
688 template<typename KeyTraits> | 691 template<typename KeyTraits> |
689 class UnorderedHashSet : public HashSet<UnorderedHashTable<KeyTraits, 0> > { | 692 class UnorderedHashSet : public HashSet<UnorderedHashTable<KeyTraits, 0> > { |
690 public: | 693 public: |
691 typedef HashSet<UnorderedHashTable<KeyTraits, 0> > BaseSet; | 694 typedef HashSet<UnorderedHashTable<KeyTraits, 0> > BaseSet; |
692 explicit UnorderedHashSet(RawArray* data) : BaseSet(data) {} | 695 explicit UnorderedHashSet(RawArray* data) : BaseSet(data) { |
| 696 ASSERT(data != Array::null()); |
| 697 } |
693 UnorderedHashSet(Zone* zone, RawArray* data) : BaseSet(zone, data) {} | 698 UnorderedHashSet(Zone* zone, RawArray* data) : BaseSet(zone, data) {} |
694 }; | 699 }; |
695 | 700 |
696 | 701 |
697 template<typename KeyTraits> | 702 template<typename KeyTraits> |
698 class EnumIndexHashSet : public HashSet<EnumIndexHashTable<KeyTraits, 0> > { | 703 class EnumIndexHashSet : public HashSet<EnumIndexHashTable<KeyTraits, 0> > { |
699 public: | 704 public: |
700 typedef HashSet<EnumIndexHashTable<KeyTraits, 0> > BaseSet; | 705 typedef HashSet<EnumIndexHashTable<KeyTraits, 0> > BaseSet; |
701 explicit EnumIndexHashSet(RawArray* data) : BaseSet(data) {} | 706 explicit EnumIndexHashSet(RawArray* data) : BaseSet(data) {} |
702 EnumIndexHashSet(Zone* zone, RawArray* data) : BaseSet(zone, data) {} | 707 EnumIndexHashSet(Zone* zone, RawArray* data) : BaseSet(zone, data) {} |
703 }; | 708 }; |
704 | 709 |
705 } // namespace dart | 710 } // namespace dart |
706 | 711 |
707 #endif // VM_HASH_TABLE_H_ | 712 #endif // VM_HASH_TABLE_H_ |
OLD | NEW |