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

Issue 5440113: code review 5440113: math/go: added BitCount() to Int.

Can't Edit
Can't Publish+Mail
Start Review
Created:
14 years, 1 month ago by davids
Modified:
11 years ago
Reviewers:
CC:
golang-codereviews, dsymonds, anacrolix, iant
Visibility:
Public.

Description

math/go: added BitCount() to Int. To count the number of bits set in Int, the BitCount() method was added. Corresponding bitCount() functions were added to nat.go and arith.go. The underlying func bitCount(x Word) (n int) uses the Wegner algorithm. It is not the best algorithm (particularly when there are many 1's), but it is simple and passes written test cases. The commented out block of code above corresponds to another algorithm: variable-precision SWAR algorithm. However, this code did not pass the test cases. Perhaps it had something to do with integer overflow? Regardless, the Wegner algorithm worked well and passes all test cases added to int_test.go. The bitCount function should perhaps return uint64 instead to guard against overflow. But the return variable is set as int in order to be consistent with the bitLen function and friends.

Patch Set 1 #

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

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

Unified diffs Side-by-side diffs Delta from patch set Stats (+67 lines, -0 lines) Patch
M src/pkg/math/big/arith.go View 1 2 1 chunk +22 lines, -0 lines 0 comments Download
M src/pkg/math/big/int.go View 1 1 chunk +5 lines, -0 lines 0 comments Download
M src/pkg/math/big/int_test.go View 1 2 1 chunk +32 lines, -0 lines 0 comments Download
M src/pkg/math/big/nat.go View 1 1 chunk +8 lines, -0 lines 0 comments Download

Messages

Total messages: 6
davids
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go/
13 years, 11 months ago (2012-02-01 05:39:14 UTC) #1
dsymonds
In the words of the sages, "not now". Perhaps after Go 1. Dave.
13 years, 11 months ago (2012-02-01 06:39:25 UTC) #2
anacrolix
Can this be revisited?
11 years, 4 months ago (2014-09-11 18:09:21 UTC) #3
gobot
Replacing golang-dev with golang-codereviews. To the author of this CL: If you are using 'hg ...
11 years, 4 months ago (2014-09-11 18:10:44 UTC) #4
iant
On Thu, Sep 11, 2014 at 11:09 AM, <anacrolix@gmail.com> wrote: > Can this be revisited? ...
11 years, 4 months ago (2014-09-12 13:29:10 UTC) #5
gobot
11 years ago (2014-12-19 05:18:09 UTC) #6
R=close

To the author of this CL:

The Go project has moved to Gerrit Code Review.

If this CL should be continued, please see the latest version of
https://golang.org/doc/contribute.html for instructions on
how to set up Git and the Go project's Gerrit codereview plugin,
and then create a new change with your current code.

If there has been discussion on this CL, please give a link to it
(golang.org/cl/5440113 is best) in the description in your
new CL.

Thanks very much.
Sign in to reply to this message.

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