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

Keep active brackets in a dictionary #35

Open
Bronzila opened this issue Jun 28, 2023 · 1 comment
Open

Keep active brackets in a dictionary #35

Bronzila opened this issue Jun 28, 2023 · 1 comment
Labels
good first issue Good for newcomers refactoring Improving code quality

Comments

@Bronzila
Copy link
Collaborator

Changing the list of active brackets to a dictionary with the bracket_id as keys would make the code on some occasions more readable. For example this:

# pass information of job submission to Bracket Manager
for bracket in self.active_brackets:
    if bracket.bracket_id == job_info['bracket_id']:
        # registering is IMPORTANT for Bracket Manager to perform SH
        bracket.register_job(job_info['budget'])
        break

Could then be rewritten as:

bracket_id = job_info['bracket_id']
self.active_brackets[bracket_id].register_job(job_info['budget'])

This would also have runtime advantages, however these are rather small, given that our active_brackets list is mostly small.

To clean up the dictionary we can then simlpy iterate over the key-value pairs and delete the brackets, that are already done.

@Bronzila Bronzila added good first issue Good for newcomers refactoring Improving code quality labels Jun 28, 2023
@eddiebergman
Copy link
Contributor

Efficient for performing operations on the ends of lists
https://docs.python.org/3/library/collections.html#collections.deque

from collections import deque

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers refactoring Improving code quality
Projects
None yet
Development

No branches or pull requests

2 participants