Initial commit: Final state of the master project

This commit is contained in:
2017-09-16 09:41:37 +02:00
commit 696180d43b
832 changed files with 169717 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
#pragma once
#include <vector>
#include <assert.h>
#include "../../core/CollectionHelper.h"
#include "../../inc/tbb/parallel_for.h"
template<typename T>
struct NearestFinder
{
T operator()(const T& source, const std::vector<T>& values) const
{
assert(!values.empty());
float min = T::Distance(source, values[0]);
size_t minIndex = 0;
for (size_t i = 0; i < values.size(); i++)
{
float distance = T::Distance(source, values[i]);
if (distance < min)
{
min = distance;
minIndex = i;
}
}
return values[minIndex];
}
};
template<typename T>
struct ParallelNearestFinder
{
T operator()(const T& source, const std::vector<T>& values) const
{
assert(!values.empty());
std::vector<float> distances(values.size());
tbb::parallel_for(size_t(0), values.size(), [&](size_t i) { distances[i] = T::Distance(source, values[i]); });
return values[CollectionHelper::MinIndex(distances)];
}
};