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: the result of sort.SearchString not expect #25382

Closed
thinkerou opened this issue May 14, 2018 · 2 comments
Closed

sort: the result of sort.SearchString not expect #25382

thinkerou opened this issue May 14, 2018 · 2 comments

Comments

@thinkerou
Copy link

Please answer these questions before submitting your issue. Thanks!

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

go version go1.10 darwin/amd64

Does this issue reproduce with the latest release?

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

GOROOT="/usr/local/Cellar/go/1.10/libexec"

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

code:

func main() {
	s := []string{"c", "ca", "b", "d", "a"}

	sort.Strings(s)
	fmt.Println(s)

	i := sort.SearchStrings(s, "bx")
	println(i)
}
➜  ~ go run test.go
[a b c ca d]
2

What did you expect to see?

it should return 5

What did you see instead?

@blyork
Copy link

blyork commented May 14, 2018

The docs say that it will return the insertion index if the element is not found. 2 is the correct value because "bx" comes after "b" and before "c" and "b" is at index 1.

@dominikh
Copy link
Member

Working as intended as per @blyork

@dominikh dominikh changed the title the result of sort.SearchString not expect sort: the result of sort.SearchString not expect May 14, 2018
@golang golang locked and limited conversation to collaborators May 14, 2019
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