Merge pull request #416 from Laupetin/fix/t6-stringtable-cell-indices

fix: ignoring last element in t6 stringtable cell index sorting
This commit is contained in:
Jan 2025-04-23 08:08:33 +02:00 committed by GitHub
commit 82d38ab710
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 16 deletions

View File

@ -1942,7 +1942,7 @@ namespace T6
int columnCount;
int rowCount;
StringTableCell* values;
int16_t* cellIndex;
uint16_t* cellIndex;
};
enum LbUpdateType

View File

@ -112,7 +112,8 @@ namespace string_table
template<typename StringTableType, int (*HashFunc)(const char*)>
class StringTableLoaderV3 final : public AbstractStringTableLoader<StringTableType, std::remove_pointer_t<decltype(StringTableType::values)>>
{
using CellType_t = decltype(*StringTableType::values);
using CellType_t = std::remove_pointer_t<decltype(StringTableType::values)>;
using CellIndexType_t = std::remove_pointer_t<decltype(StringTableType::cellIndex)>;
protected:
void SetCellContent(CellType_t& cell, const char* content) override
@ -129,13 +130,13 @@ namespace string_table
return;
}
stringTable->cellIndex = memory.Alloc<int16_t>(cellCount);
stringTable->cellIndex = memory.Alloc<CellIndexType_t>(cellCount);
for (auto i = 0u; i < cellCount; i++)
stringTable->cellIndex[i] = i;
stringTable->cellIndex[i] = static_cast<CellIndexType_t>(i);
std::sort(&stringTable->cellIndex[0],
&stringTable->cellIndex[cellCount - 1],
[stringTable](const int16_t a, const int16_t b)
&stringTable->cellIndex[cellCount],
[stringTable](const CellIndexType_t a, const CellIndexType_t b)
{
auto compareResult = stringTable->values[a].hash - stringTable->values[b].hash;
if (compareResult == 0)

View File

@ -51,10 +51,11 @@ namespace
CHECK(stringTable->values[5].hash == 0x1505);
REQUIRE(stringTable->cellIndex != nullptr);
CHECK(stringTable->cellIndex[0] == 2);
CHECK(stringTable->cellIndex[1] == 4);
CHECK(stringTable->cellIndex[2] == 3);
CHECK(stringTable->cellIndex[3] == 1);
CHECK(stringTable->cellIndex[4] == 0);
CHECK(stringTable->cellIndex[0] == 5);
CHECK(stringTable->cellIndex[1] == 2);
CHECK(stringTable->cellIndex[2] == 4);
CHECK(stringTable->cellIndex[3] == 3);
CHECK(stringTable->cellIndex[4] == 1);
CHECK(stringTable->cellIndex[5] == 0);
}
} // namespace

View File

@ -51,10 +51,11 @@ namespace
CHECK(stringTable->values[5].hash == 0x1505);
REQUIRE(stringTable->cellIndex != nullptr);
CHECK(stringTable->cellIndex[0] == 2);
CHECK(stringTable->cellIndex[1] == 4);
CHECK(stringTable->cellIndex[2] == 3);
CHECK(stringTable->cellIndex[3] == 1);
CHECK(stringTable->cellIndex[4] == 0);
CHECK(stringTable->cellIndex[0] == 5);
CHECK(stringTable->cellIndex[1] == 2);
CHECK(stringTable->cellIndex[2] == 4);
CHECK(stringTable->cellIndex[3] == 3);
CHECK(stringTable->cellIndex[4] == 1);
CHECK(stringTable->cellIndex[5] == 0);
}
} // namespace