Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: src/hashmap.h

Issue 10031032: I'd like to add addr field into EntryInfo struct. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: style errors were fixed Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/profile-generator.h » ('j') | src/profile-generator.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 uint32_t hash; // the full hash value for key 55 uint32_t hash; // the full hash value for key
56 }; 56 };
57 57
58 // If an entry with matching key is found, Lookup() 58 // If an entry with matching key is found, Lookup()
59 // returns that entry. If no matching entry is found, 59 // returns that entry. If no matching entry is found,
60 // but insert is set, a new entry is inserted with 60 // but insert is set, a new entry is inserted with
61 // corresponding key, key hash, and NULL value. 61 // corresponding key, key hash, and NULL value.
62 // Otherwise, NULL is returned. 62 // Otherwise, NULL is returned.
63 Entry* Lookup(void* key, uint32_t hash, bool insert); 63 Entry* Lookup(void* key, uint32_t hash, bool insert);
64 64
65 // Removes the entry with matching key. 65 // Removes the entry with matching key.
mnaganov (inactive) 2012/04/10 21:12:04 Please update the comment.
66 void Remove(void* key, uint32_t hash); 66 void* Remove(void* key, uint32_t hash);
67 67
68 // Empties the hash map (occupancy() == 0). 68 // Empties the hash map (occupancy() == 0).
69 void Clear(); 69 void Clear();
70 70
71 // The number of (non-empty) entries in the table. 71 // The number of (non-empty) entries in the table.
72 uint32_t occupancy() const { return occupancy_; } 72 uint32_t occupancy() const { return occupancy_; }
73 73
74 // The capacity of the table. The implementation 74 // The capacity of the table. The implementation
75 // makes sure that occupancy is at most 80% of 75 // makes sure that occupancy is at most 80% of
76 // the table capacity. 76 // the table capacity.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 return p; 140 return p;
141 } 141 }
142 142
143 // No entry found and none inserted. 143 // No entry found and none inserted.
144 return NULL; 144 return NULL;
145 } 145 }
146 146
147 147
148 template<class P> 148 template<class P>
149 void TemplateHashMapImpl<P>::Remove(void* key, uint32_t hash) { 149 void* TemplateHashMapImpl<P>::Remove(void* key, uint32_t hash) {
150 // Lookup the entry for the key to remove. 150 // Lookup the entry for the key to remove.
151 Entry* p = Probe(key, hash); 151 Entry* p = Probe(key, hash);
152 if (p->key == NULL) { 152 if (p->key == NULL) {
153 // Key not found nothing to remove. 153 // Key not found nothing to remove.
154 return; 154 return NULL;
155 } 155 }
156 156
157 void* value = p->value;
157 // To remove an entry we need to ensure that it does not create an empty 158 // To remove an entry we need to ensure that it does not create an empty
158 // entry that will cause the search for another entry to stop too soon. If all 159 // entry that will cause the search for another entry to stop too soon. If all
159 // the entries between the entry to remove and the next empty slot have their 160 // the entries between the entry to remove and the next empty slot have their
160 // initial position inside this interval, clearing the entry to remove will 161 // initial position inside this interval, clearing the entry to remove will
161 // not break the search. If, while searching for the next empty entry, an 162 // not break the search. If, while searching for the next empty entry, an
162 // entry is encountered which does not have its initial position between the 163 // entry is encountered which does not have its initial position between the
163 // entry to remove and the position looked at, then this entry can be moved to 164 // entry to remove and the position looked at, then this entry can be moved to
164 // the place of the entry to remove without breaking the search for it. The 165 // the place of the entry to remove without breaking the search for it. The
165 // entry made vacant by this move is now the entry to remove and the process 166 // entry made vacant by this move is now the entry to remove and the process
166 // starts over. 167 // starts over.
(...skipping 28 matching lines...) Expand all
195 if ((q > p && (r <= p || r > q)) || 196 if ((q > p && (r <= p || r > q)) ||
196 (q < p && (r <= p && r > q))) { 197 (q < p && (r <= p && r > q))) {
197 *p = *q; 198 *p = *q;
198 p = q; 199 p = q;
199 } 200 }
200 } 201 }
201 202
202 // Clear the entry which is allowed to en emptied. 203 // Clear the entry which is allowed to en emptied.
203 p->key = NULL; 204 p->key = NULL;
204 occupancy_--; 205 occupancy_--;
206 return value;
205 } 207 }
206 208
207 209
208 template<class P> 210 template<class P>
209 void TemplateHashMapImpl<P>::Clear() { 211 void TemplateHashMapImpl<P>::Clear() {
210 // Mark all entries as empty. 212 // Mark all entries as empty.
211 const Entry* end = map_end(); 213 const Entry* end = map_end();
212 for (Entry* p = map_; p < end; p++) { 214 for (Entry* p = map_; p < end; p++) {
213 p->key = NULL; 215 p->key = NULL;
214 } 216 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 Iterator begin() const { return Iterator(this, this->Start()); } 333 Iterator begin() const { return Iterator(this, this->Start()); }
332 Iterator end() const { return Iterator(this, NULL); } 334 Iterator end() const { return Iterator(this, NULL); }
333 Iterator find(Key* key, bool insert = false) { 335 Iterator find(Key* key, bool insert = false) {
334 return Iterator(this, this->Lookup(key, key->Hash(), insert)); 336 return Iterator(this, this->Lookup(key, key->Hash(), insert));
335 } 337 }
336 }; 338 };
337 339
338 } } // namespace v8::internal 340 } } // namespace v8::internal
339 341
340 #endif // V8_HASHMAP_H_ 342 #endif // V8_HASHMAP_H_
OLDNEW
« no previous file with comments | « no previous file | src/profile-generator.h » ('j') | src/profile-generator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698