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_
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
uint32_t capacity() const
bool(* MatchFun)(void *key1, void *key2)
static const uint32_t kDefaultHashMapCapacity
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 use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra 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 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
Entry * Next(Entry *p) const