-
Notifications
You must be signed in to change notification settings - Fork 673
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
refactor: add index
method for StacksEpochId
#5350
Conversation
This allows us to cleanup some magic numbers when accessing epochs in a list and make the expected behavior more clear to the reader.
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.
LGTM assuming CI passes
The list of epochs passed in here is not complete, so we cannot use the standard epoch indices for it.
There was once place acting on a list of epochs where the list was incomplete, so the standard indices shouldn't be used. This fix should resolve the failing tests. |
I think it'd be good to try to clean up the magic numbers and accessors used in epoch lists, but I'm kind of wary of encoding the indexes, even though it probably is perfectly safe (because there's no legal epoch ordering where An alternative that I think would have some of the same benefits would be a wrapper struct... pub struct EpochList (Vec<StacksEpoch>) And then defining: impl Index<&StacksEpochId> for EpochList {
type Output = StacksEpoch;
fn index(&self, index: &StacksEpochId) -> &StacksEpoch {
self.get(index).unwrap()
}
}
impl EpochList {
fn get(&self, index: &StacksEpochId) -> Option<&StacksEpoch> {
self.0.get(StacksEpoch::find_by_epoch_id(&self.0, index)?)
}
} Then, we could do things like |
Sure, that does seem nice. Likely a little slower, but I don't think we'd use it anywhere that is performance critical. |
Wrapper struct to make the accessing of the individual epochs easier and standardized.
Ok, re-refactored with |
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 looks good to me-- it definitely improves the legibility of the epochs lists! Just a couple comments.
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This allows us to cleanup some magic numbers when accessing epochs in a list and make the expected behavior more clear to the reader.