38 template<
class AllocationPolicy>
41 typedef bool (*
MatchFun) (
void* key1,
void* key2);
52 AllocationPolicy allocator = AllocationPolicy());
70 Entry*
Lookup(
void* key, uint32_t hash,
bool insert,
71 AllocationPolicy allocator = AllocationPolicy());
76 void*
Remove(
void* key, uint32_t hash);
87 uint32_t
capacity()
const {
return capacity_; }
98 Entry*
Next(Entry* p)
const;
106 Entry* map_end()
const {
return map_ + capacity_; }
107 Entry* Probe(
void* key, uint32_t hash);
108 void Initialize(uint32_t
capacity, AllocationPolicy allocator);
109 void Resize(AllocationPolicy allocator);
114 template<
class AllocationPolicy>
116 MatchFun match, uint32_t initial_capacity, AllocationPolicy allocator) {
118 Initialize(initial_capacity, allocator);
122 template<
class AllocationPolicy>
124 AllocationPolicy::Delete(map_);
128 template<
class AllocationPolicy>
131 void* key, uint32_t hash,
bool insert, AllocationPolicy allocator) {
133 Entry* p = Probe(key, hash);
146 if (occupancy_ + occupancy_/4 >= capacity_) {
148 p = Probe(key, hash);
159 template<
class AllocationPolicy>
162 Entry* p = Probe(key, hash);
168 void* value = p->
value;
183 ASSERT(occupancy_ < capacity_);
190 if (q == map_end()) {
202 Entry* r = map_ + (q->
hash & (capacity_ - 1));
207 if ((q > p && (r <= p || r > q)) ||
208 (q < p && (r <= p && r > q))) {
221 template<
class AllocationPolicy>
224 const Entry* end = map_end();
225 for (
Entry* p = map_; p < end; p++) {
232 template<
class AllocationPolicy>
235 return Next(map_ - 1);
239 template<
class AllocationPolicy>
242 const Entry* end = map_end();
243 ASSERT(map_ - 1 <= p && p < end);
244 for (p++; p < end; p++) {
253 template<
class AllocationPolicy>
259 Entry* p = map_ + (hash & (capacity_ - 1));
260 const Entry* end = map_end();
261 ASSERT(map_ <= p && p < end);
263 ASSERT(occupancy_ < capacity_);
264 while (p->key !=
NULL && (hash != p->hash || !match_(key, p->key))) {
275 template<
class AllocationPolicy>
276 void TemplateHashMapImpl<AllocationPolicy>::Initialize(
277 uint32_t capacity, AllocationPolicy allocator) {
279 map_ =
reinterpret_cast<Entry*
>(allocator.New(capacity *
sizeof(Entry)));
284 capacity_ = capacity;
289 template<
class AllocationPolicy>
290 void TemplateHashMapImpl<AllocationPolicy>::Resize(AllocationPolicy allocator) {
292 uint32_t n = occupancy_;
295 Initialize(capacity_ * 2, allocator);
298 for (Entry* p = map; n > 0; p++) {
299 if (p->key !=
NULL) {
300 Lookup(p->key, p->hash,
true, allocator)->value = p->value;
306 AllocationPolicy::Delete(map);
311 template<
class Key,
class Value,
class AllocationPolicy>
324 entry_ = map_->Next(entry_);
334 map_(map), entry_(entry) { }
344 AllocationPolicy allocator = AllocationPolicy())
350 Iterator
begin()
const {
return Iterator(
this, this->
Start()); }
351 Iterator
end()
const {
return Iterator(
this,
NULL); }
352 Iterator
find(Key* key,
bool insert =
false,
353 AllocationPolicy allocator = AllocationPolicy()) {
354 return Iterator(
this, this->
Lookup(key, key->Hash(), insert, allocator));
360 #endif // V8_HASHMAP_H_
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
Entry * Lookup(void *key, uint32_t hash, bool insert, AllocationPolicy allocator=AllocationPolicy())
STATIC_ASSERT(sizeof(Key *)==sizeof(void *))
void FatalProcessOutOfMemory(const char *message)
void * Remove(void *key, uint32_t hash)
TemplateHashMapImpl(MatchFun match, uint32_t capacity=kDefaultHashMapCapacity, AllocationPolicy allocator=AllocationPolicy())
TemplateHashMapImpl< FreeStoreAllocationPolicy > HashMap
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination trace on stack replacement optimize closures functions with arguments object optimize functions containing for in loops profiler considers IC stability primitive functions trigger their own optimization re try self optimization if it failed insert an interrupt check at function exit execution budget before interrupt is triggered call count before self optimization self_optimization count_based_interrupts weighted_back_edges trace_opt emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 enable use of ARMv7 instructions if enable use of MIPS FPU instructions if NULL
uint32_t capacity() const
bool(* MatchFun)(void *key1, void *key2)
static const uint32_t kDefaultHashMapCapacity
Entry * Next(Entry *p) const