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

Code cleanup: Refactor various lists into OrderedDicts #133

Open
CydeWeys opened this issue Dec 21, 2019 · 0 comments
Open

Code cleanup: Refactor various lists into OrderedDicts #133

CydeWeys opened this issue Dec 21, 2019 · 0 comments

Comments

@CydeWeys
Copy link
Collaborator

There's lots of things that currently exist as lists in the codebase (e.g. lists of order ids, lists of tracking #s, lists of entire cluster objects, etc.). These should be converted into OrderedDicts for reasons of code cleanliness and efficiency, especially in cases where there is a unique key (e.g. the map of tracking #s to order #s). It gets a little bit harder for the clusters list, because there's no obvious unique key there since each cluster can have N trackings and N orderings. If we keyed it off the tracking and then put the same object as the value for every tracking key, it's not clear to me that, after a pickle serialization/deserialization round trip, they'd still be the same objects!

As for why OrderedDict over just plain dict, OrderedDict preserves insertion order, which is what we want. Thus the older order IDs and tracking #s would continue to remain at the front of the respective lists, exactly like how ImmutableSet and ImmutableMap in Guava preserve insertion order. Unfortunately it doesn't appear that Python has a simple set that preserves insertion order (at least not in the stdlib), but OrderedDict probably suffices in most casts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant