-
Notifications
You must be signed in to change notification settings - Fork 309
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
Const generic permutations #954
Conversation
PermutationState::Start => { | ||
*state = PermutationState::End; | ||
// TODO: Consider this case and handle it somehow, currently just using default | ||
Some(std::array::from_fn(|_|I::Item::default())) | ||
} |
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.
Not sure how to proceed about this, from what i can tell the API guarantees the vector to always be K elements long, but the reference returns an empty vec?
let item = vals.get_at(&indices[0..K]); // TODO: Impl const sized variant otherwise this is pointless | ||
*state = PermutationState::Loaded { indices, cycles }; | ||
Some(item.try_into().ok()?) // TODO: Handle error case | ||
} | ||
} | ||
PermutationState::Loaded { indices, cycles } => { | ||
if advance(indices, cycles) { | ||
*state = PermutationState::End; | ||
return None; | ||
} | ||
let k = cycles.len(); |
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.
Indexing into LazyBuffer would require a const-generic function also, otherwise this effort would be pointless
Unless the lexicographic order of the permutations is important for you, the permutohedron crate should plainly satify you (created by bluss who first wrote itertools). It should even be faster than a const-generics version of our permutations, due to the algorithm. Now, some context... Right now, our MSRV is 1.43.1 while const-generics require 1.51.0. We will move to it in a near future though. But This will eventually be done along with combinations & Co. but not immediately. #560 would be a more intermediary step. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #954 +/- ##
==========================================
- Coverage 94.38% 93.23% -1.16%
==========================================
Files 48 50 +2
Lines 6665 7143 +478
==========================================
+ Hits 6291 6660 +369
- Misses 374 483 +109 ☔ View full report in Codecov by Sentry. |
permutohedron covers my case, thanks! Seeing that the MSRV is restricted like that, should I close this? |
If you want to revisit this when a more appriopriate time come then we can re-open it. |
In an application of mine i use a fixed size of permutations, which would cut down on some very wasteful temporary allocations. Therefore I am proposing a const-generic counterpart to the regular permutations.
This drafts purpose is to get some initial feedback on the idea.
Do not expect feature completeness or sanity, it is 3AM. Though I do intend to properly implement this if interest exists.