-
Notifications
You must be signed in to change notification settings - Fork 58
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
Add set/reset/flip functions to change sequences #27
Conversation
ff12396
to
14bdb9e
Compare
Codecov Report
@@ Coverage Diff @@
## develop #27 +/- ##
===========================================
+ Coverage 75.41% 76.76% +1.35%
===========================================
Files 5 5
Lines 541 594 +53
Branches 198 210 +12
===========================================
+ Hits 408 456 +48
- Misses 23 24 +1
- Partials 110 114 +4
Continue to review full report at Codecov.
|
This change is fine, however I think calling it set() makes more sense, and adding reset(f, l) and perhaps flip(f, l) so that all the bit manipulators can operate either on a single bit or a range of bits would complete the desired goal to modify sequences efficiently. As for the meaning of |
@jeking3 I like your thoughts and agree with most of them. Using relative last bit positions instead of absolute is done in std::string and it's logical to do the same here. I decided to not call But I have a serious doubt connected with implicit conversions from int to bool.
The last line was supposed to be Other things seem fine to me, I'd make reset() and flip() with tests as well, after some time. |
So, I've added some commits and there are three new range functions... With tests, docs, without code doubling. Anyone, feel free to comment them! |
@@ -197,10 +198,13 @@ <h3><a id ="synopsis">Synopsis</a></h3> | |||
dynamic_bitset <a href="#op-sl">operator<<</a>(size_type n) const; | |||
dynamic_bitset <a href="#op-sr">operator>></a>(size_type n) const; | |||
|
|||
dynamic_bitset& <a href="#set3">set</a>(size_type n, size_type len, bool val = true); |
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.
This has led to ambiguity. See rdkit/rdkit#2128. We need to resolve this. I will open an issue.
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.
This needs to be resolved by Nov 7 or it will be reverted for the Boost 1.69.0 beta.
Neither boost::dynamic_bitset nor vanilla std::bitset have the
fill()
function, and I propose to introduce this.The point of the function is being used instead of loops with calling the
set(pos)
function.Let's consider an example where we want either to set 1024 consecutive bits or to reset them (taking as the fact that we don't change the whole bitset, only its part).
Using a cycle we do it using, well, 1024 operations. Though we could have done it using maximum 1024/64+1=17 operations (considering the blocks as 64-bit integers) - setting the whole blocks between the first and the last bit, and optionally setting a suffix or a prefix of the first/last block respectively.
I also updated docs, tests. Yeah, the algorithm can look a bit complicated, and there are 2 helper functions added, but there's nothing hard at all.
Any suggestions, notes on possible performance improvement, arguments meaning (we change here [first; last], but can change [first;last) as it's more STL-like style); maybe naming too? I guess
fill(size_type first, size_type last, bool val = true);
could be namedset(size_type first, size_type last, bool val = true);
as well.