-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
Implement <<= and >>= for std.bitmanip.BitArray. #2797
Conversation
c6cce91 to
da54691
Compare
| ptr[i] = 0; | ||
| } | ||
|
|
||
| version(none) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a bad idea to introduce dead code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops!! I was supposed to delete that code before pushing. Sorry!!
|
|
|
|
Is it? The documentation doesn't say so. Anyway, then it's ok to leave it as-is. |
Yeah, that documentation could be clearer. IIRC |
Bugfixes.
25f6e91 to
d86e971
Compare
|
Rebased. Are we talking about dlang.org docs, or is there some docs in this PR that needs to be improved? |
dlang.org |
| @@ -1710,6 +1710,242 @@ public: | |||
| assert(c[2] == 0); | |||
| } | |||
|
|
|||
| // Rolls double word (upper, lower) to the right by n bits and returns the | |||
| // lower word of the result. | |||
| private static size_t rollRight(size_t upper, size_t lower, size_t nbits) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really-really hope this is inlined but experience tells me it's likely not.
I'd double check it - if not, then using empty template args rollRight()(sizet_ ...) would help.
|
Templatized |
|
LGTM. Anyone else? |
|
LGTM |
|
Auto-merge toggled on |
Implement <<= and >>= for std.bitmanip.BitArray.
|
Nice! So, are we going to implement rotations too? |
|
Should we? |
Sounds useful. |
| // Unfortunately, due to the way core.bitop.bt() works, indices are the | ||
| // reverse order of what an equivalent << on a size_t would do, so we | ||
| // have to use rollRight() instead of rollLeft() here, contrary to the | ||
| // direction of the << operator on this BitArray. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get this comment, but bt sure works like I thought it does.
http://dpaste.dzfl.pl/005ca912e356
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see what's going on, you're shifting in the wrong directions.
In fact the formatted string is LSB order, so shifting in one direction should shift the string into the other.
import std.bitmanip, std.format;
void main()
{
BitArray ba;
ba.init([0, 0, 0, 0, 1]);
assert(ba[4]);
assert(format("%b", ba) == "00001");
ba >>= 2;
assert(ba[2]);
assert(format("%b", ba) == "001");
ba <<= 2;
assert(ba[4]);
assert(format("%b", ba) == "00001");
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the directions of the shift should be reversed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep
|
Follow-up pull: #2844 |
As requested on the forum.