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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // | 64 // |
65 // WARNING: This method cannot be called while iterating a `HashMap` | 65 // WARNING: This method cannot be called while iterating a `HashMap` |
66 // otherwise the iteration might step over elements! | 66 // otherwise the iteration might step over elements! |
67 void Remove(void* key, uint32_t hash); | 67 void Remove(void* key, uint32_t hash); |
68 | 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 | |
86 // Empties the hash map (occupancy() == 0), and calls the function 'clear' on | 69 // Empties the hash map (occupancy() == 0), and calls the function 'clear' on |
87 // each of the values if given. | 70 // each of the values if given. |
88 void Clear(ClearFun clear = NULL); | 71 void Clear(ClearFun clear = NULL); |
89 | 72 |
90 // The number of entries stored in the table. | 73 // The number of entries stored in the table. |
91 intptr_t size() const { return occupancy_; } | 74 intptr_t size() const { return occupancy_; } |
92 | 75 |
93 // The capacity of the table. The implementation | 76 // The capacity of the table. The implementation |
94 // makes sure that occupancy is at most 80% of | 77 // makes sure that occupancy is at most 80% of |
95 // the table capacity. | 78 // the table capacity. |
(...skipping 21 matching lines...) Expand all Loading... |
117 void Initialize(uint32_t capacity); | 100 void Initialize(uint32_t capacity); |
118 void Resize(); | 101 void Resize(); |
119 | 102 |
120 friend class IntSet; // From hashmap_test.cc | 103 friend class IntSet; // From hashmap_test.cc |
121 DISALLOW_COPY_AND_ASSIGN(HashMap); | 104 DISALLOW_COPY_AND_ASSIGN(HashMap); |
122 }; | 105 }; |
123 | 106 |
124 } // namespace dart | 107 } // namespace dart |
125 | 108 |
126 #endif // RUNTIME_PLATFORM_HASHMAP_H_ | 109 #endif // RUNTIME_PLATFORM_HASHMAP_H_ |
OLD | NEW |