k-d tree implementation in Mathematica