Skip to content

Commit

Permalink
feat(libespm): switch return type of GetDistinctRecordsByType to vect…
Browse files Browse the repository at this point in the history
…or<LookupResult>
  • Loading branch information
Pospelove committed Apr 14, 2024
1 parent 3a577a7 commit 14b6c02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
3 changes: 1 addition & 2 deletions libespm/include/libespm/CombineBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class CombineBrowser
std::vector<const std::vector<const RecordHeader*>*> GetRecordsByType(
const char* type) const;

const std::vector<const RecordHeader*> GetDistinctRecordsByType(
const char* type) const;
std::vector<LookupResult> GetDistinctRecordsByType(const char* type) const;

std::vector<const std::vector<const RecordHeader*>*> GetRecordsAtPos(
uint32_t cellOrWorld, int16_t cellX, int16_t cellY) const;
Expand Down
15 changes: 7 additions & 8 deletions libespm/src/CombineBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,25 @@ CombineBrowser::GetRecordsByType(const char* type) const
return res;
}

const std::vector<const RecordHeader*>
CombineBrowser::GetDistinctRecordsByType(const char* type) const
std::vector<LookupResult> CombineBrowser::GetDistinctRecordsByType(
const char* type) const
{
if (pImpl->numSources == 0) {
return {};
}

spp::sparse_hash_set<formId> formSet;
std::vector<const RecordHeader*> result;
std::vector<LookupResult> result;
for (size_t i = pImpl->numSources - 1; i != static_cast<size_t>(-1); --i) {
const auto& records = pImpl->sources[i].br->GetRecordsByType(type);
formSet.reserve(records.size());
result.reserve(records.size());

for (auto record : records) {
if (formSet
.insert(
utils::GetMappedId(record->GetId(), *pImpl->sources[i].toComb))
.second) {
result.push_back(record);
auto mappedId =
utils::GetMappedId(record->GetId(), *pImpl->sources[i].toComb);
if (formSet.insert(mappedId).second) {
result.push_back(LookupResult(this, record, static_cast<uint8_t>(i)));
}
}
}
Expand Down

0 comments on commit 14b6c02

Please sign in to comment.