Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored some shared_ptrs to unique_ptrs in the IndexBuilder #457

Merged
merged 2 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/index/Index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,9 @@ VocabularyData Index::passFileForVocabulary(const string& filename,
for (size_t j = 0; j < NUM_PARALLEL_ITEM_MAPS; ++j) {
convertedMaps[j] = std::move(itemArray[j]).moveMap();
}
auto oldItemPtr =
std::make_shared<const std::array<ItemMap, NUM_PARALLEL_ITEM_MAPS>>(
std::move(convertedMaps));
auto oldItemPtr = std::make_unique<ItemMapArray>(std::move(convertedMaps));
sortFuture = writeNextPartialVocabulary(
i, numFiles, actualCurrentPartialSize, oldItemPtr,
i, numFiles, actualCurrentPartialSize, std::move(oldItemPtr),
std::move(localIdTriples), &writer);
numFiles++;
// Save the information how many triples this partial vocabulary actually
Expand Down Expand Up @@ -1523,8 +1521,7 @@ void Index::initializeVocabularySettingsBuild() {
// ___________________________________________________________________________
std::future<void> Index::writeNextPartialVocabulary(
size_t numLines, size_t numFiles, size_t actualCurrentPartialSize,
std::shared_ptr<const std::array<ItemMap, NUM_PARALLEL_ITEM_MAPS>> items,
std::unique_ptr<TripleVec> localIds,
std::unique_ptr<ItemMapArray> items, std::unique_ptr<TripleVec> localIds,
TripleVec::bufwriter_type* globalWritePtr) {
LOG(INFO) << "Lines (from KB-file) processed: " << numLines << '\n';
LOG(INFO) << "Actual number of Triples in this section (include "
Expand All @@ -1537,10 +1534,11 @@ std::future<void> Index::writeNextPartialVocabulary(
PARTIAL_VOCAB_FILE_NAME +
std::to_string(numFiles);

auto lambda = [localIds = std::move(localIds), globalWritePtr, items,
vocab = &_vocab, partialFilename, partialCompressionFilename,
vocabPrefixCompressed = _vocabPrefixCompressed]() {
auto vec = vocabMapsToVector(items);
auto lambda = [localIds = std::move(localIds), globalWritePtr,
items = std::move(items), vocab = &_vocab, partialFilename,
partialCompressionFilename,
vocabPrefixCompressed = _vocabPrefixCompressed]() mutable {
auto vec = vocabMapsToVector(std::move(items));
const auto identicalPred = [&c = vocab->getCaseComparator()](
const auto& a, const auto& b) {
return c(a.second.m_splitVal, b.second.m_splitVal,
Expand Down
3 changes: 1 addition & 2 deletions src/index/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,7 @@ class Index {
*/
std::future<void> writeNextPartialVocabulary(
size_t numLines, size_t numFiles, size_t actualCurrentPartialSize,
std::shared_ptr<const ItemMapArray> items,
std::unique_ptr<TripleVec> localIds,
std::unique_ptr<ItemMapArray> items, std::unique_ptr<TripleVec> localIds,
TripleVec::bufwriter_type* globalWritePtr);

void convertPartialToGlobalIds(TripleVec& data,
Expand Down
2 changes: 1 addition & 1 deletion src/index/VocabularyGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void writePartialVocabularyToFile(const ItemVec& els, const string& fileName);
* elements from all the hashMaps into a single vector No reordering or
* deduplication is done, so result.size() == summed size of all the hash maps
*/
ItemVec vocabMapsToVector(std::shared_ptr<const ItemMapArray> map);
ItemVec vocabMapsToVector(std::unique_ptr<ItemMapArray> map);

// _____________________________________________________________________________________________________________
/**
Expand Down
7 changes: 4 additions & 3 deletions src/index/VocabularyGeneratorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,15 @@ void writePartialIdMapToBinaryFileForMerging(
}

// __________________________________________________________________________________________________
ItemVec vocabMapsToVector(std::shared_ptr<const ItemMapArray> map) {
ItemVec vocabMapsToVector(std::unique_ptr<ItemMapArray> map) {
ItemVec els;
size_t totalEls = std::accumulate(
map->begin(), map->end(), 0,
[](const auto& x, const auto& y) { return x + y.size(); });
els.reserve(totalEls);
for (const auto& singleMap : *map) {
els.insert(end(els), begin(singleMap), end(singleMap));
for (auto& singleMap : *map) {
els.insert(end(els), std::make_move_iterator(begin(singleMap)),
std::make_move_iterator(end(singleMap)));
}
return els;
}
Expand Down