]> Cypherpunks repositories - gostls13.git/commitdiff
bytes: Change Compare example to be consistent with sort.Search's.
authorMatthew Dempsky <mdempsky@google.com>
Mon, 7 Jan 2013 03:43:32 +0000 (22:43 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 7 Jan 2013 03:43:32 +0000 (22:43 -0500)
R=rsc, adg
CC=golang-dev
https://golang.org/cl/7057049

src/pkg/bytes/example_test.go

index 5f7e18c9f64c518ae9730812cf657f989a2ea910..dc66b6a40f67b73c24bd9c158bb82bded3f8d064 100644 (file)
@@ -59,10 +59,10 @@ func ExampleCompare_search() {
        var needle []byte
        var haystack [][]byte // Assume sorted
        i := sort.Search(len(haystack), func(i int) bool {
-               // Return needle <= haystack[i].
-               return bytes.Compare(needle, haystack[i]) <= 0
+               // Return haystack[i] >= needle.
+               return bytes.Compare(haystack[i], needle) >= 0
        })
-       if i < len(haystack) && bytes.Equal(needle, haystack[i]) {
+       if i < len(haystack) && bytes.Equal(haystack[i], needle) {
                // Found it!
        }
 }