OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/hashmap.h" | 5 #include "platform/hashmap.h" |
6 | 6 |
7 #include "platform/utils.h" | 7 #include "platform/utils.h" |
8 | 8 |
9 namespace dart { | 9 namespace dart { |
10 | 10 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 candidate = next; | 103 candidate = next; |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 // Clear the candidate which will not break searching the hash table. | 107 // Clear the candidate which will not break searching the hash table. |
108 candidate->key = NULL; | 108 candidate->key = NULL; |
109 occupancy_--; | 109 occupancy_--; |
110 } | 110 } |
111 | 111 |
112 | 112 |
113 HashMap::Entry* HashMap::Remove(Entry* entry) { | |
114 Remove(entry->key, entry->hash); | |
115 | |
116 // A key can only exist once in the map and we just removed `key`. This means | |
117 // that either a left-rotation has happened (in which case `entry` points | |
118 // already to the next element (in terms of iteration order)) or alternatively | |
119 // we can use the normal `Next()` call to move in iteration order. | |
120 if (entry->key != NULL) { | |
121 // A left-rotation happened. `entry` points already to the next element in | |
122 // iteration order. | |
123 return entry; | |
124 } else { | |
125 return Next(entry); | |
126 } | |
127 } | |
128 | |
129 | |
130 void HashMap::Clear(ClearFun clear) { | 113 void HashMap::Clear(ClearFun clear) { |
131 // Mark all entries as empty. | 114 // Mark all entries as empty. |
132 const Entry* end = map_end(); | 115 const Entry* end = map_end(); |
133 for (Entry* p = map_; p < end; p++) { | 116 for (Entry* p = map_; p < end; p++) { |
134 if ((clear != NULL) && (p->key != NULL)) { | 117 if ((clear != NULL) && (p->key != NULL)) { |
135 clear(p->value); | 118 clear(p->value); |
136 } | 119 } |
137 p->key = NULL; | 120 p->key = NULL; |
138 } | 121 } |
139 occupancy_ = 0; | 122 occupancy_ = 0; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 Lookup(p->key, p->hash, true)->value = p->value; | 184 Lookup(p->key, p->hash, true)->value = p->value; |
202 n--; | 185 n--; |
203 } | 186 } |
204 } | 187 } |
205 | 188 |
206 // Delete old map. | 189 // Delete old map. |
207 delete[] map; | 190 delete[] map; |
208 } | 191 } |
209 | 192 |
210 } // namespace dart | 193 } // namespace dart |
OLD | NEW |