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

Add DelegatingMapSet to collection package #18705

Closed
nex3 opened this issue May 7, 2014 · 5 comments
Closed

Add DelegatingMapSet to collection package #18705

nex3 opened this issue May 7, 2014 · 5 comments
Assignees
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. type-enhancement A request for a change that isn't a bug

Comments

@nex3
Copy link
Member

nex3 commented May 7, 2014

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.

@nex3
Copy link
Member Author

nex3 commented May 8, 2014

Set owner to @nex3.
Added Started label.

@lrhn
Copy link
Member

lrhn commented May 8, 2014

You can do that using:

     new HashSet(equals: (a, b) => keyForValue(a) == keyForValue(b),
                 hash: (a) => keyForValue(a).hashCode);

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).

@nex3
Copy link
Member Author

nex3 commented May 8, 2014

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".

@nex3
Copy link
Member Author

nex3 commented May 21, 2014

Fixed in r36447, to be released in collection 0.9.3.


Added Fixed label.

@nex3 nex3 added Type-Enhancement area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. labels May 21, 2014
@nex3 nex3 self-assigned this May 21, 2014
@DartBot
Copy link

DartBot commented Jun 5, 2015

This issue has been moved to dart-lang/collection#11.

@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed priority-unassigned labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants