chore: add defrag for StringSet (#4308)

* add defrag logic for StringSet
* add test
This commit is contained in:
Kostas Kyrimis 2025-01-27 12:53:38 +02:00 committed by GitHub
parent d88bdb8bc3
commit fbd785cbc7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 103 additions and 2 deletions

View file

@ -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: