-
Notifications
You must be signed in to change notification settings - Fork 5
Double ended iteration for iter_set_bits.
#81
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
Conversation
This stuff mostly dates from when I was trying to get my head around what such iterators should be. Some of the comments are of negligible use; some are so blindingly obvious that I'm not sure why I ever put them in!
|
Maybe we should add: While touching the iterators anyway.. It should be safe since the range is |
|
I'm not totally sure of |
|
hm, maybe it's a bad idea. It might be an expensive operation that seldom is needed. |
|
I don't think it would add expense. I don't know whether it's very useful, or not, though; but if it is useful, and it's safe for us to do so, I'm happy to see a PR for it. |
Is that just the normal size reduction by one corresponding to the consuming of an item from the iterator? also out of curiousity are the iterators fused? (never return
Since the docs kind of imply that the iterator should be fused
So I'm curious what a non-fused iterator should return, the number of Edit: initially my search failed me, but I did manage to find the following, which indicates it should return |
|
Regarding the And for fused iterators, i think And that iterator is fused (to the best of my knowledge). |
|
@ratmice makes a good point (which I hadn't considered). Here are the docs:
That's not the case here. |
But if iter_set_bits is fused, then we can figure that out:
The question is if we are willing to pay that O(number-of-words) cost. |
|
I agree that it works, but I'm not sure there's a use case which is important enough to bear this (surprising) cost: I think most users would expect the cost to be O(1). [Another way of putting this is that the only way to know how far long the journey will be is to complete the journey then go back and tell everyone how long it will be :)] |
|
Oh, the journey is not O(max bit range) but i get your point. But on the other hand, if the Vob is used as a non-manifold-vertex indicator in a very large 3d mesh, and someone does However, one thing we get out of this that we should probably add the Fused trait and a test for "is iterator fused" otherwise the premise "behaves like a |
|
Dumb question: how does Good point about |
|
|
I did not know that. Perhaps it's better not to implement |
|
We could always implement size_hint() as: But i just had an idea, why not have the best of both worlds? So normally we just use the current, fast, variant with the same syntax as before. If the user uses We could not implement |
|
Is there much use in this if we can't implement |
|
You're right, maybe it is not worth the code-bloat. At least if the worst over-capacity allocation cases are fixed with a more conservative |
The main commit here is f9372b4.