Skip to content
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

Merged

Conversation

danlaine
Copy link

see #27474

@danlaine danlaine requested review from fjl and zsfelfoldi as code owners June 16, 2023 13:50
@fjl fjl changed the title p2p; use slices package for sorting p2p: use slices package for sorting Jun 16, 2023
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)
}
Copy link
Contributor

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)

Copy link
Author

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

Copy link
Contributor

@fjl fjl Jun 18, 2023

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

@fjl fjl merged commit 289c6c3 into ethereum:master Jun 19, 2023
@fjl fjl added this to the 1.12.1 milestone Jun 19, 2023
devopsbo3 pushed a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
Co-authored-by: Felix Lange <fjl@twurst.com>
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants