mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 10:25:47 +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_;
|
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
|
} // namespace dfly
|
||||||
|
|
|
@ -202,11 +202,6 @@ class DenseSet {
|
||||||
|
|
||||||
void Advance();
|
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_;
|
DenseSet* owner_;
|
||||||
ChainVectorIterator curr_list_;
|
ChainVectorIterator curr_list_;
|
||||||
DensePtr* curr_entry_;
|
DensePtr* curr_entry_;
|
||||||
|
|
|
@ -164,23 +164,25 @@ pair<sds, bool> DuplicateEntryIfFragmented(void* obj, float ratio) {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
bool ScoreMap::iterator::ReallocIfNeeded(float ratio, std::function<void(sds, sds)> cb) {
|
bool ScoreMap::iterator::ReallocIfNeeded(float ratio, std::function<void(sds, sds)> cb) {
|
||||||
bool reallocated = false;
|
auto* ptr = curr_entry_;
|
||||||
auto body = [ratio, &cb, &reallocated](auto* ptr) {
|
|
||||||
auto* obj = ptr->GetObject();
|
if (ptr->IsLink()) {
|
||||||
auto [new_obj, duplicate] = DuplicateEntryIfFragmented(obj, ratio);
|
ptr = ptr->AsLink();
|
||||||
if (duplicate) {
|
}
|
||||||
if (cb) {
|
|
||||||
cb((sds)obj, (sds)new_obj);
|
DCHECK(!ptr->IsEmpty());
|
||||||
}
|
DCHECK(ptr->IsObject());
|
||||||
sdsfree((sds)obj);
|
|
||||||
ptr->SetObject(new_obj);
|
auto* obj = ptr->GetObject();
|
||||||
|
auto [new_obj, realloced] = DuplicateEntryIfFragmented(obj, ratio);
|
||||||
|
if (realloced) {
|
||||||
|
if (cb) {
|
||||||
|
cb((sds)obj, (sds)new_obj);
|
||||||
}
|
}
|
||||||
reallocated |= duplicate;
|
sdsfree((sds)obj);
|
||||||
};
|
ptr->SetObject(new_obj);
|
||||||
|
}
|
||||||
TraverseApply(curr_entry_, body);
|
return realloced;
|
||||||
|
|
||||||
return reallocated;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dfly
|
} // namespace dfly
|
||||||
|
|
|
@ -298,17 +298,19 @@ detail::SdsPair StringMap::iterator::BreakToPair(void* obj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StringMap::iterator::ReallocIfNeeded(float ratio) {
|
bool StringMap::iterator::ReallocIfNeeded(float ratio) {
|
||||||
bool reallocated = false;
|
auto* ptr = curr_entry_;
|
||||||
auto body = [this, ratio, &reallocated](auto* ptr) {
|
if (ptr->IsLink()) {
|
||||||
auto* obj = ptr->GetObject();
|
ptr = ptr->AsLink();
|
||||||
auto [new_obj, realloc] = static_cast<StringMap*>(owner_)->ReallocIfNeeded(obj, ratio);
|
}
|
||||||
ptr->SetObject(new_obj);
|
|
||||||
reallocated |= realloc;
|
|
||||||
};
|
|
||||||
|
|
||||||
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
|
} // namespace dfly
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue