38 template<
class AllocationPolicy>
41 typedef bool (*
MatchFun) (
void* key1,
void* key2);
52 AllocationPolicy allocator = AllocationPolicy());
71 Entry*
Lookup(
void* key, uint32_t hash,
bool insert,
72 AllocationPolicy allocator = AllocationPolicy());
77 void*
Remove(
void* key, uint32_t hash);
88 uint32_t
capacity()
const {
return capacity_; }
99 Entry*
Next(Entry* p)
const;
107 Entry* map_end()
const {
return map_ + capacity_; }
108 Entry* Probe(
void* key, uint32_t hash);
109 void Initialize(uint32_t
capacity, AllocationPolicy allocator);
110 void Resize(AllocationPolicy allocator);
115 template<
class AllocationPolicy>
117 MatchFun match, uint32_t initial_capacity, AllocationPolicy allocator) {
119 Initialize(initial_capacity, allocator);
123 template<
class AllocationPolicy>
125 AllocationPolicy::Delete(map_);
129 template<
class AllocationPolicy>
132 void* key, uint32_t hash,
bool insert, AllocationPolicy allocator) {
134 Entry* p = Probe(key, hash);
144 p->
order = occupancy_;
148 if (occupancy_ + occupancy_/4 >= capacity_) {
150 p = Probe(key, hash);
161 template<
class AllocationPolicy>
164 Entry* p = Probe(key, hash);
170 void* value = p->
value;
185 ASSERT(occupancy_ < capacity_);
192 if (q == map_end()) {
204 Entry* r = map_ + (q->
hash & (capacity_ - 1));
209 if ((q > p && (r <= p || r > q)) ||
210 (q < p && (r <= p && r > q))) {
223 template<
class AllocationPolicy>
226 const Entry* end = map_end();
227 for (
Entry* p = map_; p < end; p++) {
234 template<
class AllocationPolicy>
237 return Next(map_ - 1);
241 template<
class AllocationPolicy>
244 const Entry* end = map_end();
245 ASSERT(map_ - 1 <= p && p < end);
246 for (p++; p < end; p++) {
255 template<
class AllocationPolicy>
261 Entry* p = map_ + (hash & (capacity_ - 1));
262 const Entry* end = map_end();
263 ASSERT(map_ <= p && p < end);
265 ASSERT(occupancy_ < capacity_);
266 while (p->key !=
NULL && (hash != p->hash || !match_(key, p->key))) {
277 template<
class AllocationPolicy>
278 void TemplateHashMapImpl<AllocationPolicy>::Initialize(
279 uint32_t capacity, AllocationPolicy allocator) {
281 map_ =
reinterpret_cast<Entry*
>(allocator.New(capacity *
sizeof(Entry)));
286 capacity_ = capacity;
291 template<
class AllocationPolicy>
292 void TemplateHashMapImpl<AllocationPolicy>::Resize(AllocationPolicy allocator) {
294 uint32_t n = occupancy_;
297 Initialize(capacity_ * 2, allocator);
300 for (Entry* p = map; n > 0; p++) {
301 if (p->key !=
NULL) {
302 Entry* entry = Lookup(p->key, p->hash,
true, allocator);
303 entry->value = p->value;
304 entry->order = p->order;
310 AllocationPolicy::Delete(map);
315 template<
class Key,
class Value,
class AllocationPolicy>
328 entry_ = map_->Next(entry_);
338 map_(map), entry_(entry) { }
348 AllocationPolicy allocator = AllocationPolicy())
354 Iterator
begin()
const {
return Iterator(
this, this->
Start()); }
355 Iterator
end()
const {
return Iterator(
this,
NULL); }
356 Iterator
find(Key* key,
bool insert =
false,
357 AllocationPolicy allocator = AllocationPolicy()) {
358 return Iterator(
this, this->
Lookup(key, key->Hash(), insert, allocator));
364 #endif // V8_HASHMAP_H_
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf map
bool operator!=(const Iterator &other)
Iterator find(Key *key, bool insert=false, AllocationPolicy allocator=AllocationPolicy())
#define ASSERT(condition)
value_type * operator->()
TemplateHashMap(typename TemplateHashMapImpl< AllocationPolicy >::MatchFun match, AllocationPolicy allocator=AllocationPolicy())
uint32_t occupancy() const
void FatalProcessOutOfMemory(const char *message)
Entry * Lookup(void *key, uint32_t hash, bool insert, AllocationPolicy allocator=AllocationPolicy())
STATIC_ASSERT(sizeof(Key *)==sizeof(void *))
void * Remove(void *key, uint32_t hash)
TemplateHashMapImpl(MatchFun match, uint32_t capacity=kDefaultHashMapCapacity, AllocationPolicy allocator=AllocationPolicy())
TemplateHashMapImpl< FreeStoreAllocationPolicy > HashMap
uint32_t capacity() const
bool(* MatchFun)(void *key1, void *key2)
static const uint32_t kDefaultHashMapCapacity
Entry * Next(Entry *p) const