Very nice work !
However, VP trees are really useful for mining huge collection of data.
From a quick look at your implementation, I found two issues. One is minor, the second one is more complex.
The minor one is about to_list
: it has at least quadratic complexity, since each right sub-tree is traversed twice, on during to_list
and once during List.rev_append
; you must use a right-to-left traversal with an accumulator instead, and add each individual vp
node with a O(1) cons on it.
Although, since VP tree are expected to be huge, a to-list function is not really useful.
The second issue is that you assume all the data is initially available into one single list, hence it must entirely fit into the memory. Of course, having initially a small list of representative points is useful for building good vantage points using their statistical distribution. But we might want to make that database huge later on.
A more interesting implementation would be to have an abstract layer to access and build the VP tree lazily, hence making us able to back it on disk and only caching some nodes into memory. If you look carefully at the algorithms provided in the reference paper, only a very thin slice of the VP tree is actually required to be loaded into memory when looking for some specific points. That's where VP tree are really amazing.
Although, you shall add a function to insert a new point in the VP tree.