[Merged by Bors] - Add ExactSizeIterator implementation for QueryCombinatonIter#5148
[Merged by Bors] - Add ExactSizeIterator implementation for QueryCombinatonIter#5148nicopap wants to merge 1 commit intobevyengine:mainfrom
Conversation
4674c1c to
9e73a7e
Compare
| // binomial coefficient: (n ; k) = n! / k!(n-k)! = (n*n-1*...*n-k+1) / k! | ||
| // See https://en.wikipedia.org/wiki/Binomial_coefficient | ||
| // See https://blog.plover.com/math/choose.html for implementation | ||
| // It was chosen to reduce overflow potential. |
There was a problem hiding this comment.
Note: It reduces overflow potential at least compared to the previous solution which computed n! and k!(n-k)!. This still can overflow even when the result is not an overflow. An example is provided in https://blog.plover.com/math/choose-2.html
It's also probably slower than the previous solution, because it does k div and k checked_mul, while the previous one did 1 div, k mul and k checked_mul.
| assert_eq!(a_query.iter_combinations::<5>(w).count(), 0); | ||
| assert_eq!(a_query.iter_combinations::<5>(w).size_hint().1, Some(0)); | ||
| assert_eq!(a_query.iter_combinations::<128>(w).count(), 0); | ||
| assert_eq!(a_query.iter_combinations::<128>(w).size_hint().1, Some(0)); |
There was a problem hiding this comment.
I moved those tests to query_filtered_exactsizeiterator_len, so that they can be deduplicated and tested on more stuff.
|
Check the timings for your tests; they may be making miri take excessively long. bors retry |
9e73a7e to
8460fc4
Compare
|
Despite this behavior being incorrect per #5149, I'd prefer to leave this behavior intact for consistency. That issue should be fixed all at once. |
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149 (although, if bevyengine#5148 is merged, bevyengine#5149 will re-open) - bevyengine#5149 - bevyengine#5148
|
@bevyengine/ecs-team can I get a review please? I'd like to merge this, then fix it all together in #5214. |
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149 (although, if bevyengine#5148 is merged, bevyengine#5149 will re-open) - bevyengine#5149 - bevyengine#5148
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149. This is also true of `QueryCombinationIter`. - bevyengine#5149 - bevyengine#5148
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149. This is also true of `QueryCombinationIter`. - bevyengine#5149 - bevyengine#5148
|
IMO #5214 is basically guaranteed to land; the performance overhead doesn't look nearly as bad as I expected. Merging now for consistency. bors r+ |
Following #5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`. Also: - Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`. - Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator` --- ## Changelog - Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
|
Build failed (retrying...): |
Following #5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`. Also: - Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`. - Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator` --- ## Changelog - Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
|
Build failed (retrying...): |
Following #5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`. Also: - Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`. - Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator` --- ## Changelog - Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
|
Build failed: |
8460fc4 to
2927014
Compare
|
bors retry |
Following #5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`. Also: - Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`. - Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator` --- ## Changelog - Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
2927014 to
865c34e
Compare
|
Canceled. |
|
bors retry |
Following #5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`. Also: - Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`. - Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator` --- ## Changelog - Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149. This is also true of `QueryCombinationIter`. - bevyengine#5149 - bevyengine#5148
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149. This is also true of `QueryCombinationIter`. - bevyengine#5149 - bevyengine#5148
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149. This is also true of `QueryCombinationIter`. - bevyengine#5149 - bevyengine#5148
…ine#5148) Following bevyengine#5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`. Also: - Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`. - Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator` --- ## Changelog - Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149. This is also true of `QueryCombinationIter`. - bevyengine#5149 - bevyengine#5148
…ine#5148) Following bevyengine#5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`. Also: - Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`. - Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator` --- ## Changelog - Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149. This is also true of `QueryCombinationIter`. - bevyengine#5149 - bevyengine#5148
…er (#5214) # Objective Fix #5149 ## Solution Instead of returning the **total count** of elements in the `QueryIter` in `size_hint`, we return the **count of remaining elements**. This Fixes #5149 even when #5148 gets merged. - #5149 - #5148 --- ## Changelog - Fix partially consumed `QueryIter` and `QueryCombinationIter` having invalid `size_hint` Co-authored-by: Nicola Papale <nicopap@users.noreply.github.com>
…er (#5214) # Objective Fix #5149 ## Solution Instead of returning the **total count** of elements in the `QueryIter` in `size_hint`, we return the **count of remaining elements**. This Fixes #5149 even when #5148 gets merged. - #5149 - #5148 --- ## Changelog - Fix partially consumed `QueryIter` and `QueryCombinationIter` having invalid `size_hint` Co-authored-by: Nicola Papale <nicopap@users.noreply.github.com>
…ine#5148) Following bevyengine#5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`. Also: - Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`. - Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator` --- ## Changelog - Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
…er (bevyengine#5214) # Objective Fix bevyengine#5149 ## Solution Instead of returning the **total count** of elements in the `QueryIter` in `size_hint`, we return the **count of remaining elements**. This Fixes bevyengine#5149 even when bevyengine#5148 gets merged. - bevyengine#5149 - bevyengine#5148 --- ## Changelog - Fix partially consumed `QueryIter` and `QueryCombinationIter` having invalid `size_hint` Co-authored-by: Nicola Papale <nicopap@users.noreply.github.com>
Following #5124 I decided to add the
ExactSizeIteratorimpl forQueryCombinationIter.Also:
size_hintandlenfor both the normalQueryIterandQueryCombinationIter.QueryCombinationIterwhen it shouldn't beExactSizeIteratorChangelog
ExactSizeIteratorimplementation forQueryCombinatonIter