Add a template implementation of mergesort with threshold.