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

OrderedSet or IndexedSet #42

Closed
albertz opened this issue Oct 26, 2021 · 1 comment
Closed

OrderedSet or IndexedSet #42

albertz opened this issue Oct 26, 2021 · 1 comment
Assignees

Comments

@albertz
Copy link
Member

albertz commented Oct 26, 2021

For some internal handling (storing the parents of a module), I need a ordered set to make the behavior deterministic.

Python does not have this as a builtin.

So our options:

  • Just do not use a set, but a dict instead, with dummy values. (And then due to Make minimum Python version explicit #43 it is ordered.)
  • Implement OrderedSet by ourselves here in returnn-common.
  • Implement it by ourselves in RETURNN (returnn.util.ordered_set or so) and use it here.
  • Use some external dependency (should be recent and used by many people):

Suggestions? Opinions?

Another aspect, not really relevant for my use case currently, but maybe it will be: __eq__ is usually different on OrderedDict (and also Boltons IndexedSet) than it is on dict.__eq__/set.__eq__ and defines it such that it is only equal when it also has the same order. I see also use cases where we want to keep the original dict.__eq__/set.__eq__ logic.

albertz added a commit that referenced this issue Oct 27, 2021
Related:
#42 (OrderedSet or IndexedSet)
#43 (min Python version)
@albertz
Copy link
Member Author

albertz commented Oct 27, 2021

In 75948c8 I implemented now the variant via dict by not using set at all. And this is enough now for me. Maybe we can reopen this once we need it again for some other purpose.

@albertz albertz closed this as completed Oct 27, 2021
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

5 participants