OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // Otherwise, NULL is returned. | 76 // Otherwise, NULL is returned. |
77 Entry* Lookup(void* key, uint32_t hash, bool insert); | 77 Entry* Lookup(void* key, uint32_t hash, bool insert); |
78 | 78 |
79 // Removes the entry with matching key. | 79 // Removes the entry with matching key. |
80 void Remove(void* key, uint32_t hash); | 80 void Remove(void* key, uint32_t hash); |
81 | 81 |
82 // Empties the hash map (occupancy() == 0). | 82 // Empties the hash map (occupancy() == 0). |
83 void Clear(); | 83 void Clear(); |
84 | 84 |
85 // The number of (non-empty) entries in the table. | 85 // The number of (non-empty) entries in the table. |
86 uint32_t occupancy() const { return occupancy_; } | 86 uint32_t occupancy() const { return occupancy_; } |
87 | 87 |
88 // The capacity of the table. The implementation | 88 // The capacity of the table. The implementation |
89 // makes sure that occupancy is at most 80% of | 89 // makes sure that occupancy is at most 80% of |
90 // the table capacity. | 90 // the table capacity. |
91 uint32_t capacity() const { return capacity_; } | 91 uint32_t capacity() const { return capacity_; } |
92 | 92 |
93 // Iteration | 93 // Iteration |
94 // | 94 // |
95 // for (Entry* p = map.Start(); p != NULL; p = map.Next(p)) { | 95 // for (Entry* p = map.Start(); p != NULL; p = map.Next(p)) { |
96 // ... | 96 // ... |
97 // } | 97 // } |
98 // | 98 // |
99 // If entries are inserted during iteration, the effect of | 99 // If entries are inserted during iteration, the effect of |
100 // calling Next() is undefined. | 100 // calling Next() is undefined. |
101 Entry* Start() const; | 101 Entry* Start() const; |
102 Entry* Next(Entry* p) const; | 102 Entry* Next(Entry* p) const; |
103 | 103 |
104 private: | 104 private: |
105 Allocator* allocator_; | 105 Allocator* allocator_; |
106 MatchFun match_; | 106 MatchFun match_; |
107 Entry* map_; | 107 Entry* map_; |
108 uint32_t capacity_; | 108 uint32_t capacity_; |
109 uint32_t occupancy_; | 109 uint32_t occupancy_; |
110 | 110 |
111 Entry* map_end() const { return map_ + capacity_; } | 111 Entry* map_end() const { return map_ + capacity_; } |
112 Entry* Probe(void* key, uint32_t hash); | 112 Entry* Probe(void* key, uint32_t hash); |
113 void Initialize(uint32_t capacity); | 113 void Initialize(uint32_t capacity); |
114 void Resize(); | 114 void Resize(); |
115 }; | 115 }; |
116 | 116 |
117 | 117 |
118 } } // namespace v8::internal | 118 } } // namespace v8::internal |
119 | 119 |
120 #endif // V8_HASHMAP_H_ | 120 #endif // V8_HASHMAP_H_ |
OLD | NEW |