-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Support for Bimaps #10906
Comments
There are currently no plans for that as far as I know. There are many useful data structures and bimap is not necessarily the most important one. I don't think they should be all baked into the language anyway. That work is probably better spent towards introducing templates #869 which would make reusable custom implementations of such structures possible. Maybe a bimap could one day be a part of the standard library (that we're currently brainstorming, see #10282) but definitely not in the near future - the stuff it's going to contain initially will be much lower level and I think that data structures would be something more suited for third-party libraries. As for bimap specifically, even if we did decide to add it, it would be just syntactic sugar, not something you cannot achieve currently by just storing two maps. One of the biggest benefits of Boost bimap is that you don't have to waste space storing keys and values twice. But in Solidity keys are not stored anyway (that's why you can't iterate over a mapping unless you keep track of keys separately) so two separate maps are already the best you can get. By the way, this question sounds like a very good topic for our new language forum: https://forum.soliditylang.org. This is a bug tracker and people come here mostly to report problems so any language design discussion moves at a glacial pace (spurred by someone randomly finding the topic). There aren't many topics there yet since people interested in discussing the language are slowly migrating off the old mailing list but I think that eventually it will be a better place for a lively discussion. I'd encourage you to try posting there :) |
I think the question has been answered so I'm closing this. But feel free to post on the forum if you'd like to discuss this in more detail! |
It would be great if Solidity would support bidirectional mappings. As far as I understand, mappings only work in a single direction. An example of this, in C++, is the Boost Bimap.
A simple example might be where you have TokenIds and Addresses. If you want to be able to get the address for a given TokenIds (in constant time), you need to hold a
TokenId -> Address
mapping. Conversely, if you want to retrieve all of the TokenIds for a given address (in constant time), you need to hold an additional mapping, along the lines ofAddress -> [TokenId]
.Is this something that would ever be offered by Solidity? It would offer better centralization of data for such situations.
Thanks!
(I understand this request lacks some criteria – I figured it was worth asking generally before delving into too much detail)
The text was updated successfully, but these errors were encountered: