| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 void resize(size_type bucketCount) | 142 void resize(size_type bucketCount) |
| 143 { | 143 { |
| 144 std::unique_ptr<entry_type[]> oldBuckets(std::move(mBuckets)); | 144 std::unique_ptr<entry_type[]> oldBuckets(std::move(mBuckets)); |
| 145 size_type oldCount = mBucketCount; | 145 size_type oldCount = mBucketCount; |
| 146 | 146 |
| 147 mEntryCount = 0; | 147 mEntryCount = 0; |
| 148 mBucketCount = bucketCount; | 148 mBucketCount = bucketCount; |
| 149 mBuckets.reset(new entry_type[mBucketCount]); | 149 allocate(); |
| 150 // Working around https://github.com/waywardmonkeys/emscripten-trace-colle
ctor/issues/2 here | |
| 151 annotate_address(reinterpret_cast<size_type*>(mBuckets.get()) - 1, "Hash t
able buffer"); | |
| 152 | 150 |
| 153 // Copy old entries into the new buffer | 151 // Copy old entries into the new buffer |
| 154 for (size_type i = 0; i < oldCount; i++) | 152 for (size_type i = 0; i < oldCount; i++) |
| 155 { | 153 { |
| 156 entry_type& entry = oldBuckets[i]; | 154 entry_type& entry = oldBuckets[i]; |
| 157 if (!entry.is_invalid() && !entry.is_deleted()) | 155 if (!entry.is_invalid() && !entry.is_deleted()) |
| 158 { | 156 { |
| 159 *find_bucket(entry.first) = entry; | 157 *find_bucket(entry.first) = entry; |
| 160 mEntryCount++; | 158 mEntryCount++; |
| 161 } | 159 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 173 } | 171 } |
| 174 mEntryCount++; | 172 mEntryCount++; |
| 175 #if defined(DEBUG) | 173 #if defined(DEBUG) |
| 176 mInsertCounter++; | 174 mInsertCounter++; |
| 177 #endif | 175 #endif |
| 178 } | 176 } |
| 179 *existing = entry; | 177 *existing = entry; |
| 180 return existing; | 178 return existing; |
| 181 } | 179 } |
| 182 | 180 |
| 181 void allocate() |
| 182 { |
| 183 mBuckets.reset(new entry_type[mBucketCount]); |
| 184 // Working around https://github.com/waywardmonkeys/emscripten-trace-colle
ctor/issues/2 here |
| 185 annotate_address(reinterpret_cast<size_type*>(mBuckets.get()) - 1, "Hash t
able buffer"); |
| 186 } |
| 187 |
| 183 public: | 188 public: |
| 184 explicit HashContainer(size_type expectedEntries = 0) | 189 explicit HashContainer(size_type expectedEntries = 0) |
| 185 : mEntryCount(0) | 190 : mEntryCount(0) |
| 186 { | 191 { |
| 187 expectedEntries = ceil(expectedEntries / LOAD_FACTOR); | 192 expectedEntries = ceil(expectedEntries / LOAD_FACTOR); |
| 188 mBucketCount = MIN_BUCKETS; | 193 mBucketCount = MIN_BUCKETS; |
| 189 while (mBucketCount < expectedEntries) | 194 while (mBucketCount < expectedEntries) |
| 190 mBucketCount <<= 1; | 195 mBucketCount <<= 1; |
| 191 | 196 |
| 192 mBuckets.reset(new entry_type[mBucketCount]); | 197 allocate(); |
| 193 // Working around https://github.com/waywardmonkeys/emscripten-trace-colle
ctor/issues/2 here | 198 } |
| 194 annotate_address(reinterpret_cast<size_type*>(mBuckets.get()) - 1, "Hash t
able buffer"); | 199 |
| 200 void clear() |
| 201 { |
| 202 mEntryCount = 0; |
| 203 allocate(); |
| 195 } | 204 } |
| 196 | 205 |
| 197 void insert(const entry_type& entry) | 206 void insert(const entry_type& entry) |
| 198 { | 207 { |
| 199 assign(find_bucket(entry.first), entry); | 208 assign(find_bucket(entry.first), entry); |
| 200 } | 209 } |
| 201 | 210 |
| 202 bool erase(key_type_cref key) | 211 bool erase(key_type_cref key) |
| 203 { | 212 { |
| 204 entry_type* entry = find_bucket(key); | 213 entry_type* entry = find_bucket(key); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 const_reference find(key_type_cref key) const | 314 const_reference find(key_type_cref key) const |
| 306 { | 315 { |
| 307 return super::find(key); | 316 return super::find(key); |
| 308 } | 317 } |
| 309 | 318 |
| 310 reference find(key_type_cref key) | 319 reference find(key_type_cref key) |
| 311 { | 320 { |
| 312 return reference(this, key, super::find_bucket(key)); | 321 return reference(this, key, super::find_bucket(key)); |
| 313 } | 322 } |
| 314 }; | 323 }; |
| OLD | NEW |