Allow application to use custom memory allocation
Change order of comparator for timsort_arg

BSD qsort_r takes the context as the first param to the comparator
function. Changed timsort_arg to match that