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

'sort.Search()' can't get index 0 at 'f func(int) bool' #34827

Closed
jhaoheng opened this issue Oct 10, 2019 · 2 comments
Closed

'sort.Search()' can't get index 0 at 'f func(int) bool' #34827

jhaoheng opened this issue Oct 10, 2019 · 2 comments

Comments

@jhaoheng
Copy link

What version of Go are you using (go version)?

go version go1.13 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"

What did you do?

Playground link: https://play.golang.org/p/f0E0SRNHj-5
and Output is

Origin : [{zig 40} {max 19} {sunny 18}]
1 {max 19}
2 {sunny 18}

The output should include 0 {zig 40}, but not.

What did you expect to see?

Origin : [{zig 40} {max 19} {sunny 18}]
0 {zig 40}
1 {max 19}
2 {sunny 18}

What did you see instead?

Origin : [{zig 40} {max 19} {sunny 18}]
1 {max 19}
2 {sunny 18}
@jespino
Copy link

jespino commented Oct 10, 2019

I think this is not a bug, accordingly to the documentation of sort.Search is using binary search to find a the index i in [0, n) at which f(i) is true, so it doesn't need to evaluate all the values only a subset of them.

@agnivade
Copy link
Contributor

What @jespino said. You are not even searching for a value, the function just blindly returns false.

If you have further questions, please feel free to ask it in any of these forums below:

Thanks

@golang golang locked and limited conversation to collaborators Oct 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants