more fixes to the VPTree, this time it's working consistently for real

git-svn-id: http://google-refine.googlecode.com/svn/trunk@293 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Stefano Mazzocchi 2010-03-14 01:29:27 +00:00
parent f7ab7c9cf6
commit 3495c417cd

View File

@ -80,12 +80,14 @@ public class VPTreeBuilder {
return null;
}
TNode vpNode = new TNode(nodes[begin + getRandomIndex(delta)].get());
Node randomNode = nodes[begin + getRandomIndex(delta)];
TNode vpNode = new TNode(randomNode.get());
if (DEBUG) System.out.println("\nvp-node: " + vpNode.get().toString());
calculateDistances (vpNode , nodes, begin, end);
orderDistances (nodes, begin, end);
fixVantagPoint (randomNode , nodes, begin, end);
if (DEBUG) {
for (int i = begin; i <= end; i++) {
@ -127,6 +129,19 @@ public class VPTreeBuilder {
}
}
private void fixVantagPoint (Node pivot, Node nodes[], int begin, int end) {
for (int i = begin; i < end; i++) {
if (nodes[i] == pivot) {
if (i > begin) {
Node tmp = nodes[begin];
nodes[begin] = pivot;
nodes[i] = tmp;
break;
}
}
}
}
private void orderDistances(Node nodes[], int begin, int end) {
NodeSorter.sort(nodes, begin, end);
}