mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 02:15:45 +02:00
chore(DenseSet): defrag all links in a chain (#4019)
* add defrag for all nodes in a link chain * add tests --------- Signed-off-by: kostas <kostas@dragonflydb.io>
This commit is contained in:
parent
cc6fdd7fbf
commit
4859077122
4 changed files with 47 additions and 26 deletions
|
@ -840,4 +840,22 @@ 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue