Generalized merge sort algorithm

The algorithm now uses templates for handling different types of key and
is not restricted to 32-bit unsigned integers anymore