5 #ifndef V8_OBJECTS_HASH_TABLE_H_ 6 #define V8_OBJECTS_HASH_TABLE_H_ 8 #include "src/base/compiler-specific.h" 9 #include "src/globals.h" 10 #include "src/objects/fixed-array.h" 11 #include "src/objects/smi.h" 14 #include "src/objects/object-macros.h" 55 template <
typename KeyT>
59 static inline RootIndex GetMapRootIndex();
60 static const bool kNeedsHoleCheck =
true;
66 class V8_EXPORT_PRIVATE
HashTableBase :
public NON_EXPORTED_BASE(FixedArray) {
69 inline int NumberOfElements()
const;
72 inline int NumberOfDeletedElements()
const;
75 inline int Capacity()
const;
79 inline void ElementAdded();
83 inline void ElementRemoved();
84 inline void ElementsRemoved(
int n);
88 static inline int ComputeCapacity(
int at_least_space_for);
92 return (n + n * n) >> 1;
95 static const int kNumberOfElementsIndex = 0;
96 static const int kNumberOfDeletedElementsIndex = 1;
97 static const int kCapacityIndex = 2;
98 static const int kPrefixStartIndex = 3;
101 static const int kNotFound = -1;
104 static const int kMinCapacity = 4;
108 inline void SetNumberOfElements(
int nof);
111 inline void SetNumberOfDeletedElements(
int nod);
115 DCHECK(base::bits::IsPowerOfTwo(size));
116 return (hash + GetProbeOffset(number)) & (size - 1);
120 return hash & (size - 1);
125 return (last + number) & (size - 1);
131 template <
typename Derived,
typename Shape>
134 typedef Shape ShapeT;
135 typedef typename Shape::Key Key;
139 Isolate* isolate,
int at_least_space_for,
140 PretenureFlag pretenure = NOT_TENURED,
141 MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY);
148 inline int FindEntry(
ReadOnlyRoots roots, Key key, int32_t hash);
149 int FindEntry(
Isolate* isolate, Key key);
161 Object* KeyAt(
int entry) {
return get(EntryToIndex(entry) + kEntryKeyIndex); }
163 static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize;
164 static const int kEntrySize = Shape::kEntrySize;
165 STATIC_ASSERT(kEntrySize > 0);
166 static const int kEntryKeyIndex = 0;
167 static const int kElementsStartOffset =
168 kHeaderSize + kElementsStartIndex * kTaggedSize;
172 static const int kMaxCapacity =
173 (FixedArray::kMaxLength - kElementsStartIndex) / kEntrySize;
176 static const int kMinShrinkCapacity = 16;
179 static const int kMaxRegularCapacity = 16384;
182 static constexpr
inline int EntryToIndex(
int entry) {
183 return (entry * kEntrySize) + kElementsStartIndex;
189 PretenureFlag pretenure = NOT_TENURED);
192 bool HasSufficientCapacityToAdd(
int number_of_additional_elements);
198 Isolate* isolate,
int capacity, PretenureFlag pretenure);
210 STATIC_ASSERT(EntryToIndex(kMaxRegularCapacity) < kMaxRegularLength);
211 STATIC_ASSERT(v8::base::bits::IsPowerOfTwo(kMaxRegularCapacity));
212 static const int kMaxRegularEntry = kMaxRegularCapacity / kEntrySize;
213 static const int kMaxRegularIndex = EntryToIndex(kMaxRegularEntry);
214 STATIC_ASSERT(OffsetOfElementAt(kMaxRegularIndex) <
215 kMaxRegularHeapObjectSize);
218 void SetCapacity(
int capacity) {
222 DCHECK_GT(capacity, 0);
223 DCHECK_LE(capacity, kMaxCapacity);
224 set(kCapacityIndex, Smi::FromInt(capacity));
236 void Rehash(
Isolate* isolate, Derived new_table);
247 virtual bool IsMatch(
Object* other) = 0;
252 uint32_t Hash()
const {
return hash_; }
270 static const int kPrefixSize = 0;
271 static const int kEntryValueIndex = 1;
272 static const int kEntrySize = 2;
273 static const bool kNeedsHoleCheck =
false;
276 template <
typename Derived,
typename Shape>
286 Object* ValueAt(
int entry);
306 static inline int EntryToValueIndex(
int entry) {
308 Shape::kEntryValueIndex;
313 void RemoveEntry(
int entry);
333 static inline RootIndex GetMapRootIndex();
356 static const int kPrefixSize = 0;
357 static const int kEntrySize = 1;
377 #include "src/objects/object-macros-undef.h" 379 #endif // V8_OBJECTS_HASH_TABLE_H_