-
Notifications
You must be signed in to change notification settings - Fork 55
use list for unique_task2name #100
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
Conversation
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 great. My only suggestion is to use a set instead of list, which is more efficient if we had a lot of names, and also add
and discard
don't require testing beforehand.
task = cls.unique_name2task[name] | ||
if task in cls.unique_task2name: | ||
if name in cls.unique_task2name[task]: | ||
cls.unique_task2name[task].remove(name) |
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.
It would be more efficient to use a set, in which case the last two lines can just be a single-line discard
(which is a no-op if not present)
cls.unique_name2task[name] = curr_task | ||
cls.unique_task2name[curr_task] = name | ||
if curr_task not in cls.unique_task2name: | ||
cls.unique_task2name[curr_task] = [] |
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 would be set()
instead of []
I considered a set because it makes the values unique automatically. But, having never used one before, when I looked up the differences between a list and set I read that items in a set could not be changed or replaced. So I went with a list because I knew it would work (i.e. I chickened out on having to debug it if it didn't work as I expected). I'll convert to a set. |
A |
Looks great; fixes #99. |
well... TIL about object hashes in python. I've never tried to use a dict as a dict key before, but now I know why I can't. Thanks! |
Fixes #99