| 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 #ifndef RUNTIME_PLATFORM_HASHMAP_H_ | 5 #ifndef RUNTIME_PLATFORM_HASHMAP_H_ |
| 6 #define RUNTIME_PLATFORM_HASHMAP_H_ | 6 #define RUNTIME_PLATFORM_HASHMAP_H_ |
| 7 | 7 |
| 8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 // If an entry with matching key is found, Lookup() | 56 // If an entry with matching key is found, Lookup() |
| 57 // returns that entry. If no matching entry is found, | 57 // returns that entry. If no matching entry is found, |
| 58 // but insert is set, a new entry is inserted with | 58 // but insert is set, a new entry is inserted with |
| 59 // corresponding key, key hash, and NULL value. | 59 // corresponding key, key hash, and NULL value. |
| 60 // Otherwise, NULL is returned. | 60 // Otherwise, NULL is returned. |
| 61 Entry* Lookup(void* key, uint32_t hash, bool insert); | 61 Entry* Lookup(void* key, uint32_t hash, bool insert); |
| 62 | 62 |
| 63 // Removes the entry with matching key. | 63 // Removes the entry with matching key. |
| 64 // |
| 65 // WARNING: This method cannot be called while iterating a `HashMap` |
| 66 // otherwise the iteration might step over elements! |
| 64 void Remove(void* key, uint32_t hash); | 67 void Remove(void* key, uint32_t hash); |
| 65 | 68 |
| 69 // Removes the entry and returns the next entry (in iteration order) after |
| 70 // this one. |
| 71 // |
| 72 // Usage instructions for removing elements during iteration: |
| 73 // |
| 74 // HashMap::Entry* current = map.Start(); |
| 75 // while (current != NULL) { |
| 76 // ... |
| 77 // if (condition) { |
| 78 // current = map.Remove(current); |
| 79 // } else { |
| 80 // current = map.Next(current); |
| 81 // } |
| 82 // } |
| 83 // |
| 84 Entry* Remove(Entry* entry); |
| 85 |
| 66 // Empties the hash map (occupancy() == 0), and calls the function 'clear' on | 86 // Empties the hash map (occupancy() == 0), and calls the function 'clear' on |
| 67 // each of the values if given. | 87 // each of the values if given. |
| 68 void Clear(ClearFun clear = NULL); | 88 void Clear(ClearFun clear = NULL); |
| 69 | 89 |
| 70 // The number of entries stored in the table. | 90 // The number of entries stored in the table. |
| 71 intptr_t size() const { return occupancy_; } | 91 intptr_t size() const { return occupancy_; } |
| 72 | 92 |
| 73 // The capacity of the table. The implementation | 93 // The capacity of the table. The implementation |
| 74 // makes sure that occupancy is at most 80% of | 94 // makes sure that occupancy is at most 80% of |
| 75 // the table capacity. | 95 // the table capacity. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 97 void Initialize(uint32_t capacity); | 117 void Initialize(uint32_t capacity); |
| 98 void Resize(); | 118 void Resize(); |
| 99 | 119 |
| 100 friend class IntSet; // From hashmap_test.cc | 120 friend class IntSet; // From hashmap_test.cc |
| 101 DISALLOW_COPY_AND_ASSIGN(HashMap); | 121 DISALLOW_COPY_AND_ASSIGN(HashMap); |
| 102 }; | 122 }; |
| 103 | 123 |
| 104 } // namespace dart | 124 } // namespace dart |
| 105 | 125 |
| 106 #endif // RUNTIME_PLATFORM_HASHMAP_H_ | 126 #endif // RUNTIME_PLATFORM_HASHMAP_H_ |
| OLD | NEW |