fix: make sure kvps are in a deterministic order

This commit is contained in:
Jan
2025-01-05 10:08:21 +00:00
parent 67fb11506c
commit cacccf64e1
3 changed files with 121 additions and 1 deletions

View File

@ -1,7 +1,9 @@
#include "KeyValuePairsCreator.h"
#include <algorithm>
#include <format>
#include <iostream>
#include <ranges>
CommonKeyValuePair::CommonKeyValuePair(std::string keyStr, std::string value)
: m_key_str(std::move(keyStr)),
@ -49,6 +51,23 @@ void KeyValuePairsCreator::Finalize(const ZoneDefinition& zoneDefinition)
}
}
}
std::ranges::sort(m_key_value_pairs,
[](const CommonKeyValuePair& v0, const CommonKeyValuePair& v1)
{
if (v0.m_key_str.has_value())
{
if (!v1.m_key_str.has_value())
return true;
return *v0.m_key_str < *v1.m_key_str;
}
if (!v1.m_key_hash.has_value())
return false;
return *v0.m_key_hash < *v1.m_key_hash;
});
}
std::vector<CommonKeyValuePair> KeyValuePairsCreator::GetFinalKeyValuePairs()

View File

@ -18,7 +18,7 @@ public:
std::string m_value;
};
class KeyValuePairsCreator : public IZoneAssetCreationState
class KeyValuePairsCreator final : public IZoneAssetCreationState
{
public:
void AddKeyValuePair(CommonKeyValuePair keyValuePair);