sort and rank improvements

Applied improvements suggested at commit a24b7d70172602855c45d7805f74fb4d6e0d3320 to sort_asc, sort_desc and rank

Also added some unit tests for size zero vector and fixed formatting.