if both Less(i, j) and Less(j, k) are true, then Less(i, k) must be true as well.
if both Less(i, j) and Less(j, k) are false, then Less(i, k) must be false as well.
The previous implementation tried to sort only adjacent fields, but this meant it didn't follow the requirements of Less. This made the sorting unstable for inputs like the attached bug.
The new implementation makes the order transitive and stable.
The next change will fix sort_repeated_fields_by_content which has the same problem.
Make
sort_repeated_fields_by_subfield
transitive and stable.https://pkg.go.dev/sort#Interface says:
The previous implementation tried to sort only adjacent fields, but this meant it didn't follow the requirements of
Less
. This made the sorting unstable for inputs like the attached bug.The new implementation makes the order transitive and stable.
The next change will fix
sort_repeated_fields_by_content
which has the same problem.