#ifndef KNN_H
#define KNN_H

#include <vector>
#include <algorithm>

template <typename T, int dim> class KNN {

private:

	std::vector<T> elems;

public:

	/** add a new element */
	void add(const T& elem) {
		elems.push_back(elem);
	}

	void build() {;}

	/** get the nearest n elements */
	template <typename T2> std::vector<T> get(const T2& src, const int num) {

		auto lambda = [&] (const T& e1, const T& e2) {
			return e1.getDistance(src) < e2.getDistance(src);
		};

		std::sort(elems.begin(), elems.end(), lambda);

		std::vector<T> res;
		for (int i = 0; i < num; ++i) { res.push_back(elems[i]); }
		return res;

	}


};

#endif // KNN_H

