functools already have `cmp_to_key`, so I could delete some code.