update to hierarchical k-means: pass inputs by reference to reduce space usage - but we also require modification of the input, so no longer const