Incorporate KDTree code.

This is still a work in progress, but I believe it is close. 45/48 linking-related tests pass in 'KDTree' mode. And none of the tests are broken in 'BTree' mode using the HashTable.

The branches have diverged too severely to for a merge to be practical, so I typed in @nkeim 's code and attributed him as the author of the key commits.