Skip to content
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: combine Program.hints and Program.hints_ranges into a custom collection #1342

Closed
MegaRedHand opened this issue Jul 21, 2023 · 1 comment · Fixed by #1366
Closed
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@MegaRedHand
Copy link
Contributor

Currently, the Program struct contains two fields hints and hints_ranges, where the second one is used to index the first.

pub(crate) hints: Vec<HintParams>,
/// This maps a PC to the range of hints in `hints` that correspond to it.
pub(crate) hints_ranges: Vec<HintRange>,

As they are strongly related two each other, they should be combined into a single collection that encapsulates the creation and indexing of hints. Some related functionality would be:

  • Program::flatten_hints (a kind of constructor for it),

pub(crate) fn flatten_hints(
hints: &HashMap<usize, Vec<HintParams>>,
program_length: usize,
) -> Result<(Vec<HintParams>, Vec<HintRange>), ProgramError> {

  • and indexing operations (they are used in more than one place)

let hint_data = self
.program
.shared_program_data
.hints_ranges
.get(vm.run_context.pc.offset)
.and_then(|r| r.and_then(|(s, l)| hint_data.get(s..s + l.get())))
.unwrap_or(&[]);

@PanGan21
Copy link
Contributor

PanGan21 commented Aug 9, 2023

Hi! I did some effort to achieve this refactor in the pr mentioned above. Let me know if it would require more changes :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants