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

[Feature Request]: Ordered dictionary implementation #26774

Open
Iainmon opened this issue Feb 25, 2025 · 3 comments
Open

[Feature Request]: Ordered dictionary implementation #26774

Iainmon opened this issue Feb 25, 2025 · 3 comments

Comments

@Iainmon
Copy link
Contributor

Iainmon commented Feb 25, 2025

Summary of Feature

Description:

A well implemented ordered dictionary would be very nice to have. dict would behave just like map, but dict.keys() would iterate over keys in the order that they were originally inserted. If a key was removed and then reinserted, then it's new position would be last. If a key's value was just updated, then it's position would remain.

I have tried to implement this, but have had issues using it, especially when the value type is an owned class: https://github.com/Iainmon/ChAI/blob/main/lib/OrderedDict.chpl

Is this issue currently blocking your progress?

Yes.

@Iainmon
Copy link
Contributor Author

Iainmon commented Feb 25, 2025

Or if someone has a suggestion about how to improve my implementation, that would be fantastic 😄

@mppf
Copy link
Member

mppf commented Feb 25, 2025

I have tried to implement this, but have had issues using it, especially when the value type is an owned class: https://github.com/Iainmon/ChAI/blob/main/lib/OrderedDict.chpl

Can you show a reproducer of using it that runs into problems? It's true that owned can be tricky.

@Iainmon
Copy link
Contributor Author

Iainmon commented Mar 4, 2025

Thank you for your reply.

To reproduce it would be kind of tricky. Basically I had a class

class Layer : Module(?) {
  var subModules: dict(int,owned Module(?));
  proc init(in subs: owned Module(?)) {
    // want to convert to dict and transfer ownership
  }
}

and wanted to instantiate it via

var l = new Layer(new Module1(), new Module2());

but I was running into so many issues. The best solution was just to use shared as the convention for the ChAI library. I did not like the option of using nillable owned:

var l = new Layer(new Module1()?, new Module2()?);

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

No branches or pull requests

3 participants