| Index: compiled/Map.h |
| =================================================================== |
| --- a/compiled/Map.h |
| +++ b/compiled/Map.h |
| @@ -144,19 +144,17 @@ |
| void resize(size_type bucketCount) |
| { |
| std::unique_ptr<entry_type[]> oldBuckets(std::move(mBuckets)); |
| size_type oldCount = mBucketCount; |
| mEntryCount = 0; |
| mBucketCount = bucketCount; |
| - mBuckets.reset(new entry_type[mBucketCount]); |
| - // Working around https://github.com/waywardmonkeys/emscripten-trace-collector/issues/2 here |
| - annotate_address(reinterpret_cast<size_type*>(mBuckets.get()) - 1, "Hash table buffer"); |
| + allocate(); |
| // Copy old entries into the new buffer |
| for (size_type i = 0; i < oldCount; i++) |
| { |
| entry_type& entry = oldBuckets[i]; |
| if (!entry.is_invalid() && !entry.is_deleted()) |
| { |
| *find_bucket(entry.first) = entry; |
| @@ -178,28 +176,39 @@ |
| #if defined(DEBUG) |
| mInsertCounter++; |
| #endif |
| } |
| *existing = entry; |
| return existing; |
| } |
| + void allocate() |
| + { |
| + mBuckets.reset(new entry_type[mBucketCount]); |
| + // Working around https://github.com/waywardmonkeys/emscripten-trace-collector/issues/2 here |
| + annotate_address(reinterpret_cast<size_type*>(mBuckets.get()) - 1, "Hash table buffer"); |
| + } |
| + |
| public: |
| explicit HashContainer(size_type expectedEntries = 0) |
| : mEntryCount(0) |
| { |
| expectedEntries = ceil(expectedEntries / LOAD_FACTOR); |
| mBucketCount = MIN_BUCKETS; |
| while (mBucketCount < expectedEntries) |
| mBucketCount <<= 1; |
| - mBuckets.reset(new entry_type[mBucketCount]); |
| - // Working around https://github.com/waywardmonkeys/emscripten-trace-collector/issues/2 here |
| - annotate_address(reinterpret_cast<size_type*>(mBuckets.get()) - 1, "Hash table buffer"); |
| + allocate(); |
| + } |
| + |
| + void clear() |
| + { |
| + mEntryCount = 0; |
| + allocate(); |
| } |
| void insert(const entry_type& entry) |
| { |
| assign(find_bucket(entry.first), entry); |
| } |
| bool erase(const key_type& key) |
| @@ -222,16 +231,21 @@ |
| return const_iterator(&mBuckets[0], &mBuckets[mBucketCount]); |
| } |
| const_iterator end() const |
| { |
| return const_iterator(&mBuckets[mBucketCount], &mBuckets[mBucketCount]); |
| } |
| + bool empty() const |
| + { |
| + return mEntryCount == 0; |
| + } |
| + |
| size_type size() const |
| { |
| return mEntryCount; |
| } |
| }; |
| template<typename Entry> |
| struct MapReference : public HashContainerReference<Entry> |