-
Notifications
You must be signed in to change notification settings - Fork 20.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
p2p: use slices package for sorting #27494
p2p: use slices package for sorting #27494
Conversation
func (cs capsByNameAndVersion) Less(i, j int) bool { | ||
return cs[i].Name < cs[j].Name || (cs[i].Name == cs[j].Name && cs[i].Version < cs[j].Version) | ||
func capLessFunc(a, b Cap) bool { | ||
return a.Name < b.Name || (a.Name == b.Name && a.Version < b.Version) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to have a method
func (cap Cap) Less(other Cap) bool { ... }
You can then use it like this:
slices.SortFunc(caps, Cap.Less)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd actually have to look like this:
slices.SortFunc(caps, func(a, b Cap) bool {
return a.Less(b)
})
and I felt this was less attractive but up to you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd actually have to look like this:
Incorrect. Proof: https://go.dev/play/p/cE5HK4dAyl8
Co-authored-by: Felix Lange <fjl@twurst.com>
This reverts commit 9bcadfb.
This reverts commit 9bcadfb.
see #27474