mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-10 18:05:44 +02:00
fix: remove DenseSet::IteratorBase::TraverseApply (#4170)
Signed-off-by: kostas <kostas@dragonflydb.io>
This commit is contained in:
parent
b8c2dd888a
commit
a012539f2c
4 changed files with 29 additions and 48 deletions
|
@ -840,22 +840,4 @@ size_t DenseSet::SizeSlow() {
|
|||
return size_;
|
||||
}
|
||||
|
||||
size_t DenseSet::IteratorBase::TraverseApply(DensePtr* ptr, std::function<void(DensePtr*)> fun) {
|
||||
size_t links_traversed = 0;
|
||||
while (ptr->IsLink()) {
|
||||
DenseLinkKey* link = ptr->AsLink();
|
||||
fun(link);
|
||||
ptr = &link->next;
|
||||
++links_traversed;
|
||||
}
|
||||
|
||||
// The last ptr in the link always returns ptr->IsLink() = false
|
||||
DCHECK(!ptr->IsEmpty());
|
||||
DCHECK(ptr->IsObject());
|
||||
fun(ptr);
|
||||
++links_traversed;
|
||||
|
||||
return links_traversed;
|
||||
}
|
||||
|
||||
} // namespace dfly
|
||||
|
|
|
@ -202,11 +202,6 @@ class DenseSet {
|
|||
|
||||
void Advance();
|
||||
|
||||
// If ptr is a link, it calls fun on all links in the chain.
|
||||
// Otherwise it calls it only once on the object.
|
||||
// ptr must be non empty.
|
||||
size_t TraverseApply(DensePtr* ptr, std::function<void(DensePtr*)> fun);
|
||||
|
||||
DenseSet* owner_;
|
||||
ChainVectorIterator curr_list_;
|
||||
DensePtr* curr_entry_;
|
||||
|
|
|
@ -164,23 +164,25 @@ pair<sds, bool> DuplicateEntryIfFragmented(void* obj, float ratio) {
|
|||
} // namespace
|
||||
|
||||
bool ScoreMap::iterator::ReallocIfNeeded(float ratio, std::function<void(sds, sds)> cb) {
|
||||
bool reallocated = false;
|
||||
auto body = [ratio, &cb, &reallocated](auto* ptr) {
|
||||
auto* obj = ptr->GetObject();
|
||||
auto [new_obj, duplicate] = DuplicateEntryIfFragmented(obj, ratio);
|
||||
if (duplicate) {
|
||||
if (cb) {
|
||||
cb((sds)obj, (sds)new_obj);
|
||||
}
|
||||
sdsfree((sds)obj);
|
||||
ptr->SetObject(new_obj);
|
||||
auto* ptr = curr_entry_;
|
||||
|
||||
if (ptr->IsLink()) {
|
||||
ptr = ptr->AsLink();
|
||||
}
|
||||
|
||||
DCHECK(!ptr->IsEmpty());
|
||||
DCHECK(ptr->IsObject());
|
||||
|
||||
auto* obj = ptr->GetObject();
|
||||
auto [new_obj, realloced] = DuplicateEntryIfFragmented(obj, ratio);
|
||||
if (realloced) {
|
||||
if (cb) {
|
||||
cb((sds)obj, (sds)new_obj);
|
||||
}
|
||||
reallocated |= duplicate;
|
||||
};
|
||||
|
||||
TraverseApply(curr_entry_, body);
|
||||
|
||||
return reallocated;
|
||||
sdsfree((sds)obj);
|
||||
ptr->SetObject(new_obj);
|
||||
}
|
||||
return realloced;
|
||||
}
|
||||
|
||||
} // namespace dfly
|
||||
|
|
|
@ -298,17 +298,19 @@ detail::SdsPair StringMap::iterator::BreakToPair(void* obj) {
|
|||
}
|
||||
|
||||
bool StringMap::iterator::ReallocIfNeeded(float ratio) {
|
||||
bool reallocated = false;
|
||||
auto body = [this, ratio, &reallocated](auto* ptr) {
|
||||
auto* obj = ptr->GetObject();
|
||||
auto [new_obj, realloc] = static_cast<StringMap*>(owner_)->ReallocIfNeeded(obj, ratio);
|
||||
ptr->SetObject(new_obj);
|
||||
reallocated |= realloc;
|
||||
};
|
||||
auto* ptr = curr_entry_;
|
||||
if (ptr->IsLink()) {
|
||||
ptr = ptr->AsLink();
|
||||
}
|
||||
|
||||
TraverseApply(curr_entry_, body);
|
||||
DCHECK(!ptr->IsEmpty());
|
||||
DCHECK(ptr->IsObject());
|
||||
|
||||
return reallocated;
|
||||
auto* obj = ptr->GetObject();
|
||||
auto [new_obj, realloced] = static_cast<StringMap*>(owner_)->ReallocIfNeeded(obj, ratio);
|
||||
ptr->SetObject(new_obj);
|
||||
|
||||
return realloced;
|
||||
}
|
||||
|
||||
} // namespace dfly
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue