28 using SampleData = std::vector<std::remove_pointer_t<samplePtr>>;
32 std::function<
void()> onComplete)
39 const auto blocksCount = blocks.size();
41 const size_t blockPerThread = blocks.size() /
mThreadsCount + 1;
45 const size_t startIndex = i;
47 if (startIndex >= blocks.size())
50 std::vector<LockedBlock> threadBlocks;
51 threadBlocks.reserve(blockPerThread);
53 for (
size_t j = startIndex; j < blocksCount; j +=
mThreadsCount)
54 threadBlocks.emplace_back(blocks[j]);
58 [
this, threadBlocks = std::move(threadBlocks)]()
63 for (
const auto& block : threadBlocks)
64 result.emplace(block.Id,
ComputeHash(sampleData, block));
85 [](
const auto& result)
87 return result.wait_for(std::chrono::seconds(0)) ==
88 std::future_status::ready;
92 std::pair<std::string, bool>
95 assert(block.
Id >= 0);
102 return { hash,
false };
108 sampleData.resize(dataSize);
110 const size_t samplesRead = block.
Block->GetSamples(
114 return { {},
false };
118 return { hash,
true };
129 std::vector<std::pair<int64_t, std::string>> result;
133 const auto& threadResult = fut.get();
135 for (
const auto& [
id, hash] : threadResult)
137 result.emplace_back(std::make_pair(
id, hash.first));
154 using Result = std::unordered_map<int64_t, std::pair<std::string, bool>>;
166 std::function<
void()> onComplete)
179 mWorkers = std::make_unique<Workers>(
180 cache, std::move(blocks), std::move(onComplete));
virtual void UpdateHash(int64_t blockId, const std::string &hash)=0
virtual bool GetHash(int64_t blockId, std::string &hash) const =0
std::function< void()> mOnComplete
const size_t mThreadsCount
std::vector< std::future< Result > > mResults
std::pair< std::string, bool > ComputeHash(SampleData &sampleData, const LockedBlock &block) const
std::future< void > mWaiter
Workers(BlockHashCache &cache, const std::vector< LockedBlock > blocks, std::function< void()> onComplete)
std::unordered_map< int64_t, std::pair< std::string, bool > > Result
std::vector< std::pair< int64_t, std::string > > TakeResult()
std::vector< std::remove_pointer_t< samplePtr > > SampleData
bool ComputeHashes(BlockHashCache &cache, std::vector< LockedBlock > blocks, std::function< void()> onComplete)
std::unique_ptr< Workers > mWorkers
std::vector< std::pair< int64_t, std::string > > TakeResult()
Positions or offsets within audio files need a wide type.
std::string sha256(const T &data)