OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 13748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13759 } | 13759 } |
13760 } | 13760 } |
13761 } | 13761 } |
13762 new_table->SetNumberOfElements(NumberOfElements()); | 13762 new_table->SetNumberOfElements(NumberOfElements()); |
13763 new_table->SetNumberOfDeletedElements(0); | 13763 new_table->SetNumberOfDeletedElements(0); |
13764 return new_table; | 13764 return new_table; |
13765 } | 13765 } |
13766 | 13766 |
13767 | 13767 |
13768 template<typename Shape, typename Key> | 13768 template<typename Shape, typename Key> |
| 13769 uint32_t HashTable<Shape, Key>::EntryForProbe(Key key, |
| 13770 Object* k, |
| 13771 int probe, |
| 13772 uint32_t expected) { |
| 13773 uint32_t hash = HashTable<Shape, Key>::HashForObject(key, k); |
| 13774 uint32_t capacity = Capacity(); |
| 13775 uint32_t entry = FirstProbe(hash, capacity); |
| 13776 for (int i = 1; i < probe; i++) { |
| 13777 if (entry == expected) return expected; |
| 13778 entry = NextProbe(entry, i, capacity); |
| 13779 } |
| 13780 return entry; |
| 13781 } |
| 13782 |
| 13783 |
| 13784 template<typename Shape, typename Key> |
| 13785 void HashTable<Shape, Key>::Swap(uint32_t entry1, |
| 13786 uint32_t entry2, |
| 13787 WriteBarrierMode mode) { |
| 13788 int index1 = EntryToIndex(entry1); |
| 13789 int index2 = EntryToIndex(entry2); |
| 13790 Object* temp[Shape::kEntrySize]; |
| 13791 for (int j = 0; j < Shape::kEntrySize; j++) { |
| 13792 temp[j] = get(index1 + j); |
| 13793 } |
| 13794 for (int j = 0; j < Shape::kEntrySize; j++) { |
| 13795 set(index1 + j, get(index2 + j), mode); |
| 13796 } |
| 13797 for (int j = 0; j < Shape::kEntrySize; j++) { |
| 13798 set(index2 + j, temp[j], mode); |
| 13799 } |
| 13800 } |
| 13801 |
| 13802 |
| 13803 template<typename Shape, typename Key> |
| 13804 void HashTable<Shape, Key>::Rehash(Key key) { |
| 13805 DisallowHeapAllocation no_gc; |
| 13806 WriteBarrierMode mode = GetWriteBarrierMode(no_gc); |
| 13807 uint32_t capacity = Capacity(); |
| 13808 bool done = false; |
| 13809 for (int probe = 1; !done; probe++) { |
| 13810 // All elements at entries given by one of the first _probe_ probes |
| 13811 // are placed correctly. Other elements might need to be moved. |
| 13812 done = true; |
| 13813 for (uint32_t current = 0; current < capacity; current++) { |
| 13814 Object* current_key = get(EntryToIndex(current)); |
| 13815 if (IsKey(current_key)) { |
| 13816 uint32_t target = EntryForProbe(key, current_key, probe, current); |
| 13817 if (current == target) continue; |
| 13818 Object* target_key = get(EntryToIndex(target)); |
| 13819 if (!IsKey(target_key) || |
| 13820 EntryForProbe(key, target_key, probe, target) != target) { |
| 13821 // Put the current element into the correct position. |
| 13822 Swap(current, target, mode); |
| 13823 // The other element will be processed on the next iteration. |
| 13824 current--; |
| 13825 } else { |
| 13826 // The place for the current element is occupied. Leave the element |
| 13827 // for the next probe. |
| 13828 done = false; |
| 13829 } |
| 13830 } |
| 13831 } |
| 13832 } |
| 13833 } |
| 13834 |
| 13835 |
| 13836 template<typename Shape, typename Key> |
13769 MaybeObject* HashTable<Shape, Key>::EnsureCapacity(int n, Key key) { | 13837 MaybeObject* HashTable<Shape, Key>::EnsureCapacity(int n, Key key) { |
13770 int capacity = Capacity(); | 13838 int capacity = Capacity(); |
13771 int nof = NumberOfElements() + n; | 13839 int nof = NumberOfElements() + n; |
13772 int nod = NumberOfDeletedElements(); | 13840 int nod = NumberOfDeletedElements(); |
13773 // Return if: | 13841 // Return if: |
13774 // 50% is still free after adding n elements and | 13842 // 50% is still free after adding n elements and |
13775 // at most 50% of the free elements are deleted elements. | 13843 // at most 50% of the free elements are deleted elements. |
13776 if (nod <= (capacity - nof) >> 1) { | 13844 if (nod <= (capacity - nof) >> 1) { |
13777 int needed_free = nof >> 1; | 13845 int needed_free = nof >> 1; |
13778 if (nof + needed_free <= capacity) return this; | 13846 if (nof + needed_free <= capacity) return this; |
(...skipping 2269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16048 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16116 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16049 static const char* error_messages_[] = { | 16117 static const char* error_messages_[] = { |
16050 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16118 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16051 }; | 16119 }; |
16052 #undef ERROR_MESSAGES_TEXTS | 16120 #undef ERROR_MESSAGES_TEXTS |
16053 return error_messages_[reason]; | 16121 return error_messages_[reason]; |
16054 } | 16122 } |
16055 | 16123 |
16056 | 16124 |
16057 } } // namespace v8::internal | 16125 } } // namespace v8::internal |
OLD | NEW |