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

Optimize: We can remove the sorting in new instance #38

Open
win5do opened this issue Oct 23, 2024 · 0 comments
Open

Optimize: We can remove the sorting in new instance #38

win5do opened this issue Oct 23, 2024 · 0 comments

Comments

@win5do
Copy link

win5do commented Oct 23, 2024

func NewChooser[T any, W integer](choices ...Choice[T, W]) (*Chooser[T, W], error) {
sort.Slice(choices, func(i, j int) bool {
return choices[i].Weight < choices[j].Weight
})

Sort doesn't make any sense for randomness.
And it will change the order of the original array, which is not a good practice.

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

No branches or pull requests

1 participant