diff --git a/src/core/dense_set.cc b/src/core/dense_set.cc index ef2281588..05df23938 100644 --- a/src/core/dense_set.cc +++ b/src/core/dense_set.cc @@ -184,7 +184,7 @@ void DenseSet::ClearInternal() { entries_.clear(); num_used_buckets_ = 0; - num_chain_entries_ = 0; + num_links_ = 0; size_ = 0; expiration_used_ = false; } @@ -426,10 +426,6 @@ void DenseSet::AddUnique(void* obj, bool has_ttl, uint64_t hashcode) { bucket_id -= unlinked.GetDisplacedDirection(); } - if (!entries_[bucket_id].IsEmpty()) { - ++num_chain_entries_; - } - DCHECK_EQ(BucketId(to_insert.GetObject(), 0), bucket_id); ChainVectorIterator list = entries_.begin() + bucket_id; PushFront(list, to_insert); @@ -497,7 +493,6 @@ void DenseSet::Delete(DensePtr* prev, DensePtr* ptr) { } else { DCHECK(prev->IsLink()); - --num_chain_entries_; DenseLinkKey* plink = prev->AsLink(); DensePtr tmp = DensePtr::From(plink); DCHECK(ObjectAllocSize(tmp.GetObject())); @@ -512,7 +507,6 @@ void DenseSet::Delete(DensePtr* prev, DensePtr* ptr) { DenseLinkKey* link = ptr->AsLink(); obj = link->Raw(); *ptr = link->next; - --num_chain_entries_; FreeLink(link); } @@ -538,10 +532,7 @@ void* DenseSet::PopInternal() { ExpireIfNeeded(nullptr, &(*bucket_iter)); } while (bucket_iter->IsEmpty()); - if (bucket_iter->IsLink()) { - --num_chain_entries_; - } else { - DCHECK(bucket_iter->IsObject()); + if (bucket_iter->IsObject()) { --num_used_buckets_; } @@ -663,6 +654,8 @@ auto DenseSet::NewLink(void* data, DensePtr next) -> DenseLinkKey* { lk->next = next; lk->SetObject(data); + ++num_links_; + return lk; } diff --git a/src/core/dense_set.h b/src/core/dense_set.h index 0c55287b7..3b788327c 100644 --- a/src/core/dense_set.h +++ b/src/core/dense_set.h @@ -227,11 +227,6 @@ class DenseSet { return entries_.size(); } - // those that are chained to the entries stored inline in the bucket array. - size_t NumChainEntries() const { - return num_chain_entries_; - } - size_t NumUsedBuckets() const { return num_used_buckets_; } @@ -241,7 +236,7 @@ class DenseSet { } size_t SetMallocUsed() const { - return (num_chain_entries_ + entries_.capacity()) * sizeof(DensePtr); + return entries_.capacity() * sizeof(DensePtr) + num_links_ * sizeof(DenseLinkKey); } using ItemCb = std::function; @@ -344,7 +339,8 @@ class DenseSet { // return a ChainVectorIterator (a.k.a iterator) or end if there is an empty chain found ChainVectorIterator FindEmptyAround(uint32_t bid); - // return if bucket has no item which is not displaced and right/left bucket has no displaced item + + // Return if bucket has no item which is not displaced and right/left bucket has no displaced item // belong to given bid bool NoItemBelongsBucket(uint32_t bid) const; void Grow(size_t prev_size); @@ -376,6 +372,7 @@ class DenseSet { inline void FreeLink(DenseLinkKey* plink) { // deallocate the link if it is no longer a link as it is now in an empty list mr()->deallocate(plink, sizeof(DenseLinkKey), alignof(DenseLinkKey)); + --num_links_; } // Returns true if *node was deleted. @@ -395,9 +392,9 @@ class DenseSet { std::vector entries_; mutable size_t obj_malloc_used_ = 0; - mutable uint32_t size_ = 0; - mutable uint32_t num_chain_entries_ = 0; - mutable uint32_t num_used_buckets_ = 0; + mutable uint32_t size_ = 0; // number of elements in the set. + mutable uint32_t num_links_ = 0; // number of links in the set. + mutable uint32_t num_used_buckets_ = 0; // number of buckets used in entries_ array. unsigned capacity_log_ = 0; uint32_t time_now_ = 0;