Use prim algo in core to create the document trees.

Add tests, as well as rename prims to get-mst, since we want to say what
we are doing, instead of how we are doing it.