Skip to content

Commit

Permalink
Prevent array sublists interfering with parent lists
Browse files Browse the repository at this point in the history
  • Loading branch information
AReallyGoodName committed Dec 16, 2014
1 parent 4942331 commit 987a085
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target
.idea
*.iml
3 changes: 2 additions & 1 deletion src/main/java/geocode/kdtree/KDTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ of this software and associated documentation files (the "Software"), to deal

package geocode.kdtree;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -53,7 +54,7 @@ private KDNode<T> createKDTree( List<T> items, int depth ) {
}
Collections.sort(items, items.get(0).getComparator(depth % 3));
int currentIndex = items.size()/2;
return new KDNode<T>(createKDTree(items.subList(0, currentIndex), depth+1), createKDTree(items.subList(currentIndex + 1, items.size()), depth+1), items.get(currentIndex));
return new KDNode<T>(createKDTree(new ArrayList<T>(items.subList(0, currentIndex)), depth+1), createKDTree(new ArrayList<T>(items.subList(currentIndex + 1, items.size())), depth+1), items.get(currentIndex));
}

private KDNode<T> findNearest(KDNode<T> currentNode, T search, int depth) {
Expand Down

0 comments on commit 987a085

Please sign in to comment.