Index: compiled/Map.h |
=================================================================== |
--- a/compiled/Map.h |
+++ b/compiled/Map.h |
@@ -141,19 +141,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; |
@@ -175,28 +173,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(key_type_cref key) |
@@ -219,16 +228,21 @@ |
return const_iterator(&mBuckets[0], &mBuckets[mBucketCount]); |
} |
const_iterator end() const |
{ |
return const_iterator(&mBuckets[mBucketCount], &mBuckets[mBucketCount]); |
} |
+ bool empty() const |
sergei
2018/01/15 15:31:19
What about renaming of `empty` and `size` methods
hub
2018/01/16 02:57:39
I'm willing to not add empty() and use size() == 0
sergei
2018/01/16 16:43:58
As I see it's really used as
!((filter.GetDomains
|
+ { |
+ return mEntryCount == 0; |
+ } |
+ |
size_type size() const |
{ |
return mEntryCount; |
} |
}; |
template<typename Entry> |
struct MapReference : public HashContainerReference<Entry> |