-
Notifications
You must be signed in to change notification settings - Fork 86
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
Add DelegatingMapSet to collection package #11
Comments
<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="48" height="48"hspace="10"> Comment by nex3 |
<img src="https://avatars.githubusercontent.com/u/4865287?v=3" align="left" width="48" height="48"hspace="10"> Comment by lrhn You can do that using: new HashSet(equals: (a, b) => keyForValue(a) == keyForValue(b), Is there something a specialized map-backed-set would be able to do better than this? If the keyForValue computation is expensive, I can see a reason to extract it once, and use it as the key of a map, but it's going to be used on all lookups as well, so it should probably be cached on the object instead (or maybe in an Expando). |
<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="48" height="48"hspace="10"> Comment by nex3 The goal is to provide a Set view of a map's keys, so it's important that the resulting set delegates to the backing map. For example, in Barback we have a notion of assets that have ids. We store these assets in a Map<AssetId, Asset>, but sometimes it's useful to view this as a Set—it makes it easier to add and remove Assets, for example. In this case, keyForValue would be "(asset) => asset.id". |
<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="48" height="48"hspace="10"> Comment by nex3 Fixed in dart-lang/sdk@39ba636, to be released in collection 0.9.3. Added Fixed label. |
<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="96" height="96"hspace="10"> Issue by nex3
Originally opened as dart-lang/sdk#18705
Suppose there's a collection of objects that are indexed by properties on the objects themselves. Normally this would be represented by a Map, but in some cases it may be more useful to treat it as a Set. This is possible since the key is determinable from each value, so for example "add" could be implemented as "super[keyForValue(value)] = value". It would be nice to add a class to support this to the collection package.
The text was updated successfully, but these errors were encountered: