Knn implementation without matrices