Extract partition and selection out of sort.c

Have extracted partition and selection algorithm out of sort.c to make
it available for external code. Have also made corresponding unit tests
, and CMake files reflecting the changes.