1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 09:23:53 +00:00

Merge branch 'fix_index_ref_id_hash' into 'master'

Shift record type value for IndexRefId hash

See merge request OpenMW/openmw!2885
This commit is contained in:
psi29a 2023-04-02 21:52:29 +00:00
commit 0a791528bc
2 changed files with 17 additions and 1 deletions

View file

@ -196,6 +196,22 @@ namespace ESM
EXPECT_NE(stringRefId, formIdRefId); EXPECT_NE(stringRefId, formIdRefId);
} }
TEST(ESMRefIdTest, indexRefIdHashDiffersForDistinctValues)
{
const RefId a = RefId::index(static_cast<RecNameInts>(3), 1);
const RefId b = RefId::index(static_cast<RecNameInts>(3), 2);
std::hash<RefId> hash;
EXPECT_NE(hash(a), hash(b));
}
TEST(ESMRefIdTest, indexRefIdHashDiffersForDistinctRecords)
{
const RefId a = RefId::index(static_cast<RecNameInts>(1), 3);
const RefId b = RefId::index(static_cast<RecNameInts>(2), 3);
std::hash<RefId> hash;
EXPECT_NE(hash(a), hash(b));
}
struct ESMRefIdToStringTest : TestWithParam<std::pair<RefId, std::string>> struct ESMRefIdToStringTest : TestWithParam<std::pair<RefId, std::string>>
{ {
}; };

View file

@ -53,7 +53,7 @@ namespace std
{ {
std::size_t operator()(ESM::IndexRefId value) const noexcept std::size_t operator()(ESM::IndexRefId value) const noexcept
{ {
return std::hash<std::uint64_t>{}(static_cast<std::uint64_t>(value.mRecordType) | value.mValue); return std::hash<std::uint64_t>{}((static_cast<std::uint64_t>(value.mRecordType) << 32) | value.mValue);
} }
}; };
} }