implemented fast sparse distance calculations for kNN