Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.
This repository was archived by the owner on Aug 2, 2023. It is now read-only.

Consider adding a Bidirectional Dictionary #446

@ianhays

Description

@ianhays

Last summer I looked into new collections to consider adding to .NET. I ultimately decided on adding the MultiValueDictionary, but a close contender was the bi-directional dictionary. Now that we have corefxlab and we're working in the open, I'd like to revisit the BiDictionary as a possible addition.

If I remember correctly, my basic implementation for a BiMap that I took to API review a year ago had two Dictionaries – one that maps from Key->Value and the other that maps Value->Key. Any time the BiMap is mutated, both internal dictionaries have to be updated. There was also a Property “Reverse” to get the Value->Key mapping such that you could do:

BiMap<int, string> map = new BiMap<int, string>();
Map[1] =cat;
BiMap<string, int> reverse = map.Reverse;
Assert.Equal(1, reverse[cat]);

Both “map” and “reverse” used the same internal store.

So moving forward we should look at the above as our “worst case” scenario. I think we can do something more clever.

The biggest design issue I'd like to get resolved is whether we should Implement IDictionary<TKey, Value> and IDictionary<TValue, TKey> or just the former.

@ReedKimble

Metadata

Metadata

Assignees

No one assigned

    Labels

    OpenBeforeArchivingThese issues were open before the repo was archived. For re-open them, file them in the new repoarea-Otherup-for-grabs

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions