Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(273)

Issue 7042045: code review 7042045: bytes: Examples recommending bytes.Compare(a, b) rel_op... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 6 months ago by mdempsky
Modified:
12 years, 6 months ago
Reviewers:
rsc
CC:
golang-dev, minux1, adg
Visibility:
Public.

Description

bytes: Examples recommending bytes.Compare(a, b) rel_op 0 to test a rel_op b.

Patch Set 1 #

Patch Set 2 : diff -r d0d76b7fb219 https://code.google.com/p/go #

Patch Set 3 : diff -r d0d76b7fb219 https://code.google.com/p/go #

Total comments: 2

Patch Set 4 : diff -r be6ca9f6bfe8 https://code.google.com/p/go #

Patch Set 5 : diff -r be6ca9f6bfe8 https://code.google.com/p/go #

Total comments: 1

Patch Set 6 : diff -r be6ca9f6bfe8 https://code.google.com/p/go #

Patch Set 7 : diff -r be6ca9f6bfe8 https://code.google.com/p/go #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+39 lines, -0 lines) Patch
M src/pkg/bytes/example_test.go View 1 2 3 4 5 6 2 chunks +39 lines, -0 lines 1 comment Download

Messages

Total messages: 10
mdempsky
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://code.google.com/p/go
12 years, 6 months ago (2013-01-03 22:45:13 UTC) #1
minux1
Go doesn't support relational operations for slices, so i don't know why we mention them ...
12 years, 6 months ago (2013-01-04 20:32:07 UTC) #2
mdempsky
On 2013/01/04 20:32:07, minux wrote: > Go doesn't support relational operations for slices, so > ...
12 years, 6 months ago (2013-01-04 21:33:07 UTC) #3
rsc
Instead of writing text, how about writing an ExampleCompare function showing uses with < 0, ...
12 years, 6 months ago (2013-01-04 23:31:28 UTC) #4
mdempsky
Hello golang-dev@googlegroups.com, minux.ma@gmail.com, rsc@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
12 years, 6 months ago (2013-01-04 23:59:20 UTC) #5
adg
https://codereview.appspot.com/7042045/diff/17001/src/pkg/bytes/example_test.go File src/pkg/bytes/example_test.go (right): https://codereview.appspot.com/7042045/diff/17001/src/pkg/bytes/example_test.go#newcode33 src/pkg/bytes/example_test.go:33: // It's idiomatic to interpret Compare's result by comparing ...
12 years, 6 months ago (2013-01-06 22:03:35 UTC) #6
mdempsky
Hello golang-dev@googlegroups.com, minux.ma@gmail.com, rsc@golang.org, adg@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
12 years, 6 months ago (2013-01-06 22:48:10 UTC) #7
adg
LGTM
12 years, 6 months ago (2013-01-06 22:58:57 UTC) #8
adg
*** Submitted as https://code.google.com/p/go/source/detail?r=9ef7b839accd *** bytes: Examples recommending bytes.Compare(a, b) rel_op 0 to test a ...
12 years, 6 months ago (2013-01-06 22:59:56 UTC) #9
rsc
12 years, 6 months ago (2013-01-07 00:26:18 UTC) #10
Message was sent while issue was closed.
https://codereview.appspot.com/7042045/diff/15002/src/pkg/bytes/example_test.go
File src/pkg/bytes/example_test.go (right):

https://codereview.appspot.com/7042045/diff/15002/src/pkg/bytes/example_test....
src/pkg/bytes/example_test.go:62: // Return needle <= haystack[i].
Please use haystack[i] >= needle, to match the sort.Search documentation.
(And fix the next line and the Equal call.)

That is, sort.Search's docs say:

    To complete the example above, the following code tries to find the
    value x in an integer slice data sorted in ascending order:

	x := 23
	i := sort.Search(len(data), func(i int) bool { return data[i] >= x })
	if i < len(data) && data[i] == x {
		// x is present at data[i]
	} else {
		// x is not present in data,
		// but i is the index where it would be inserted.
	}

This should use the same comparisons and operand orders.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b