mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 10:25:47 +02:00
chore: add defrag for StringSet (#4308)
* add defrag logic for StringSet * add test
This commit is contained in:
parent
d88bdb8bc3
commit
fbd785cbc7
4 changed files with 103 additions and 2 deletions
|
@ -276,6 +276,15 @@ pair<void*, bool> DefragSortedMap(detail::SortedMap* sm, float ratio) {
|
|||
return {sm, reallocated};
|
||||
}
|
||||
|
||||
pair<void*, bool> DefragStrSet(StringSet* ss, float ratio) {
|
||||
bool realloced = false;
|
||||
|
||||
for (auto it = ss->begin(); it != ss->end(); ++it)
|
||||
realloced |= it.ReallocIfNeeded(ratio);
|
||||
|
||||
return {ss, realloced};
|
||||
}
|
||||
|
||||
// Iterates over allocations of internal hash data structures and re-allocates
|
||||
// them if their pages are underutilized.
|
||||
// Returns pointer to new object ptr and whether any re-allocations happened.
|
||||
|
@ -304,8 +313,7 @@ pair<void*, bool> DefragSet(unsigned encoding, void* ptr, float ratio) {
|
|||
}
|
||||
|
||||
case kEncodingStrMap2: {
|
||||
// Still not implemented
|
||||
return {ptr, false};
|
||||
return DefragStrSet((StringSet*)ptr, ratio);
|
||||
}
|
||||
|
||||
default:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue