Skip to content

Commit

Permalink
Implemented the small changes requested. (Using ql::views and lowerca…
Browse files Browse the repository at this point in the history
…se namespace)
  • Loading branch information
Flixtastic committed Jan 9, 2025
1 parent 09d4a97 commit 777329a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
20 changes: 10 additions & 10 deletions src/index/IndexImpl.Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ void IndexImpl::createTextIndex(const string& filename,
if (std::get<0>(*reader) != currentBlockIndex) {
AD_CONTRACT_CHECK(!classicPostings.empty());

ContextListMetaData classic = TextIndexReadWrite::writePostings(
ContextListMetaData classic = textIndexReadWrite::writePostings(
out, classicPostings, true, currenttOffset_);
ContextListMetaData entity = TextIndexReadWrite::writePostings(
ContextListMetaData entity = textIndexReadWrite::writePostings(
out, entityPostings, false, currenttOffset_);
textMeta_.addBlock(TextBlockMetaData(
currentMinWordIndex, currentMaxWordIndex, classic, entity));
Expand All @@ -382,9 +382,9 @@ void IndexImpl::createTextIndex(const string& filename,
}
// Write the last block
AD_CONTRACT_CHECK(!classicPostings.empty());
ContextListMetaData classic = TextIndexReadWrite::writePostings(
ContextListMetaData classic = textIndexReadWrite::writePostings(
out, classicPostings, true, currenttOffset_);
ContextListMetaData entity = TextIndexReadWrite::writePostings(
ContextListMetaData entity = textIndexReadWrite::writePostings(
out, entityPostings, false, currenttOffset_);
textMeta_.addBlock(TextBlockMetaData(currentMinWordIndex, currentMaxWordIndex,
classic, entity));
Expand Down Expand Up @@ -575,7 +575,7 @@ IdTable IndexImpl::readWordCl(
const ad_utility::AllocatorWithLimit<Id>& allocator) const {
IdTable idTable{3, allocator};
vector<TextRecordIndex> cids =
TextIndexReadWrite::readGapComprList<TextRecordIndex, uint64_t>(
textIndexReadWrite::readGapComprList<TextRecordIndex, uint64_t>(
tbmd._cl._nofElements, tbmd._cl._startContextlist,
static_cast<size_t>(tbmd._cl._startWordlist -
tbmd._cl._startContextlist),
Expand All @@ -584,7 +584,7 @@ IdTable IndexImpl::readWordCl(
ql::ranges::transform(cids, idTable.getColumn(0).begin(),
&Id::makeFromTextRecordIndex);
ql::ranges::copy(
TextIndexReadWrite::readFreqComprList<Id, WordIndex>(
textIndexReadWrite::readFreqComprList<Id, WordIndex>(
tbmd._cl._nofElements, tbmd._cl._startWordlist,
static_cast<size_t>(tbmd._cl._startScorelist -
tbmd._cl._startWordlist),
Expand All @@ -593,7 +593,7 @@ IdTable IndexImpl::readWordCl(
return Id::makeFromWordVocabIndex(WordVocabIndex::make(id));
}),
idTable.getColumn(1).begin());
std::ranges::copy(TextIndexReadWrite::readFreqComprList<Id, Score>(
std::ranges::copy(textIndexReadWrite::readFreqComprList<Id, Score>(
tbmd._cl._nofElements, tbmd._cl._startScorelist,
static_cast<size_t>(tbmd._cl._lastByte + 1 -
tbmd._cl._startScorelist),
Expand All @@ -608,7 +608,7 @@ IdTable IndexImpl::readWordEntityCl(
const ad_utility::AllocatorWithLimit<Id>& allocator) const {
IdTable idTable{3, allocator};
vector<TextRecordIndex> cids =
TextIndexReadWrite::readGapComprList<TextRecordIndex, uint64_t>(
textIndexReadWrite::readGapComprList<TextRecordIndex, uint64_t>(
tbmd._entityCl._nofElements, tbmd._entityCl._startContextlist,
static_cast<size_t>(tbmd._entityCl._startWordlist -
tbmd._entityCl._startContextlist),
Expand All @@ -617,7 +617,7 @@ IdTable IndexImpl::readWordEntityCl(
ql::ranges::transform(cids, idTable.getColumn(0).begin(),
&Id::makeFromTextRecordIndex);
ql::ranges::copy(
TextIndexReadWrite::readFreqComprList<Id, WordIndex>(
textIndexReadWrite::readFreqComprList<Id, WordIndex>(
tbmd._entityCl._nofElements, tbmd._entityCl._startWordlist,
static_cast<size_t>(tbmd._entityCl._startScorelist -
tbmd._entityCl._startWordlist),
Expand All @@ -627,7 +627,7 @@ IdTable IndexImpl::readWordEntityCl(
}),
idTable.getColumn(1).begin());
ql::ranges::copy(
TextIndexReadWrite::readFreqComprList<Id, Score>(
textIndexReadWrite::readFreqComprList<Id, Score>(
tbmd._entityCl._nofElements, tbmd._entityCl._startScorelist,
static_cast<size_t>(tbmd._entityCl._lastByte + 1 -
tbmd._entityCl._startScorelist),
Expand Down
18 changes: 9 additions & 9 deletions src/index/TextIndexReadWrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "util/Simple8bCode.h"

namespace TextIndexReadWrite {
namespace textIndexReadWrite {

// ____________________________________________________________________________
ContextListMetaData writePostings(ad_utility::File& out,
Expand All @@ -24,17 +24,17 @@ ContextListMetaData writePostings(ad_utility::File& out,
}

auto firstElements =
postings | std::ranges::views::transform([](const Posting& posting) {
postings | ql::views::transform([](const Posting& posting) {
return std::get<0>(posting).get();
});

auto secondElements =
postings | std::ranges::views::transform([](const Posting& posting) {
postings | ql::views::transform([](const Posting& posting) {
return std::get<1>(posting);
});

auto thirdElements =
postings | std::ranges::views::transform([](const Posting& posting) {
postings | ql::views::transform([](const Posting& posting) {
return std::get<2>(posting);
});

Expand Down Expand Up @@ -95,12 +95,12 @@ void writeVectorAndMoveOffset(const std::vector<T>& vectorToWrite,
off_t& currentOffset) {
T* vectorAsList = new T[vectorToWrite.size()];
std::copy(vectorToWrite.begin(), vectorToWrite.end(), vectorAsList);
size_t bytes = TextIndexReadWrite::writeList(vectorAsList, nofElements, file);
size_t bytes = textIndexReadWrite::writeList(vectorAsList, nofElements, file);
currentOffset += bytes;
delete[] vectorAsList;
}

} // namespace TextIndexReadWrite
} // namespace textIndexReadWrite

// ____________________________________________________________________________
template <typename T>
Expand Down Expand Up @@ -152,8 +152,8 @@ FrequencyEncode<T>::FrequencyEncode(const TypedVector& vectorToEncode) {
template <typename T>
void FrequencyEncode<T>::writeToFile(ad_utility::File& out, size_t nofElements,
off_t& currentOffset) {
currentOffset += TextIndexReadWrite::writeCodebook(codeBook_, out);
TextIndexReadWrite::writeVectorAndMoveOffset(encodedVector_, nofElements, out,
currentOffset += textIndexReadWrite::writeCodebook(codeBook_, out);
textIndexReadWrite::writeVectorAndMoveOffset(encodedVector_, nofElements, out,
currentOffset);
}

Expand All @@ -179,6 +179,6 @@ template <typename T>
requires std::is_arithmetic_v<T>
void GapEncode<T>::writeToFile(ad_utility::File& out, size_t nofElements,
off_t& currentOffset) {
TextIndexReadWrite::writeVectorAndMoveOffset(encodedVector_, nofElements, out,
textIndexReadWrite::writeVectorAndMoveOffset(encodedVector_, nofElements, out,
currentOffset);
}
4 changes: 2 additions & 2 deletions src/index/TextIndexReadWrite.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "util/HashMap.h"
#include "util/Simple8bCode.h"

namespace TextIndexReadWrite {
namespace textIndexReadWrite {
/// THIS METHOD HAS BEEN MODIFIED
/// It basically tries to mimic the old function but with the new classes.
ContextListMetaData writePostings(ad_utility::File& out,
Expand Down Expand Up @@ -140,7 +140,7 @@ vector<To> readGapComprList(
return result;
}

} // namespace TextIndexReadWrite
} // namespace textIndexReadWrite

/// THIS IS A NEW CLASS WHICH MAINLY STEMS FROM ONE FUNCTION BEFORE
/// The FrequencyEncode class basically does the olf createCodebook method
Expand Down

0 comments on commit 777329a

Please sign in to comment.